Solved

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

Posted on 2013-01-15
5
212 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 86

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 86

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

688 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