|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Newbie: Event with Control ArrayThere is no control array. So, if I have a hundred buttons, do I list all 100 buttons after the Handle keyword? Is it how it is done in VB.NET? Thanks! Something like: Sub My_Button_Event_Handler(sender, your_event) Handle button1.click, button2.click, button3.click, ...buttonN-1.click, button<infinty>.click -- > There is no answer. http://spaces.msn.com/bzDaCat> There has not been an answer. > There will not be an answer. > That IS the answer! > And I am screwed. > Deadline was due yesterday. > > There is no point to life. > THAT IS THE POINT. > And we are screwed. > We will run out of oil soon. You have a hundred buttons that all do the same thing?
You're right, there is no control array. You can set up event handlers for each button and have them run the same routine. AddHandler myButton.Click, AddressOf RunThisRoutine You can write a routine that does this in a loop. This would be called from your Form Load event: 'This recurses, so it picks up controls inside panels, etc. Private Sub AddEventHandlers(ByVal ctrlContainer As Control) For Each ctrl As Control In ctrlContainer.Controls 'Debug.Print(ctrl.Name.ToString) If TypeOf ctrl Is Button Then AddHandler ctrl.Click, AddressOf RunThisRoutine End If 'if control has children, call this function recursively If ctrl.HasChildren Then AddEventHandlers(ctrl) End If Next End Sub Robin S. Show quoteHide quote "bz" <nospam@yahoo.com> wrote in message news:%23iBkI8EBHHA.3396@TK2MSFTNGP02.phx.gbl... > Hi, > > There is no control array. So, if I have a hundred buttons, do I list all > 100 buttons after the Handle keyword? > > Is it how it is done in VB.NET? > > Thanks! > > Something like: > > Sub My_Button_Event_Handler(sender, your_event) Handle button1.click, > button2.click, button3.click, ...buttonN-1.click, button<infinty>.click > > > > > -- >> There is no answer. >> There has not been an answer. >> There will not be an answer. >> That IS the answer! >> And I am screwed. >> Deadline was due yesterday. >> >> There is no point to life. >> THAT IS THE POINT. >> And we are screwed. >> We will run out of oil soon. > > http://spaces.msn.com/bzDaCat > Thanks. But what is the purpose of this line?
Show quoteHide quote > 'if control has children, call this function recursively > If ctrl.HasChildren Then > AddEventHandlers(ctrl) > End If "RobinS" <RobinS@NoSpam.yah.none> wrote in message news:DPidnY6T1fUgKM7YnZ2dnUVZ_v2dnZ2d@comcast.com... > You have a hundred buttons that all do the same thing? > > You're right, there is no control array. You can > set up event handlers for each button and have them > run the same routine. > > AddHandler myButton.Click, AddressOf RunThisRoutine > > You can write a routine that does this in a loop. > This would be called from your Form Load event: > > 'This recurses, so it picks up controls inside panels, etc. > Private Sub AddEventHandlers(ByVal ctrlContainer As Control) > For Each ctrl As Control In ctrlContainer.Controls > 'Debug.Print(ctrl.Name.ToString) > If TypeOf ctrl Is Button Then > AddHandler ctrl.Click, AddressOf RunThisRoutine > End If > 'if control has children, call this function recursively > If ctrl.HasChildren Then > AddEventHandlers(ctrl) > End If > Next > End Sub > > Robin S. > > "bz" <nospam@yahoo.com> wrote in message > news:%23iBkI8EBHHA.3396@TK2MSFTNGP02.phx.gbl... >> Hi, >> >> There is no control array. So, if I have a hundred buttons, do I list >> all 100 buttons after the Handle keyword? >> >> Is it how it is done in VB.NET? >> >> Thanks! >> >> Something like: >> >> Sub My_Button_Event_Handler(sender, your_event) Handle button1.click, >> button2.click, button3.click, ...buttonN-1.click, button<infinty>.click >> >> >> >> >> -- >>> There is no answer. >>> There has not been an answer. >>> There will not be an answer. >>> That IS the answer! >>> And I am screwed. >>> Deadline was due yesterday. >>> >>> There is no point to life. >>> THAT IS THE POINT. >>> And we are screwed. >>> We will run out of oil soon. >> >> http://spaces.msn.com/bzDaCat >> > > If you have panels on your form, and you have controls inside
the panels, they are children of the panel. The first "level" of AddEventHandlers will pick up the panels, but the children are invisible to the first "level". So you have to check each control to see if it has controls inside it, and if so, call the routine recursively to handle those controls. If those controls have more controls inside them, it will call it recursively again. Eventually, it will hit controls without children, and it will work itself back up the tree. This also works if you have a user-control that has controls inside it. You may not have that sort of thing now, but one day you will, and it's best to write the code to handle what *could* happen rather than what *should* happen. Put some panels on your form, and put some controls inside it, and then add a call to AddEventHandlers to your Form_Load. Uncomment the line in AddEventHandlers that prints out the name of the current control, and step through it. You'll see what I'm talking about. Robin S. Show quoteHide quote "bz" <nospam@yahoo.com> wrote in message news:eg3RDnPBHHA.4256@TK2MSFTNGP04.phx.gbl... > Thanks. But what is the purpose of this line? >> 'if control has children, call this function recursively >> If ctrl.HasChildren Then >> AddEventHandlers(ctrl) >> End If > > > > "RobinS" <RobinS@NoSpam.yah.none> wrote in message > news:DPidnY6T1fUgKM7YnZ2dnUVZ_v2dnZ2d@comcast.com... >> You have a hundred buttons that all do the same thing? >> >> You're right, there is no control array. You can >> set up event handlers for each button and have them >> run the same routine. >> >> AddHandler myButton.Click, AddressOf RunThisRoutine >> >> You can write a routine that does this in a loop. >> This would be called from your Form Load event: >> >> 'This recurses, so it picks up controls inside panels, etc. >> Private Sub AddEventHandlers(ByVal ctrlContainer As Control) >> For Each ctrl As Control In ctrlContainer.Controls >> 'Debug.Print(ctrl.Name.ToString) >> If TypeOf ctrl Is Button Then >> AddHandler ctrl.Click, AddressOf RunThisRoutine >> End If >> 'if control has children, call this function recursively >> If ctrl.HasChildren Then >> AddEventHandlers(ctrl) >> End If >> Next >> End Sub >> >> Robin S. >> >> "bz" <nospam@yahoo.com> wrote in message >> news:%23iBkI8EBHHA.3396@TK2MSFTNGP02.phx.gbl... >>> Hi, >>> >>> There is no control array. So, if I have a hundred buttons, do I list >>> all 100 buttons after the Handle keyword? >>> >>> Is it how it is done in VB.NET? >>> >>> Thanks! >>> >>> Something like: >>> >>> Sub My_Button_Event_Handler(sender, your_event) Handle button1.click, >>> button2.click, button3.click, ...buttonN-1.click, button<infinty>.click >>> >>> >>> >>> >>> -- >>>> There is no answer. >>>> There has not been an answer. >>>> There will not be an answer. >>>> That IS the answer! >>>> And I am screwed. >>>> Deadline was due yesterday. >>>> >>>> There is no point to life. >>>> THAT IS THE POINT. >>>> And we are screwed. >>>> We will run out of oil soon. >>> >>> http://spaces.msn.com/bzDaCat >>> >> >> > >
VB Controls In VB2005
difference between dataAdapter.InsertCommand/dataAdapter.SelectCom Get the value of a cell when row changes in DataGridView accessing data from a class event in a form Has anyone managed to send email using the smtp localhost? how to create var with same name but another index? remove xml file root tag add xml validation schema in the xml file Using variable names to change labels Why has debug.print stopped working??? |
|||||||||||||||||||||||