C#WinsForm帮助..显示文本C# [英] C# WinsForm Help.. Displaying text C#

查看:75
本文介绍了C#WinsForm帮助..显示文本C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..

所以我的项目中有2个表格,名为form1和form2。



form1包含一个按钮。

form2包含一个文本框。



我的问题是如何在表单2中从表单1显示文本到文本框?



例如,当单击form1中的按钮时,我会在form2的文本框中显示诸如hi的文本。



希望这是有道理的,谢谢你的时间。





Abz

Hi guys..
so I have 2 forms in my project appropriately named form1 and form2.

form1 contains a button.
form2 contains a textbox.

My question is how do i get to display text to the textbox in form 2 from form 1?

for example when the button in form1 is clicked , i would it to display a text such as "hi" in the textbox that is in form2.

hope this makes sense and thank you for your time.


Abz

推荐答案

在你的Form1上添加一个事件,你的按钮调用Form2



On your Form1 add an event on your button which calls the Form2

private void button1_Click(object sender, EventArgs e)
{
    Form2 form2 = new Form2("Hi");
    form2.ShowDialog();

}





在你的Form2上添加一个构造函数,它将接受一个字符串,它将在你的文本框中输出





On your Form2 add a constructor that will accept a string, that will output in your textbox

public Form2(string text)
{
    InitializeComponent();
    textBox1.Text = text;
}


这篇关于C#WinsForm帮助..显示文本C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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