VB.net strange textbox behavior - vb.net

A customer of mine is having a problem with a text box. When he clicks on the string in the text box the cursor always jumps to the end of the string. This is a standard VB.net 2005 text box with multi-line true. On my development machine it works correctly. I click in the middle of a string and can edit where I click. Can anyone suggest what is wrong?
He has run the program both under terminal server and locally on his lap top and has the same problem.
TIA,
John

Is it possible to observe the user? For example, the user might be pressing shift-tab when they are past the text-box, and refering to that as "clicking" the text box.
You can always force behavior like:
Private Sub TextBox1_GotFocus(sender As Object, e As System.EventArgs) Handles TextBox1.GotFocus
TextBox1.SelectionStart = 0
End Sub

Related

Visual Basic Can't Type in Listbox

I am using Visual Studio and working in a Windows Form Application. I have added a Listbox on my form. The problem I am having is that when I run my application I can't add any text or even select the Listbox to put my cursor in.
You have to add values or action to listbox before run it,if you run it without value or action absolutely that will give you nothing.
To add a value in listbox,right click on listbox then select "edit items...".
Or you can make a action like : add text to listbox from textbox,do looping,or another...
From the design window from theToolbox add a TextBox and a Button to your form. (The ListBox is already there, right?) Enter the following code to your form in the code window.
'This is the code that runs when the users clicks the button
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'This is the code that copies the text in the text box to the list box
ListBox1.Items.Add(TextBox1.Text)
'This code clears the text in the text box
TextBox1.Text = ""
End Sub
The text in the gray window that appears in light gray and is preceded with an apostrophe are comments; not part of the code.
Now run the program and type in the text box. Click the button and the text you typed will appear in the list box. Now that you have had this brief introduction to Visual Basic . NET try searching for a beginners tutorial. Come back when you have some code that you wrote but doesn't turn out as you thought.

Textbox: missing first character typed on the TextBox

I have 2 text boxes to accept info but only one of them is need at the same time (One is for selection of the first letter and the other is for selection of any part of the name)
So I need to delete the text of the other textbox when the user start typing on the textbox
Something like this work:
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
TextBox1.Text = ""
End Sub
But there's a problem, the first character the user type is not displayed, I think is because the first character typed is used to launch the event.
Example:
TextBox1.Text = "A"
when the user click on TextBox2 and type michael the "m" is lost
I don´t want to use the "GotFocus" event because a simple TAB pulsed to jump from TextBox1 to another control can delete the text on TextBox1 when the user stop on TextBox2, even if he don´t want to type anything there
How can I manage this mistake?
Right answer:
From #Plutonix
"No user is going to expect this behavior and you will go mad trying to divine when to execute and when not to. A better thing might be to select the text on the Enter event - at least that has been seen before by users"

Message pop up?

What is the way to implement/mimic the Windows message popup that a user gets when, for instance when you try to rename a folder on the desktop using invalid characters?
I want to use this method in lieu of a message box.
You can achieve this by using ErrorProvider. It is located in your toolbox. Just drag and drop it into your form. To use it, example code
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text.Trim().Length > 6 Then
ErrorProvider1.SetError(TextBox1, "Input is too long!")
End If
End Sub
Method 2 : Using ToolTip. This can be found in your toolbox as well. Just drop it into your form and in the properties window, you can set the "tip" for each controls in your form.
Here is how it will look like when your cursor is hovering the controls.
If you dislike the rectangle pop up, you can change it to a ballon pop up by isBallon = true.

I have a "bug/glitch" in my vb program need assistance

I have a program that replaces every letter of the alphabet with something new inside the same textbox by clicking a button then buy clicking the button it translates it back to original text.
However when i run this program, yes it does work as needed but not 100%
Because after i click the button to translate, (yes it shows translated)
If delete the translated text and type something new, it goes back to the old text.
(this does not happen if i click the button again, it shows the orignal text. But if i type something new it will translate it.)
Any suggestions?
This is a continuation of your other question. You will need to reset your Boolean variable when you type in your TextBox i.e.
Private Sub TextBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
bConverted = False
End Sub

Odd ComboBox behavior on resize

I have an issue where a ComboBox control will change it's Text value when it is resized. Here is some sample code that I worked up:
Option Explicit On
Option Strict On
Public Class FMain
Private Sub FMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
uxComboBox.DropDownStyle = ComboBoxStyle.DropDown
uxComboBox.AutoCompleteSource = AutoCompleteSource.ListItems
uxComboBox.AutoCompleteMode = AutoCompleteMode.Suggest
ComboTest()
End Sub
Private Sub ComboTest()
Dim value As String = "6"
uxComboBox.Text = String.Empty
uxComboBox.Items.Clear()
uxComboBox.Items.AddRange(New String() {"4 9/16", "6 9/16", "7 9/16", "8 9/16"})
Dim index As Integer = uxComboBox.FindStringExact(value)
If uxComboBox.SelectedIndex index Then
uxComboBox.SelectedIndex = index
End If
If uxComboBox.SelectedIndex = -1 AndAlso _
Not String.Equals(uxComboBox.Text, value, StringComparison.OrdinalIgnoreCase) Then
uxComboBox.Text = value
End If
' unselect the text in the combobox
'
uxComboBox.Select(0, 0)
End Sub
End Class
Note that this form (FMain) has a single combobox on it (uxComboBox) that is docked to the top. When I run the code I see that the combobox has a value of "6" which is what I would expect. When I then resize the form, the combobox gets a value of "6 9/16" which is what I would NOT expect.
Does anyone know why this happens? Any suggested workarounds?
Thanks!
Stephen
Yes, this is a known bug in the native Windows implementation of ComboBox. There's another aspect to this bug. Put a button on your form and give it TabIndex = 0, change the CB's TabIndex to 1. Run it, the button will have the focus. Resize. Note that the ComboBox's text changes as before but now also gets highlighted, as though it has the focus. Even though it hasn't.
I think this bug has been around since Vista, it didn't get fixed in Win7. There's no known workaround for it.
When the form loads, ComboTest gets executed, and you see a '6', however when you resize it does not show the new data, sounds like you need to refresh the combo box, regardless of the resize or not.
Try uxComboBox.Refresh() immediately after the line uxComboBox.Items.AddRange.
And after the line 'ComboTest', set the selected index to 0 uxComboBox.Index = 0 also.
Hope this helps,
Best regards,
Tom.
I am using windows 10 and Visual Studio 2017. It appears that this bug is still around. With Hans Passant's answer above I worked around the problem in this way.
I had a combo as a control anchored left and right so it stretched when the form expanded. When the screen expanded, the combobox text was highlighted as if it had got focus even though it hadn't.
As a work around I took one of the anchors off and added it to text box that was next to it. Now my combo box doesn't expand with the screen, the text box does instead. I know its not a fix all solution but it may help someone in a similar situation to sort the problem.