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#)


基础教程推荐
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 将 XML 转换为通用列表 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- rabbitmq 的 REST API 2022-01-01