TextBox.TextChanged在表单加载前触发两次 [英] TextBox.TextChanged fires twice befor Form load

查看:254
本文介绍了TextBox.TextChanged在表单加载前触发两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,
我使用加载项从访问表单到vb.net表单动态创建控件,在加载设计并使用加载项创建控件之后,我尝试在其中一个文本框上使用textchanged并触发在表单加载之前和在textbox1.text =上两次?问题是什么?
在此先感谢您的帮助=)

Hey,
I''m using Add-in to create controls dynamically from access form to vb.net form , after loading the design and creating the controls using the add-in I''ve tried to use textchanged on one of the textboxes and it fires twice even before the form load and on textbox1.text = something ? what the problem would be ?
thank in advance for you help =)

推荐答案

您在超过1个位置更改了textbox1.text.
You change your textbox1.text in more than 1 locations.
1. InitializeComponent();
//------------And other
2. Form_Load() //OR somewhere else

所以, TextChanged 事件触发两次.


声明一个全局变量以计算文本更改的次数.在TextChange()中增加它.

仅当计数器大于2时才处理文本更改.

将其放在您的initializecomponent中,以查看其是否被调用两次.
Declare a global variableto count the number of text changes. Increment it in TextChange().

Handle your textchange only when the counter is greater than 2.

Put it in your initializecomponent to see if its called twice.


我如何在外接程序中创建文本框
1.加载访问控制
2.检查其是否为文本框
3.创建一个文本框并调用一个名为AddTextBox的函数

私有函数AddTextBox(byVal objWindow作为EnvDTE.Window,ByVal TextBoxName作为字符串)作为TextBox

Dim ObjDesignerHost作为IDesignerHost
Dim ObjIComponent作为Icomponent
Dim ObjPropertyDescriptor作为ProperityDescriptor
昏暗的TxtBox作为文本框
Dim ObjIComponentInitializer作为IComponentInitializer

ObjDesignerHost = DirectCast(ObjWindow.Object,IDesignerHost)
ObjIComponent = ObjDesignerHost.CreateComponent(GetType(TextBox),TextBoxName)
ObjPropertyDescriptor = System.ComponentModel.TypeDescriptor.GetProperties(ObjIComponent).Item("Parent")
ObjPropertyDescriptor.SetValue(ObjIComponent,ObjDesignerHost.RootComponent)
TxtBox = DirectCast(ObjIComponent,TextBox)
ObjIComponentInitializer = TryCast(ObjDesignerHost.GetDesigner(TxtBox),IComponentInitializer)
如果(不是ObjIComponentInitializer没什么)那么
ObjIComponentInitializer.InitializeNewComponent(defaultValues:= Nothing)
TxtBox.Text = TextBoxName
返回TxtBox

结束功能

我做错什么了吗?
How I''m Creating my textbox in my Add-in
1.Load the access control
2.Check if its a text box
3.create a textBox and Call a function called AddTextBox

Private Function AddTextBox(byVal objWindow as EnvDTE.Window, ByVal TextBoxName As String) As TextBox

Dim ObjDesignerHost As IDesignerHost
Dim ObjIComponent As Icomponent
Dim ObjPropertyDescriptor As ProperityDescriptor
Dim TxtBox As TextBox
Dim ObjIComponentInitializer As IComponentInitializer

ObjDesignerHost = DirectCast(ObjWindow.Object , IDesignerHost)
ObjIComponent=ObjDesignerHost.CreateComponent(GetType(TextBox),TextBoxName)
ObjPropertyDescriptor= System.ComponentModel.TypeDescriptor.GetProperties(ObjIComponent).Item("Parent")
ObjPropertyDescriptor.SetValue(ObjIComponent,ObjDesignerHost.RootComponent)
TxtBox=DirectCast(ObjIComponent,TextBox)
ObjIComponentInitializer=TryCast(ObjDesignerHost.GetDesigner(TxtBox),IComponentInitializer)
If(Not ObjIComponentInitializer Is Nothing) Then
ObjIComponentInitializer.InitializeNewComponent(defaultValues:=Nothing)
TxtBox.Text=TextBoxName
Return TxtBox

End Function

Am I doing anything wrong ?


这篇关于TextBox.TextChanged在表单加载前触发两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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