将变量的值从一种形式移到另一种形式. [英] moving the value of a variable from a form to another..

查看:92
本文介绍了将变量的值从一种形式移到另一种形式.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,使用Windows应用程序(桌面应用程序)将变量的值从一种形式转移到另一种形式时遇到困难.
谁能帮忙吗?
正在使用vb.net
感谢

解决方案

我想您想从另一种形式中检索某种形式的变量的值,如果是这种情况,请尝试使用此方法

公共课程表格1


私有子Form1_Load(发送为System.Object,发送为System.EventArgs)处理MyBase.Load
不确定为整数
现在变暗为整数
Dim yea As Integer

Form2.takeval(确定,现在,是的)
结束子
结束类

现在,您可以通过.......
从form2调用它.
公用类Form2

公共函数takeval(以ByVal num1为整数,ByVal num2为整数,num3为整数)作为Integer
num1 = 5
num2 = 6
num3 = 7
返回num1和num2和num3
最终功能

私有子Form2_Load(发送为System.Object,发送为System.EventArgs)处理MyBase.Load
结束子
结束类

从Form2中的该函数中,您可以轻松地检索值

这是有关表单协作的常见问题.最健壮的解决方案是在Form类中实现适当的接口,并传递接口引用而不是对Form的整个实例"的引用.请查看我过去的解决方案以获取更多详细信息:如何以两种形式在列表框之间复制所有项目 [ 解决方案

I suppose you want to retrieve the value of variables in a form from another form, if that is the case then try this

Public Class Form1


Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim sure As Integer
Dim now As Integer
Dim yea As Integer

Form2.takeval(sure, now, yea)
End Sub
End Class

Now you can call it from form2 by.....

ublic Class Form2

Public Function takeval(ByVal num1 As Integer, ByVal num2 As Integer, num3 As Integer) As Integer
num1 = 5
num2 = 6
num3 = 7
Return num1 And num2 And num3
End Function

Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
End Class

From that function in Form2 you can easily retrieve your values


This is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class and passing the interface reference instead of reference to a "whole instance" of a Form. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

—SA


这篇关于将变量的值从一种形式移到另一种形式.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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