arozzy
asked on
Creating New Objects on a Winform and Saving all object when program running
Hi experts,
How can I add new object like buttons or listviews on a forms when program running and save created objects. And created objects are needed to be on the same form when program running secondly and after.
I have used a contexmenustrip for adding buttons with right click. But when program secondly runs, the created objects are not on the form.
How can I save objects all the time until user deleting objects.
Thank you
Oguzhan
Private Sub BuNoktayaMasaEkleToolStrip MenuItem_C lick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BuNoktayaMasaEkleToolStrip MenuItem.C lick
Dim btn1 As New Button
btn1.Text = "New Button"
Dim x As Integer
Dim y As Integer
x = MousePosition.X
y = MousePosition.Y
btn1.Location = New Point(x, y)
btn1.Size = New Size(100, 100)
Me.Controls.Add(btn1)
Me.ResumeLayout(True)
End Sub
How can I add new object like buttons or listviews on a forms when program running and save created objects. And created objects are needed to be on the same form when program running secondly and after.
I have used a contexmenustrip for adding buttons with right click. But when program secondly runs, the created objects are not on the form.
How can I save objects all the time until user deleting objects.
Thank you
Oguzhan
Private Sub BuNoktayaMasaEkleToolStrip
Dim btn1 As New Button
btn1.Text = "New Button"
Dim x As Integer
Dim y As Integer
x = MousePosition.X
y = MousePosition.Y
btn1.Location = New Point(x, y)
btn1.Size = New Size(100, 100)
Me.Controls.Add(btn1)
Me.ResumeLayout(True)
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Right...you'd have to save all the information about the added controls (location, size, text, etc.) in a file (possibly XML?), and then read the file on Form load and re-created those controls again.
ASKER
Thanks for your reply,
How can I add click event for these buttons ? Please help
Private Sub Form25_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dset As New DataTable
adptr.Fill(dset)
For i = 0 To dset.Rows.Count - 1
Dim button As New Button
Dim aa As String
aa = dset.Rows(i).Item(1).ToStr ing
button.Text = aa
button.ForeColor = Color.Black
button.Font = New Font("Arial", 12, FontStyle.Bold)
Dim x As Integer
Dim y As Integer
x = 60 + x + 50
y = 50
button.Location = New Point(x, y)
button.Size = New Size(100, 100)
Me.Controls.Add(button)
Me.ResumeLayout(True)
Next
How can I add click event for these buttons ? Please help
Private Sub Form25_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dset As New DataTable
adptr.Fill(dset)
For i = 0 To dset.Rows.Count - 1
Dim button As New Button
Dim aa As String
aa = dset.Rows(i).Item(1).ToStr
button.Text = aa
button.ForeColor = Color.Black
button.Font = New Font("Arial", 12, FontStyle.Bold)
Dim x As Integer
Dim y As Integer
x = 60 + x + 50
y = 50
button.Location = New Point(x, y)
button.Size = New Size(100, 100)
Me.Controls.Add(button)
Me.ResumeLayout(True)
Next
ASKER
Problem solved with this,
Thank you again
button.ContextMenuStrip = ContextMenuStrip1
Thank you again
button.ContextMenuStrip = ContextMenuStrip1
To wire up dynamic controls, use the AddHandler() method.