I current have a combobox on a form that I created in design mode. I can
therefore simply dbl click the control, and code the actions to occur when
events are fired such as when the user changes the selected item.
Now I need to add a combo to my toolbar, and the only way to do it is in
code at run time :
Dim myCombo as new combo()
toolbar1.controls.add(myCombo)
This add a combo box to my toolbar, but of course there are no event linked
to this control.
I want to do things(look up sql tables and so on) when the user changes the
selected item in the combo, but have no idea where to put the code, and how
to make the code fire when the event action happens
What do I do ?
Write a method such as
Private Sub YourHandlerMethod(sender As Object, e As EventArgs)
...
End Sub
>and how
>to make the code fire when the event action happens
AddHandler myCombo.SelectedIndexChanged, AddressOf YourHandlerMethod
Mattias
===
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
"Wheres Wally" <no...@none.com> schrieb:
> Dim myCombo as new combo()
> toolbar1.controls.add(myCombo)
>
> This add a combo box to my toolbar, but of course there are
> no event linked to this control.
AddHandler (and RemoveHandler):
\\\
Private Sub Test()
Dim btn As New Button()
With btn
.Left = 0
.Top = 0
.Width = 100
.Height = 100
End With
AddHandler btn.Click, AddressOf Me.MyButton_Click
Me.Controls.Add(btn)
End Sub
Private Sub MyButton_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
)
MsgBox("It works!")
End Sub
///
Regards,
Herfried K. Wagner
In the following exaplme, I am creating textbox at a
runtime, and then I am adding event in it.
first create a class file.
Public Class clsTitleText
Inherits System.Windows.Forms.Label
Public a As Integer
Public b As Integer
Private Sub lblTitleText_MouseDown(ByVal sender As
Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Handles MyBase.MouseDown
MsgBox ("Event Fired")
End Sub
End Class
and now add the following code when u want to create a
control at runtime:
Dim lblTitleText As New clsTitleText()
lblTitleText.Text = "This is runtime designed textbox"
lblTitleText.Height = "85"
lblTitleText.Width = "30"
Dim myPoint As New Point()
myPoint.X = "0"
myPoint.Y = "0"
lblTitleText.Location = myPoint
Form1.Controls.Add(lblTitleText)
I hope this helps,
Dhaval Faria.
Dim ctlExtender As VBControlExtender
Private Sub Form_Load()
Set ctlExtender = Controls.Add
("Project1.UserControl1", "MyControl")
With ctlExtender
.Visible = True
.Top = 1000
.Left = 1000
End With
End Sub
Private Sub extObj_ObjectEvent(Info As EventInfo)
' Program the events of the control using Select Case.
Select Case Info.Name
Case "UserName"
' Check User name value.
MsgBox Info.EventParameters("UserName").Value
' Other cases now shown
Case Else ' Unknown Event
' Handle unknown events here.
End Select
End Sub