将值传递给Forms TextBox [英] Passing value to a Forms TextBox

查看:68
本文介绍了将值传递给Forms TextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将类中公共Sub的值传递给表单文本框。


我得到''表单未声明''使用Forms!frmName!txtBoxName 。


问候

How do I pass a value from a Public Sub in a class to a forms textbox.

I get ''Name Forms is not declared'' with Forms!frmName!txtBoxName.

Regards

推荐答案

这是一个ASP.NET文本框控件吗?如果是这样,只需使用

控件的名称,如:


txtUser.Text = someValue

" Terry" ; < ne ******* @ whiteHYPHENlightDOTme.ukwrote in message

news:%2 **************** @ TK2MSFTNGP04.phx.gbl ...
Is this an ASP.NET Textbox control? If so, just use the name of the
control, as in:

txtUser.Text = someValue
"Terry" <ne*******@whiteHYPHENlightDOTme.ukwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...

如何将类中公共Sub的值传递给表单文本框。


I得到''表格没有声明''与表格!frmName!txtBoxName。


问候

How do I pass a value from a Public Sub in a class to a forms textbox.

I get ''Name Forms is not declared'' with Forms!frmName!txtBoxName.

Regards



在你班级的Public Sub中,你需要一个对相关表格的引用。

有很多方法可以达到这个目的,但有一种方法是:


Dim _f As Form = My.Application.OpenForms(" frmName")

类型为Form的对象当然不知道txtBoxName,

因此您需要将引用转换为frmName类型的变量:


Dim _f作为frmName = CType(My.Application.OpenForms(" frmName" ),frmName)


现在你有了参考,你可以直接操作TextBox:

_f.txtBoxName.text ="快速的棕色狐狸......


这种方法有很多细微差别但是如果该应用程序是一个基本的

Windows窗体应用程序,那么这种方法在大多数情况下应该可以正常工作。

Terry < ne ******* @ whiteHYPHENlightDOTme.ukwrote in message

news:%2 **************** @ TK2MSFTNGP04.phx.gbl ...
In the Public Sub in your class, you need a reference to the form concerned.
There are many ways of achieving this but one way is:

Dim _f As Form = My.Application.OpenForms("frmName")

An object of type Form does not, of course know anything about txtBoxName,
so you need to cast the reference to a variable of type frmName:

Dim _f As frmName = CType(My.Application.OpenForms("frmName"), frmName)

Now that you have the reference, you can manipulate the TextBox directly:

_f.txtBoxName.text = "The quick brown fox ..."

There are a number of nuances to this approach but if the app is a basic
Windows Forms app then this approach should work just fine in most cases.
"Terry" <ne*******@whiteHYPHENlightDOTme.ukwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...

如何将类中公共Sub的值传递给表单文本框。


I得到''表格没有声明''与表格!frmName!txtBoxName。


问候

How do I pass a value from a Public Sub in a class to a forms textbox.

I get ''Name Forms is not declared'' with Forms!frmName!txtBoxName.

Regards



这是另一种方法:


- 启动Windows应用程序

- 向form1添加一个按钮

- 添加第二个表格

- 向表格2添加一个文本框


在代码视图中打开form2&添加此代码:


Public Shadows Sub ShowDialog(ByVal s As String)

TextBox1.Text = s

MyBase.ShowDialog ()

End Sub


Public Shadows Sub Show(ByVal s As String)

TextBox1.Text = s
MyBase.Show()

结束子


双击form1&中的按钮添加其中一个片段:


''显示模态:


Dim frm As New Form2

frm。 ShowDialog(Hello,World!)

frm.Dispose()


''显示形式:


Dim frm As New Form2

frm.Show(" Hello,World!")


我希望这有帮助,


新手编码器
Here''s another way of doing it:

- Start Windows App
- Add a button to form1
- Add a second form
- Add a textbox to form2

Open form2 in code view & add this code:

Public Shadows Sub ShowDialog(ByVal s As String)
TextBox1.Text = s
MyBase.ShowDialog()
End Sub

Public Shadows Sub Show(ByVal s As String)
TextBox1.Text = s
MyBase.Show()
End Sub

Double-click the button in form1 & add one of these snippets:

'' Show modal:

Dim frm As New Form2
frm.ShowDialog("Hello, World!")
frm.Dispose()

'' Show form:

Dim frm As New Form2
frm.Show("Hello, World!")

I hope this helps,

Newbie Coder


这篇关于将值传递给Forms TextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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