从文本框中删除突出显示或关闭突出显示 [英] Removing highlight from TextBox or turn Highlighting off

查看:87
本文介绍了从文本框中删除突出显示或关闭突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以编程方式添加到表单的TextBox.我将其用于多种用途.它们是:
1.在文字旁边索引一个数字
2.在文本框中更改文本或数字
3.在数据库中将此文本用于查询目的
这是一个生产环境应用程序,用于从屏幕上的数据打印4X6英寸的标签,跟上生产数据并打印生产报告.
在一种打印方法中,我正在打印表单的客户区域.文本框是在客户端区域中显示的控件之一.表单数据更新后,再加上下一个索引号等(此数字已插入到文本框中).此时,文本框文本"被突出显示,而我发现的唯一方法是单击它以删除突出显示的区域.当然,操作员在每个打印周期都必须单击它,至少这样会很不方便.
我尝试了几种搜索显示的方法,但是在VB2010中,它们似乎不在参数中,或者它们无法按所示方式工作.下面是我用来构建文本框的代码.所以我不能使用textbox1.我必须使用访问控件的程序方法,由于某种原因,并非所有参数或控件的功能都显示出来.在这里,我只是显示我有问题的控件.如果我的标签有两个文本框,则最后添加的另一个文本框是突出显示的文本框.一种方法说使用另一个文本框并将其隐藏,但是这种缝隙似乎是浪费性能,不得不访问它.

  Dim  AddTextBox  As  文本框
        .Controls.Add(AddTextBox)
       AddTextBox.Multiline = 
       AddTextBox.Name = " 
       对于 每个 C  As 控件控件中
           如果 C.Name.Contains("  span>)然后
               C.Location = 新建 Point( 10  * TextBoxcount, 25  * TextBoxcount)
               C.Text = " 
               C.Anchor = AnchorStyles.None
               C.Enabled = 正确
               C.Name = " 
               ResizeAddHandler(C)
           结束 如果
       下一步


我一直找不到找到重点的方法.使用标签控件很难想出一种方法来更改实际打印表单客户区域中的文本,因此我被显示的文本框困住了.
任何帮助将不胜感激.

Curtis

解决方案

如果您所说的突出显示实际上是在文本框中选择了文本,则可以通过更改文本框.SelectionStart对其进行修改.将其设置为零,光标将在文本框中的第一个位置.将其设置为等于文本框的长度,光标将位于末尾.您还可以使用其他几个.Selection选项.例如,.SelectionLength设置选择多少个字符.

如果不允许用户在此文本框中输入数据,则您可能还需要考虑设置文本框的.TabStop = False,这将阻止用户使用Tab键进入文本框(此时默认为选择文本框内的文本),甚至.ReadOnly = True都可以阻止用户将数据输入文本框.

此处 [ ^ ]是.SelectionStart上的MSDN. 您选择开始时的链接给了我答案,下面是解决方法.

  Dim 实例 As  TextBox = Controls.Item(AddedCIndex(x))
               instance.SelectionStart =  0 



controls.item仅使用文本框控件的索引.因此,当我声明该实例并使它等于控件项索引(即IndexedTextBox),然后将SelectionStart值设置为0时,这允许删除突出显示.我将AddedCIndex用作工作区中的控件列表,这样,我不必遍历表单中的所有控件,而只需要更新那些需要更新的控件.

谢谢,那个链接是我在搜索中找不到的.

再次感谢.

柯蒂斯(Curtis)


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.

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

解决方案

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


Hi Kschuler,
Your link on selection start gave me the answer, below is the solution.

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


这篇关于从文本框中删除突出显示或关闭突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆