Writing to a textbox on a separate form (C#)(在单独的表单上写入文本框(C#))
问题描述
假设我有两个表格:Form1 和 Form2.Form2 有一个名为 text1 的文本控件
Suppose I have two forms: Form1 and Form2. Form2 has a text control named text1
在 VB6 中,我可以写入 Form 2 的文本框
In VB6 I could write to Form 2's textbox
使用 Form1 控制:Form2.Text1.text = "Some text here"
control from Form1 by using: Form2.Text1.text = "Some text here"
如何在 C# 中完成这项工作?我什么都试过了!
How can I make this work in C#? I have tried everything!
我尝试过的:
Form2 Frm2 = new Form2();
Frm2.show();
Frm2.Activate(); // Trying everything to make sure it sees the form (it does).
Frm2.Text1 (Doesn't find the control)...
回答:
我最终在 Form2 中创建了一个公共例程,然后只从 form1 调用这个例程.在 Form2 的这个公共例程中,我会调用文本框!
I ended up making a public routine in Form2, and then just calling this routine from form1. In this public routine of Form2 I would then call the textbox!
推荐答案
我的目标是将文本添加到另一个表单的文本框中.我有Form1和Form2.Form2 有一个名为 Text1 的文本框控件.为了完成这项工作,我创建了一个子例程:
My goal was add text to a Text Box on another form. I had Form1 and Form2. Form2 has a text box control named Text1. In order to make this work, I created a Sub Routine:
public Void WriteToText(string sData)
{
// Here is where I wrote to my textbox
Text1.text = sData;
}
<小时>
表格1代码:
Form 1 code:
Form2 Frm2 = new Form2();
Frm2.WriteToText("My Data");
这篇关于在单独的表单上写入文本框(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在单独的表单上写入文本框(C#)


- 使用 rss + c# 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01