Just have a simple question. I have a program and in it I have a label that displays results once you calculate them, and I want the label to clear once you change the text in the input boxes. Assuming the label is named like lblResult or something, how would I go about doing this?
If you are using Windows Forms, you would handle the TextChanged event of your input box. In the event handler, you would then set your lblResult.Text = ""
If you are using WPF / XAML, the concept it the same, you'd just handle the event a little differently.
You can learn more about VB.NET and Event Handlers on MSDN.
Related
I have a unit converter written in Visual Basic using Visual Studio 2012. It uses two text boxes and two combo boxes. It is programmed to send the focus back to the first text box after making a selection in either combo boxes, but after triggering a textChanged event in the second text box, and then making another selection in either of the combo boxes, the Focus() seems to be selecting all the text data in the first text box. I want only the blinking cursor to be in the box. When all the text is selected like that, it deletes the box when you try to type another digit in there because all of the text is selected. Please give me a solution or a suggestion. If you need some code to look at, just let me know and I will put together a somewhat small block of it to get my point across. Thanks in advance!
By the way, I am using Focus() to send the focus where I need it to go in this program.
Sounds like you want the cursor to be at the end of the TextBox?
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.TextLength
What is the best way to deal with a combo box event? In other words, what is the best event handler to use for the case that the user makes a selection from the combo box? I am using a textchanged event, but it seems a bit sloppy. Is there a better way? By the way, my program that I am using it for is a unit converter that converts length.
The textchanged event fires whenever the text inside the combobox changes. every character added to the combobox triggers it, which makes it sloppy.
To avoid performance issues, use either Lostfocus (which fires if the control isn't selected anymore) or the SelectedValue /Selectedindex changed events.
To answer your other question, manipulate the keypress event.
Go to the combobox's keypress event, and type this:
e.handled = true
this will reject any input from user.
I am working in windows form and have a few textboxes on a form.
These textboxes from top to bottom are connected, so if the text changes in textbox1, then txtbox2 and txtbox3 have to comply, if something changes in textbox2 then 3 has to comply;... and so on ... not going to bore you.
Now I was looking for an alternative, more efficient way of calling the textchanged event on the textboxes so it doesn't do everything everytime, even if one charater has changed....
Something like focus off textbox event ... or some other alternative .
This would be in vb.net and windows form.
You can use the TextBox.LostFocus event inherited from Control.LostFocus.
This event is fired when the control looses focus, like Tab or clicked on another control.
TextBox1.LostFocus perhaps? Or enable validation on the controls.
Control focus event order:
http://msdn.microsoft.com/en-gb/library/system.windows.forms.control.lostfocus.aspx
CausesValidation:
http://msdn.microsoft.com/en-gb/library/system.windows.forms.control.causesvalidation.aspx
How do I create a Control to input email addresses, similar to how capturing tags on stackoverflow works?
I am using C# and Xaml.
You will need:
TextBox(to show input area where you can type)
Popup(to show suggestions below TextBox like StackOveflow does)
ItemsControl(it goes into Popup, so you can just have collection of items and they will be displayed, note that ItemsPanel should be probably GridView)
Then you will need custom Button, that will be overlaid top of TextBox once tag has been added. You need to calculate how big is the button(width) and fill TextBox with empty spaces, to advance cursor further.
Also you need to control what keys are being pressed.
The effect you are after is probably that you recognize complete e-mail addresses, and render them in a custom way. I would do this by removing the completed addresses from the textbox, and wrap them in a skinned label (or maybe a custom control with a delete button).
The most straightforward way is to implement the textbox as a DockPanel with a border, suggesting that it is a text box. On the left side of your DockPanel, you have a StackPanel where you stack the completed address controls left-to-right. Then add a textbox with DockStyle=Fill to fill up the remainder of the DockPanel. Once you detect an email address is entered, you remove the characters from the textbox and add a matching control to the StackPanel.
There is probably a way to change the textbox contents without losing focus, otherwise you need to fix this though code.
Good luck!
What is the advantage of using a text box to display an answer in Visual Basic versus a label?
Using a (non-Disabled) textbox allows the user to select and copy the text.
You can automatically trigger a new event as soon as the textbox's text is changed using the textChanged function. this is not possible in case of a label.