Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
VB
Public Class form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As New RadioButton
Dim x As Integer
Dim y As Integer
Dim company As String
y = TextBox1.Text
x = xval.Text
company = InputBox("WHICH COMPANY?", "VP")
a.Text = company
a.Location = New Point(x, y)
If (x > 520) Then
TextBox1.Text = y + 50
xval.Text = 130
Else
xval.Text = x + 130
End If
Controls.Add(a)

End Sub
End Class


My question is,when I add radio buttons using the button and stop debugging and open again I cannot find any of the radio buttons that I have added previously.
If I add some radio button with company name as its text,I can see it while it is running.
When I reopen, those new radio button controls which I have added will vanish.
Are there any suggestions?
The form should be getting updated with new companies.
(I used text boxes to store position(x,y).I have made the textbox invisible(textbox.visible=false)
Posted
Updated 2-Feb-13 3:50am
v2

You are adding the radio button dynamically during the execution of your program so it only exists while the program is running. Because of that, it is unknown to the Windows Form Designer. Rather than dynamically adding controls while the program is executing, use the Windows Form Designer in Visual Studio to design the form. The Windows Form Designer will generate all of the code to properly instantiate the radio button.

This is an example of what Windows Form Designer would generate for a radio button control:
Friend WithEvents rbFuture As System.Windows.Forms.RadioButton
...
Me.rbFuture = New System.Windows.Forms.RadioButton()
...
Me.rbFuture.Location = New System.Drawing.Point(8, 24)
Me.rbFuture.Name = "rbFuture"
Me.rbFuture.Size = New System.Drawing.Size(112, 16)
Me.rbFuture.TabIndex = 2
Me.rbFuture.Text = "Days in the future"
 
Share this answer
 
v3
When you add controls at run time, they do not become permanent - they occur temporarily to the current running instance of the program, and do not affect the EXE file in any way. So when it runs the next time, it appears as it did before you added any controls. Only controls added in teh designer are automatically included in your form when you compile the application.

If you want to add controls at run time and make them persistent, you have to store their details (in a file, or the configuration settings) so that they are preserved, and read that data back when you run the program and recreate the controls you wanted.

By the way, if you want your user to select one item from a list of companies, then you might be better off using a ComboBox (with the DropDownStyle property set to DropDownList) - it takes less screen space, and is easier to add new items to.
 
Share this answer
 
I think you could save those name and other settings in Application settings and set a flag While form load check for this flag and if its true add a btn based on those settings

http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/ed1491b4-65ed-4a06-a770-d37d863ec24e/[^]

http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/ed1491b4-65ed-4a06-a770-d37d863ec24e/[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900