Solved

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

Posted on 2013-01-15
5
207 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
Comment Utility
The only way to do that is to RECREATE those controls on next run.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
Comment Utility
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
Comment Utility
Problem solved with this,

Thank you again

button.ContextMenuStrip = ContextMenuStrip1
0
 
LVL 85

Expert Comment

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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now