Solved

Creating New Objects on a Winform and Saving all object when program running

Posted on 2013-01-15
5
209 Views
Last Modified: 2013-01-15
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 BuNoktayaMasaEkleToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BuNoktayaMasaEkleToolStripMenuItem.Click
        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
0
Comment
Question by:arozzy
  • 2
  • 2
5 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 38779955
The only way to do that is to RECREATE those controls on next run.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 38780282
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.
0
 

Author Comment

by:arozzy
ID: 38780300
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).ToString
            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
0
 

Author Comment

by:arozzy
ID: 38780312
Problem solved with this,

Thank you again

button.ContextMenuStrip = ContextMenuStrip1
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 38780405
To wire up dynamic controls, use the AddHandler() method.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question