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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you enter a range when using MixedControls?

Status
Not open for further replies.

OzzieGeorge

Programmer
Jan 14, 2005
2,625
AU
I have a form that has 256 buttons on it and want to change a line of text on the form depending on which button the mouse pointer is over. I was using 8 arrays in VB6 and using case to control this.

I'm now trying to do the same in 2005 and so I am looking at using MixedControls to achieve the same ends. I am struggling with the fact that I have to enter each button individually! It starts with button0 and goes up to button 255 inclusive so is there an alternative to typing button0, button1......etc

Or should I be using some other method?
 
This just shows 25 but change to 255.
Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim NewLocation As New Point
Dim NewSize As New Point(75, 23)

For i As Integer = 0 To 25
Dim newButton As New Button
newButton.Location = NewLocation
newButton.Name = "Button" & i.ToString
newButton.Text = newButton.Name
AddHandler newButton.Click, AddressOf NewButtonClick
Me.Controls.Add(newButton)
NewLocation.X += newButton.Width
If NewLocation.X + newButton.Width > Me.Width Then
NewLocation.X = 0
NewLocation.Y += newButton.Height
End If
Next
End Sub

Private Sub NewButtonClick(ByVal sender As Object, ByVal e As EventArgs)
Dim btn As Button = DirectCast(sender, Button)
Dim num As Integer = Integer.Parse(btn.Name.Substring(6).ToString)
Me.Text = (String.Format("Button {0} was clicked", num.ToString))
End Sub
 
Wayne

Thanks for that but can I just change that to mouseover or mouse move or will it only work with a click?
 
I have just got to try the code above. It is interesting and as I am trying to learn it is good but I can't work it out at the moment. One problem I have is the buttons already exist and the text won't be just the button number I have 8 rows of 32 and have to show the row number and position in the row. It's beginning to look as though I may just have to go back to VB6!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top