Re: *Ironic angry face* Dynamically creating methods for dynamically created buttons
Like this?
Code:
Public Class Form1
Dim OpePro As String
Dim posl As Integer
Dim NPB(7) As Button
Public i As Integer
Private Sub Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Add.Click
OpenFileDialog1.ShowDialog()
OpePro = OpenFileDialog1.FileName
posl = posl + 75
For Me.i = 0 To OpePro.Length - 1
NPB(i) = New Button
NPB(i).Text = OpePro(i)
NPB(i).Width = 75
NPB(i).Height = 62
NPB(i).Left = posl
NPB(i).Top = 0
Controls.Add(NPB(i))
AddHandler NPB(i).Click, AddressOf Button1_Click
Next
End Sub
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Process.Start(OpePro)
End Sub
Private Sub Task_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Task.Click
System.Diagnostics.Process.Start("taskmgr.exe")
End Sub
Private Sub Calc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calc.Click
System.Diagnostics.Process.Start("calc.exe")
End Sub
End Class
Re: *Ironic angry face* Dynamically creating methods for dynamically created buttons
Buttons are written to the same place.
add 80 or so each time
Re: *Ironic angry face* Dynamically creating methods for dynamically created buttons
Code:
NPB(i) = New Button
I get an error. index was outside to bounds on the array
Re: *Ironic angry face* Dynamically creating methods for dynamically created buttons
should I make OpePro an array?
Re: *Ironic angry face* Dynamically creating methods for dynamically created buttons
Try something like this:
Code:
Dim btn as Button = New Button()
btn.name = "MyButton"
'.... some time later
Dim activeButton As Button = CType(Me.Controls("MyButton"), Button)
activeButton.Text = "Hooray"
Look at btn
Re: *Ironic angry face* Dynamically creating methods for dynamically created buttons
I did that and when I make a second button, the first one disappears.
Re: *Ironic angry face* Dynamically creating methods for dynamically created buttons
also I just realized I excluded
Code:
btn.name = "MyButton"
because I didn't know where to put it.
Re: *Ironic angry face* Dynamically creating methods for dynamically created buttons
SUCCESS!
Code:
Public Class Form1
Dim OpePro(7) As String
Dim posl As Integer
Dim NPB_1 As Button
Dim NPB_2 As Button
Dim i As Integer = i = OpePro.Length - 1
Private Sub Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Add.Click
posl = posl + 75
NPB_1 = New Button
NPB_2 = New Button
If i = 0 Then
OpenFileDialog1.ShowDialog()
OpePro(i) = OpenFileDialog1.FileName
NPB_1.Text = i
NPB_1.Width = 75
NPB_1.Height = 62
NPB_1.Left = 0
NPB_1.Top = 0
Controls.Add(NPB_1)
AddHandler NPB_1.Click, AddressOf Button1_Click
i = i + 1
End If
If i = 1 Then
OpenFileDialog1.ShowDialog()
OpePro(i) = OpenFileDialog1.FileName
NPB_2.Text = i
NPB_2.Width = 75
NPB_2.Height = 62
NPB_2.Left = 75
NPB_2.Top = 0
Controls.Add(NPB_2)
AddHandler NPB_2.Click, AddressOf Button2_Click
i = i + 1
End If
End Sub
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Process.Start(OpePro(0))
End Sub
Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Process.Start(OpePro(1))
End Sub
Private Sub Task_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Task.Click
System.Diagnostics.Process.Start("taskmgr.exe")
End Sub
Private Sub Calc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calc.Click
System.Diagnostics.Process.Start("calc.exe")
End Sub
End Class
Now, how do I pause between if statements.
Re: *Ironic angry face* Dynamically creating methods for dynamically created buttons
I will end this thread here. Thank you dglienna and Alsvha. You both really helped me with brainstorming.