Question Save dynamically created button permanently to the form.

Joined
Dec 8, 2014
Messages
5
Programming Experience
1-3
VB.NET:
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'some code
Dim MyButton As New Button()


        With MyButton
            .Location = New Point(12, 12)
            .Size = New Size(75, 30)
            .TabIndex = 0
            .Text = TextBox1.Text


        End With
        scriptexplorer.Controls.Add(MyButton)


        AddHandler MyButton.Click, AddressOf MyButton_Click


        MsgBox("Done!")


Private Sub MyButton_Click(ByVal obj As Object, ByVal e As EventArgs)
        Try
            scriptexplorer.RichTextBox1.Text = Runcmd(mydocpath & "\" + TextBox1.Text + ".ps1")
            scriptexplorer.RichTextBox1.Text = "success!"


        Catch
            scriptexplorer.RichTextBox1.Text = "error"
        End Try
    End Sub


So, here I am trying to create a new button with text specified in textbox1. The button is created in the form 'scriptexplorer' but the next time i load the form, its gone. So, i guess I need to save this info for the button created and call it everytime the form loads but dont know how to do it?

Please help me !
 
You need to determine what information is required to describe the Button and save that somewhere, e.g. a database or file. When you then run your application, you need to read that information from the location you saved it and use that information to create the Button. Presumably the minimum information you would require is a location and the information to use when the Button is clicked. You might want the text to display on the Button too, and possibly things like colour, etc, in advanced cases. After you've determined what information to save, you then need to decide where you're going to save it. It's information like any other so saving it will be the same as it would be for any other information.
 

Latest posts

Back
Top