creating button class

Joined
Nov 26, 2006
Messages
9
Programming Experience
Beginner
i am trying to create button class with ceratin defulat properties.

I want to use this button class as an array in my forms. I am getting stuck at creating the class itself.
 
Here is a start, notice the Inherits keyword used to specify that the class inherits from the System.Windows.Forms.Button class:
VB.NET:
Public Class somebutton
    Inherits Button
 
    Public Sub New()
        Me.Text = "default text"
    End Sub
End Class
I don't know what you mean with "use this button class as an array in my forms". The Controls property is a collection of all controls on form, maybe you want to add some of these buttons here?
VB.NET:
For i As Integer = 1 To 3
    Dim btn As New somebutton
    btn.Name = "btn" & i.ToString
    btn.Location = New Point(10, i * btn.Height)
    Me.Controls.Add(btn)
Next
 
Dear John

thanks



I have written this code

For j = 0 To Me.DataSet1.Tables("usr_mnu1").Rows.Count - 1
' Create a new Button
Dim newButton As New Button
' Add properties to the form.
newButton.Parent = Me.GroupBox1
newButton.BringToFront()
newButton.Name =
"btn" + j.ToString
newButton.Text =
Me.DataSet1.Tables("usr_mnu1").Rows(j).Item("menuname")
newButton.Location =
New Point(controlLocation.X, j * newButton.Height)
controlLocation.Y += newButton.Height + 5
newButton.Visible =
True
' Add the two event handlers.
AddHandler newButton.Click, AddressOf myButtonHandler_Click
AddHandler newButton.MouseHover, AddressOf myButtonHandler_MouseHover
' Add the control to the collection of controls.
Me.Controls.Add(newButton)
Next

My form is divided into 5 sectons and i am trying to place the button in groupbox1 when i run the form it is not giving any error but it does not display also on the form

Thanks and Regards
Arun Kumar Menon
 
Either set its Parent property or Add it to the parents Controls collection, the last of these assignments goes.
 
Back
Top