Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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
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 2-Feb-13 3:47am
Edited 2-Feb-13 3:50am
ProgramFOX124.6K
v2
Rate this: bad
good
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"
  Permalink  
v3
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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
 
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/[^]
  Permalink  
v3

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



Advertise | Privacy | Mobile
Web03 | 2.8.141022.1 | Last Updated 3 Feb 2013
Copyright © CodeProject, 1999-2014
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