Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic button creation - no handler for gotfocus - workround?

Status
Not open for further replies.

Kenny62

Programmer
Mar 3, 2004
54
GB
Hi, I've created a number buttons on a form dynamically.
I then setup handlers for MouseHover,MouseLeave, Click etc: See below:

Private Sub CreatebtnControls()
Dim answer As String
Dim index As Integer

answer = 5
For index = 1 To CInt(answer)
' Create the textbox
Dim Btn As New Button
Btn.Size = New System.Drawing.Size(400, 30)
Btn.Location = New System.Drawing.Point(50, 40 + index * 40)
'Btn.Visible = True
' we need this to identify the control
Btn.Name = "Btn #" & CStr(index)
' add to the controls collection
Me.Controls.Add(Btn)

' prepare event handlers
AddHandler Btn.MouseHover, AddressOf Btn_MouseHover
AddHandler Btn.MouseLeave, AddressOf Btn_MouseLeave
AddHandler Btn.GiveFeedback, AddressOf Btn_GiveFeedback
AddHandler Btn.Click, AddressOf Btn_Click

Next
End Sub

Private Sub Btn_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs)
Debug.WriteLine("Btn_MouseHover in " & CStr(CType(sender, Button).Name))

End Sub ....

For some reason MS didn't provide a gotfocus handler - i need this handler or something similar.
(When the user tabs from button to button the gotfocus event should be triggered and code execute...)
Does anyone one know of a workaround of method for implementing something like gotfocus.

Thanks for help in advance, Ken
 
There is a GotFocus event...or am I not fully understanding your question? e.g
Code:
AddHandler Btn.GotFocus, AddressOf Btn_GotFocus


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
There isn't a GotFocus event so i can't use code like:

AddHandler Btn.GotFocus, AddressOf Btn_GotFocus

I need an alternative or workaround - thanks for the reply.
 
There isn't a GotFocus event
There is...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Hello, ca8msm. If you you create a button by dragging a button control from the toolbar to a forrm the GotFocus event is available.
If yoy create a button like:

Dim Btn As New Button

When you code the handler like:

AddHandler Btn.

A list of events is provided after the dot - GotFocus event is not listed. (I'm using VS.NET 2003 version 7.1.3088)

Ken
 
Kenny

My version is the exact same , and yet I can see the GotFocus event. I have SP1 installed, do you?



Sweep
...if it works dont f*** with it
...if its f****ed blame someone else
...if its your fault that its f***ed, say and admit nothing.
 
What version of the framework are you using as I do have the .GotFocus event listed (I'm on version 1.1 SP1 of the framework).

Also, make sure you have unchecked the "Hide Advanced Members" checkbox in:

Tools-->Options-->Text Editor-->Basic-->General--


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks you ca8msm - The 'Hide Advance Members' was checked -having unchecked this item - GotFocus event is now listed.

Framework is 1.14322 SP1.

Thanks again, Ken
 
Since when is gotfocus advanced? What's next? Click?

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
I don't even know why Microsoft decided there was a need to hide these "advanced" members in the first place!


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Out of the box they are hidden for VB and not for C#. An annoying difference that could get anyone
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top