I am trying to create a windows form with multiple text boxes and these text boxes can grow/shrink. i would like to move the text boxes to its right and below it, based on the text entered in the current text box.
I am growing the current text box using below code
protected void Txtbx_TextChanged(object sender, EventArgs e)
{
TextBox Txtbx = sender as TextBox;
Size size = TextRenderer.MeasureText(Txtbx.Text, Txtbx.Font);
Txtbx.Width = size.Width;
Txtbx.Height = size.Height + 20;
}
FYI I am using a panel to hold the text boxes in each row and grow property set on panel.
Above image is text boxes before the text is entered
Above image is after entering text in textbox.
As you can see current text box is taking over other textboxes ,is there an easy way to move them.
All the text boxes are generated dynamically,so I was planning to adjust the location of other text boxes based on current text box in the same textchanged event handler but i feel its overkill.
Any suggestions?
Related
I am developing desktop application using c# winforms , where i have data entry form. in that data entry fields i copy data from word having some text format like underline and bold and paste it to my textbox and save it . when i show entered / stored data in gridview it would not show text underline and bold. Exapmle
While pasting data from MS word to textbox, it look like below:
Date: 18-4-19 (underline + bold)
some text
some text
some text
some text
Date: 19-4-19 (underline + bold)
some text
some text
some text
some text
when i stored data and show it on gridview it display date without underline + bold like below
Date: 18-4-19
some text
some text
some text
some text
Date: 19-4-19
some text
some text
some text
some text
how could i achieve this to remain date in underline + bold in gridview
need your kind help.
You can do it in a CellFormatting event like so:
The second if statement could be smthing different based on your needs:
I'm assuming that your DataGridView name is 'myDataGridView' and the column name where you want to apply your changes is 'columnName'
You can put that event subscription code (1st line) either in your constructor right after the pregenerated method 'InitializeComponent()' or Subscribe to that event via Visual Studio / Properties / Events.
..
myDataGridView.CellFormatting += myDataGridView_CellFormatting;
..
private void myDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
// First ill check if im in right column
// Second if checks if the value starts with "Date"
if (e.ColumnIndex == myDataGridView.Columns("columnName").Index) {
if (myDataGridView.Rows(e.RowIndex).Cells("columnName").Value.ToString().StartsWith("Date")) {
// apply your formatting
myDataGridView.Font = new Font(e.CellStyle.Font, FontStyle.Bold | FontStyle.Underline);
}
}
}
I have an issue on my code.
I need to change RichTextBox Font, while keeping the previous text formatting (Bold, Italic, Underline, Strikeout).
My form has RichTextBox; and a ToolStrip containing some ComboBoxes (where I select the Font, and set the Font Format).
Each of the controls above Controls have two events (TextChanged and SelectedIndexChanged) subscribed; running the same line of code:
My RichTextBox HideSelection property is set to false; so I can always see what Font I'm changing to and to prevent my selection from disapearing.
Please find bellow my actual code:
private void TcboSize_TextChanged(object sender, EventArgs e)
{
rtfDirections.SelectionFont = new Font(tcboFonts.Text, (float)Convert.ToDecimal(tcboSize.Text), rtfDirections.SelectionFont.Style);
}
UPDATE:
I've moved to the Form Constructor:
rtfDirections.HideSelection = false;
In order to prevent my RichTextBox Text Selection from Disappearing.
I've subscribed the SelectedIndexChanged on my ComboBoxes; in order to change the Font when the Index changes.
This sets the Font style (including Size) on the RichTextBox, and updates the ComboBox selected Item(s) Text.
My problem:
I wasn't tracking any previous selection.
When dealing with selected text; I should've assigned it to a variable; then make sure the selection is equal to that variable.
I also noticed that (sometimes) when I click any ToolStrip Button; my Text Selection disappears; which should not be the case.
As you can see above; I've set the RichTextBox.HideSelection to false.
I assume that when you select new Text in the RichTextBox; it should over write what was previously selected and use the new selection.
Should I be clearing the ComboBox Selection? If so; how can I accomplish this?
I've put break points on all lines of code and added watches to the selected text; but the Font never changes; unless I clear the Selection, but that way there are no breakpoint hits.
I have 3 text boxes and one button. On button click all text from text boxes should be written in text file (in one line). How can i do that?
Direct implementation:
File.WriteAllText(dest,
tbID.Text + tbIme.Text + tbPrezime.Text);
You can have all textboxes in a List<TextBox> and at the time of writing do:
list.ForEach(tb => file.Write(tb.Text));
file.WriteLine();
I have two columns in gridview.
One is textbox and the other is also a textbox.
If one textbox text changed , i need to perform some calculation and again need to
fill automatically the second textbox.
(e.g) Ifi enter 10 in 1st textbox, i need to perform some calculation and again the result
of that manipulation needs to shown in the textbox automatically once the text is entered
in the first textbox.
I am not getting a way to achieve this..
please help me.
You need to handle the Leave Event of the first TextBox TextBox1.
Try This:
textBox1.Leave += new System.EventHandler(textBox1_Leave);
private void textBox1_Leave(object sender, EventArgs e)
{
//Do calculations on TextBox1 value to display the result on TextBox2
}
I have text box to fill the ph.numbers in that, here what i want is, whenever i'm entering the value in that text box i need to add another empty text box dynamically where i can add another value in that in the same way if they are entering any value into this new empty box another empty text box should add at the bottom of this. And after all there is a confirm link button. When clicking on it all these ph.numbers entering on the text boxes should get. How is it possible?
You add textboxes dynamically using jquery and on the button click/submit there values to the server. What you can do is on keyup event of a textbox you can add another below it.
Try this.
I'm basing this condition that your number format is of 11, Ex: 09123456789
So on the Textbox_Textchanged event of your textbox.
if(textbox.text.length >= 11)
{
Textbox text = new Textbox();
text.TextChanged += Textbox_Textchanged; // So it would also trigger the event
// Do positioning here
}
Im thinking you can better optimize this by having a better EventArgs but you get the idea right?