hi guys,
In my program I have two classes ButtonTable and ButtonShow.
ButtonTable is a class used to add a series of buttons on a hashtable & a HostForm. ButtonShow code together with the ButtonShow designer is used to show the buttons and do some other manipulation on the form.
Previously in my ButtonTable class I have a ClickHandler which handles the click event of the buttons. It works well, e.g. if I click a button with name"ppp" a message box will come out and shows"you have clicked button ppp". But I now wanna show some controls like labels on the form that contain the button's information I've clicked.
It seems I've faced some problems when trying to do this. These two classes are sth like "isolated" from each other. I think if I wanna do this, I need either
1,make the controls on the form i.e. in ButtonShow Class available in ButtonTable class. or
2,make the ClickHandler in ButtonTalbe class available in ButtonShow class.
I may need to add many controls that contain the button's information, this will make the first way become tedious. So I now trying to make the clickHandler in ButtonTable Class accessible in ButtonShow class.
Above is part of the code related to the problem. In ButtonShow Class's ClickHandler line, the error is'Public Sub ClickHandler(sender As Object, e As System.EventArgs)' has multiple definitions with identical signatures.' I know maybe what I'm trying to do is stupid. So please kindly leave your comments.
Any help will be very appriciated! Thank you.
In my program I have two classes ButtonTable and ButtonShow.
ButtonTable is a class used to add a series of buttons on a hashtable & a HostForm. ButtonShow code together with the ButtonShow designer is used to show the buttons and do some other manipulation on the form.
Previously in my ButtonTable class I have a ClickHandler which handles the click event of the buttons. It works well, e.g. if I click a button with name"ppp" a message box will come out and shows"you have clicked button ppp". But I now wanna show some controls like labels on the form that contain the button's information I've clicked.
It seems I've faced some problems when trying to do this. These two classes are sth like "isolated" from each other. I think if I wanna do this, I need either
1,make the controls on the form i.e. in ButtonShow Class available in ButtonTable class. or
2,make the ClickHandler in ButtonTalbe class available in ButtonShow class.
I may need to add many controls that contain the button's information, this will make the first way become tedious. So I now trying to make the clickHandler in ButtonTable Class accessible in ButtonShow class.
VB.NET:
Public Class ButtonTable
Private ReadOnly HostForm As System.Windows.Forms.Form
Public hashObj As Hashtable
Public aButton As System.Windows.Forms.Button
Public Sub AddNewButton()
aButton = New Button
hashObj = New Hashtable
' some more code goes on here
HostForm.Controls.Add(aButton)
AddHandler aButton.Click, AddressOf ClickHandler
Public Sub New(ByVal host As System.Windows.Forms.Form)
HostForm = host
Me.AddNewButton()
End Sub
Public Sub ClickHandler(ByVal sender As Object, ByVal e As System.EventArgs)
'MessageBox.Show("you have clicked equipment " & CType(CType(sender, _
'System.Windows.Forms.Button).Name, String))
End Sub
End Class
VB.NET:
Public Class ButtonShow
Dim MyControlTable As ButtonTable
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
MyControlTable = New ButtonTable(Me)
Dim btn As Button
btn = MyControlTable.aButton
AddHandler btn.Click, AddressOf ClickHandler
End Sub
#End Region
Public Sub ClickHandler(ByVal sender As Object, ByVal e As System.EventArgs)
MessageBox.Show("you have clicked equipment " & CType(CType(sender, _
System.Windows.Forms.Button).Name, String))
End Sub
End Class
Any help will be very appriciated! Thank you.