Click here to Skip to main content
12,700,376 members (34,131 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
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
xval.Text = x + 130
End If

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 2-Feb-13 4:47am
Updated 2-Feb-13 4:50am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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"
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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[^][^]

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 3 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100