I want to replace my values in text box without deleting them, for example, I output in my text box time "HH:mm:ss" and if I type in that textbox first number I would like to change "H" on it, and so on. How can i do that?
I don't ask code, just an advice.
Related
Ok, I'm trying to do something a little specific here. I want to get the location of the selected text in a textbox.
To elaborate- I can use location to select text. If I have a textBox1 I could do:
textBox1.SelectionStart = 1;
textBox1.SelectionLength = 4;
That would start at the second letter and select 4 letters.
What I want to do is the opposite: when the user selects text, I want to find out what the start is and what the length is (or what the start is and what the end is. Either will work).
I thought about just searching the string for the selectedtext (textBox1.SelectedText). The problem comes if it is a common word or a string that is used multiple times. For instance.
This is a cat. This is a cat. This is a cat.
If they select the second sentence, using SelectedText to search the string for that specific sentence does me no good. It could be either of the 3.
So, my question is: When the user clicks a button, how do I determine the exact elements that are selected by the user, so that I can later manipulate those specific elements? Important to note the later part- I likely will not only want to manipulate the text when the button is pressed. I will also want to manipulate it later, at a time when the text may no longer be highlighted. This means I'll want to store SOMETHING to tell me what specific parts of the sentence I'm dealing with. If that solution isn't viable, is there a solution you can think of where, in the above "this is a cat" example, the user could select the second sentence, hit a button, and then later I know which sentence was selected when he hit that button?
According to the documentation, SelectionStart and SelectionLength can be both set and read. Just use those.
You dont even need to know the position of selected text to manipulate them, to edit the text that you have selected in the text you can simple set the SelectedText property to the new edited value.
// if textBox1.text = "Hello World World"; with first "World" selected
textBox1.SelectedText = textBox1.SelectedText.Replace("World", "Raj");
// then it becomes "Hello Raj World"
Hi I am new to C# I have one problem in masked text box
Population range is 1,000 to 12,00,00,00,000
My problem is when enter 1000 in masked text box it will be taken as 1,000 like when i enter 12000 it will considered as 12,000 like default it will arranged in ,.
How can i do it? Please provide if any solution.
What is the Mask property set to? Try making it: #,##0.
We have a WinForms application that is currently being internationalized. While some controls are straightforward to be i18n'ed, combo boxes with drop down items are giving us a hard time. Take a combo box with the following drop down items:
year
month
day
Currently these items are provided in the designer and the text values are persisted in the application database. I know it was not too bright idea to begin with but this where we are now.
I suspect I will need to go for a key/value type list and assign that as the data source to the combo box. The question is what would be the best practice to accomplish this task?
Thanks for the help in advance.
When you use combo box, we have two properties, one is "Text" and "Value". You have to set the text value from the localized resource file and Value field always from your code.
cbxJobTile.Item.Text ="Localized string from resource file";
cbxJobTile.Item.Value = "SoftwareEngineer";
I want the funcionality of a NumericUpdown (cycle through the 12 possible values) but want to display month names rather than 1..12.
Possible?
Try using the DomainUpDown control, which is sort of the same thing as NumericUpDown, but for text.
I have the following code:
txtbox1.Text = listView1.SelectedItems[0].SubItems[11].Text;
The value of the selected item of the listview is "33,5" but when the code reachs this line, in the textbox writes 34,00.
I don't know why if there's a text inside a text, I have tried convertingo to decimal before asing to the textbox but still put 34,00. I've tried too puting 33.5 instead of 33,5 but then the code writes in the textbox: 3350,0.
What can I do?
Thanks
try this:
string number = listView1.SelectedItems[0].SubItems[11].Text;
and check in debug mode what number contains.
I am convinced you have the right value in there, a simple string, but the txtbox1 is applying certain formatting on text change. You should find this out and fix the way content of txtbox1 is formatted after assignment.