0
有兩種形式,第一種包含標籤按鈕,當所有使用相同的形式,但作爲一個「昏暗的form2作爲新的形式。第二種形式使用選擇的情況下確定哪些按鈕繪製和標題等我正在努力的部分是我創建的新按鈕,我需要在那裏單獨名稱到事件處理程序子項vb.net將字符串傳遞到按鈕單擊子
所以當我點擊新建的按鈕,他們都做同樣的過程,我需要他們在「按鈕操作子」
Public Class DiaryAddForms
Private Sub DiaryAddForms_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
' gets the selected case from the button pushed on diary, then draws the appropreate buttons labels ect to the form//
Public Sub GetFormType(ByVal Type As String)
Select Case Type
Case "add"
' changes the text of the form to the button clicked,
Me.Text = ("Add Appointment")
' passes the appropreate data for the buttons required for add appointment to the "button" sub''
Button(x:=180, y:=200, name:="Cfind_Btn", title:="Find", hieght:=30, width:=50)
Button(x:=235, y:=200, name:="Cnew_Btn", title:="New", hieght:=30, width:=50)
Case "edit"
Me.Text = ("Edit Appointment")
Case "delete"
Me.Text = ("Delete Appointment")
Case "endday"
Me.Text = ("End Day")
End Select
End Sub
' rather than have to create each button individual the data types of each different button can be passed into this sub and then created.
Public Sub Button(ByVal x As Integer, ByVal y As Integer, ByVal name As String, ByVal title As String, ByVal hieght As Integer, ByVal width As Integer)
Dim btn As Button
btn = New Button
With btn
.Location = New Point(x, y)
.Text = title
.Name = name
.Width = width
.Height = hieght
Controls.Add(btn)
End With
AddHandler btn.Click, AddressOf BtnOperation
End Sub
Public Sub BtnOperation(ByVal sender As Object, ByVal e As EventArgs)
'i need a way to fetch the btn.name'
'so then with the name use "select case" to get appropreate action of the btn. '
End Sub
End Class
將'sender'強制轉換爲'Button'實例。在C#中,你可以使用'((Button)sender).Name'。 – Spooky