从用户控件中的文本框声明文本作为整个应用程序的变量 [英] declarion text from a textbox in a usercontrol as a variable for the whole app

查看:100
本文介绍了从用户控件中的文本框声明文本作为整个应用程序的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的总体目标是为远程计算机获取不同的计算机信息.

我有几个用户控件都拉不同的信息.一个用户控件获取信息(机器名),而我需要其他用户控件来查看它.

我的设置方法是,我有一个文本框和一个按钮,然后单击按钮,我希望应用程序提取机器信息.

我已经读过有关全局变量的信息,但是我是编程的新手.
我试过了:

My overall goal is pulling different machine information for remote machines.

I have several user controls all pull different information. One user controls gets the information (machine name) and I need the others user controls to see it.

The way I have it set up is I have a text box and a button and on button click I would like the application to pull the machine information.

I have read about global variables, but I am new to programming.
I have tried:

Dim comphost as string
comphost = machinename.text


我认为我走了正确的道路,但我需要帮助.


I think I am on the right path, but I need help.

推荐答案

这完全取决于您要对变量执行的操作. UserControls将如何处理此信息?

回答您的评论.您应该在主表单中创建一个公共属性,如下所示:-

It all depends on what you want to do with the variable. What will the UserControls do with this information ?

In answer to your comment. You should create a public property in your main form, something like this:-

Public Property CompHost() As String
Get
    return compHost
End Get
Set(ByVal Value As String)
    compHost = Value
End Set
End Property



然后在用户控件中创建一个构造函数,该构造函数将字符串作为参数,并在打开它时传递此属性,如下所示:-

公共



then in your user control you create a constructor that takes a string as a parameter and pass in this property when you open it, something like this:-

Public

Class myUserControl

    Public Sub myUserControl(compHost As String)
        'do something with compHost
    End Sub

End Class



也许这会给你一个更好的主意.祝你好运!



Maybe this will give you a better idea. Good luck!


这篇关于从用户控件中的文本框声明文本作为整个应用程序的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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