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#)
基础教程推荐
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
