在 VS 2010 中的窗体之间传递变量 [英] Passing variables between windows forms in VS 2010

查看:30
本文介绍了在 VS 2010 中的窗体之间传递变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种形式.表单 1 允许用户从下拉组合框中选择员工.然后将该员工传递到表格 2,用户在其中输入有关该员工的其他信息.然后,该数据将被传递到 SQL 表中.

I have two forms. Form 1 allows the user to pick an employee from a dropdown combo box. That employee is then passed onto Form 2 where the user enters additional information regarding that employee. That data will then be passed into a SQL table.

在表格 1 上我有:

Dim ChangeJobInfo As New Form2(Employee)
ChangeJobInfo.Show()

在表格 2 上我有:

Public Sub New(ByVal Employee As String)
MsgBox(Employee)
End Sub

变量通过就好了.问题是新表格上没有显示任何内容.当我设置 Form2 时,我添加了一个组合框、日期选择器、两个文本框、提交按钮等,但是当表单加载时它是完全空白的.没有错误,MsgBox 返回正确的结果,但没有显示我的 gui 元素.如果我将表单 1 上的代码更改为 Form2.show(),我会看到设计器中布局的表单.

The variable passes just fine. The issue is that nothing shows up on the new form. When I setup Form2, I added a combobox, date picker, two text boxes, submit button, etc., but when the form loads it is completely blank. No errors, the MsgBox returns the right result, but none of my gui elements show up. If I change the code on form 1 to Form2.show() I see the form as laid out in the designer.

关于如何让这些项目显示的任何想法?

Any ideas on how to get those items to show up?

推荐答案

将您在 Form2.vb 中的代码更改为 New 子项:

Change your code in Form2.vb for the New sub to this:

Public Sub New(ByVal Employee As String)

    ' This call is required by the designer.

    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.

    MsgBox(Employee)

End Sub

如果您不调用 InitializeComponent(),您的完整 GUI 将不会呈现.

If you don't call InitializeComponent(), your complete GUI is not going to render.

这篇关于在 VS 2010 中的窗体之间传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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