Solved

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

Posted on 2013-01-15
5
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Import Data from Multiple Text Files in Excel 12 86
Generate Numbers in JQuery file 11 72
VB.NET Application Installation with sqlserver 8 45
Filtering a datagrid view 8 34
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 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