Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a TextBox that programmatically added to the form. I am using it for multiple purposes. They are:
1. Indexing a number beside the text
2. Change the text or number in the textbox
3. Using this text in a Database for query purposes
This is a production environment application that is used to print a 4X6 inch label from the data on the screen, keep up with production data and print a production report.
In one print method I am printing the client area of the form. The textbox is one of the controls being displayed in the client area. After the form data is updated with then next index number etc.(this number is inserted into the textBox) At this time the textbox Text becomes highlighted and the only way I have found is to click on it to remove the highlighted area. Of course the operator would have to click on it for each print cycle and this would be inconvenient to say the least.
I have tried several methods that a search revealed but in VB2010 they don't seem to either be in the parameters or they don't work as shown. Below is the code I use to build the textbox. So I cannot use textbox1.??? I have to use the program method of accessing the control and for some reason not all the parameters or functions for the control shows up. Here I am just showing the control I have the problem with. If my label has two textboxes then the other textbox that is added last is the highlighted one. One method said to use another textbox and hide it but this seams like a waste of performance to have to access it.

VB
Dim AddTextBox As New TextBox
       Me.Controls.Add(AddTextBox)
       AddTextBox.Multiline = True
       AddTextBox.Name = "IndexedTextBox"
       For Each C As Control In Controls
           If C.Name.Contains("Indexed") Then
               C.Location = New Point(10 * TextBoxcount, 25 * TextBoxcount)
               C.Text = "Indexed # 1"
               C.Anchor = AnchorStyles.None
               C.Enabled = True
               C.Name = "IndexedTextBox"
               ResizeAddHandler(C)
           End If
       Next

I have been unable to find a way to handle the highlight. Using a label control would be difficult to come up with a method to change the text from the actual print form client area so I am stuck with a textbox being displayed.
Any help will be much appreciated.

Curtis
Posted
Updated 8-Aug-11 16:22pm
v2

If the highlighting that you are talking about is really that the text is being selected inside the textbox, you can modify it by changing the textbox .SelectionStart. Set it to zero and the cursor will be at the first position in the textbox. Set it equal to the textbox's length and the cursor will be at the end. There are a couple of other .Selection options you could play with. For example, .SelectionLength sets how many characters are selected.

If the user isn't allowed to enter data into this textbox you may also want to consider setting the textbox's .TabStop = False which would stop the user from being able to tab into the textbox (at which point the default is to select the text inside the textbox) and maybe even .ReadOnly = True which stops users from entering data into the textbox.

Here[^] is the MSDN on .SelectionStart
 
Share this answer
 
Hi Kschuler,
Your link on selection start gave me the answer, below is the solution.
VB
Dim instance As TextBox = Controls.Item(AddedCIndex(x))
               instance.SelectionStart = 0


The controls.item is just using an index to the textbox control. So when I declared the instance and made it equal to the controls item index (which is the IndexedTextBox) and then set the SelectionStart value to 0 this allowed the highlight to be removed. I am using the AddedCIndex as a list of controls in the client area, This way I dont have to loop thru all the controls in the form but just for the ones I need to update.

Thanks that link was what I could not find in the searches.

Thanks again.

Curtis
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900