文本框值没有在winforms中获得另一个表单按钮点击事件 [英] textbox value not getting another form button click event in winforms

查看:25
本文介绍了文本框值没有在winforms中获得另一个表单按钮点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理 Windows 窗体应用程序,我有两种窗体.1 是visitorinfo 2 是vistorexitsign.

I am working on windows form application and I have two forms. 1 is visitorinfo 2 is vistorexitsign.

在访问者信息中,我有保存按钮,在点击保存按钮时,我想从 vistirexitsign 表单中获取文本框值.

In the visitorinfo I have save button, while cliking save button I want to get textboxvalue from vistirexitsign form.

两个表单同时运行,我在访问者信息表单的保存按钮中给出了这样的代码:

Both forms are running at the same time, I have given code like this in save button of visitor info form:

Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        Dim obj As New VisitorExitsign
        Dim vs As String = obj.txtvisitoridExit.Text
            Dim Visitorid As String = My.Forms.VisitorExitsign.txtvisitoridExit.Text

但我总是得到这里 txtvisitoridexit.text value null.未获取文本值.

But I am always getting here txtvisitoridexit.text value null. Not getting the text value.

我的代码有什么问题?

推荐答案

您正在每个点击事件中创建新实例.

You are creating new instance in every click event.

Dim obj As New VisitorExitsign

所以这些值是在新对象中设置的,而不是在现有对象中.

So the values are set in the new objects but not in existing object.

所以实际上你必须引用 VisitorExitsign 的现有对象.

So actually you have to refer to existing object of VisitorExitsign.

例如:

您正在以某种方法创建表单 VisitorExitsign.

You are creating form VisitorExitsign in some method.

因此,无论何时创建,都将其引用存储在某个全局变量中.

VisitorExitsign obj = new VisitorExitsign

在您创建表单的地方

然后在点击事件中使用 obj 并指定文本.

then in click event use obj and assign text.

这篇关于文本框值没有在winforms中获得另一个表单按钮点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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