关于vb.net的问题 [英] A question on vb.net

查看:69
本文介绍了关于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





我的问题是,当我使用按钮添加单选按钮并停止调试并再次打开时,我找不到我之前添加的任何单选按钮。

如果我添加一些带有公司名称的单选按钮作为其文本,我可以在它运行时看到它。

当我重新打开时,我添加的那些新的单选按钮控件将消失。 />
有什么建议吗?

表格应该用新公司来更新。

(我用文本框存储位置(x,y)。我使文本框不可见(textbox.visible = false)



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)

推荐答案

您正在程序执行期间动态添加单选按钮,因此它仅在程序运行时存在。因此,Windows窗体设计器不知道。而不是在程序执行时动态添加控件,而是使用Visual Studio中的Windows窗体设计器来设计表单。 Windows窗体设计器将生成所有代码以正确实例化单选按钮。



这是Windows窗体设计器为单选按钮控件生成的示例:
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"


您在运行时添加控件,它们不会成为永久性的 - 它们暂时发生在程序的当前运行实例上,并且不会以任何方式影响EXE文件。因此,当它下次运行时,它会像添加任何控件之前一样显示。编译应用程序时,只有设计器中添加的控件才会自动包含在表单中。



如果要在运行时添加控件并使其保持持久性,则需要存储它们的详细信息(在文件或配置设置中)以便保存它们,并在运行程序时重新读取该数据并重新创建所需的控件。



顺便说一下,如果你希望你的用户从公司列表中选择一个项目,那么最好使用ComboBox(将DropDownStyle属性设置为DropDownList) - 它占用更少的屏幕空间,并且更容易添加新项目。
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.


我认为你可以在应用程序设置中保存这些名称和其他设置并设置一个标志,同时对此标志进行表单加载检查,如果是真的,则添加一个基于的btn那些设置



ħ ttp://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/ [ ^ ]
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/[^]


这篇关于关于vb.net的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆