如何使用c#在此程序中传递参数 [英] How to Pass the Parameter in this Program using c#

查看:58
本文介绍了如何使用c#在此程序中传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述






private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F3)
            {

                Form2 f2 = new Form2();
                f2.ShowDialog();
                textBox1.Text = f2._username;


            }
        }

推荐答案

参数"是特定编程实体的属性,例如方法,SQL查询等.这是代码,但并非如此在很大程度上,只需要一个有效的用户名即可将其分配给文本框的text属性.您可以简单地将f2.Username设置为internal属性,并在其getter中读取private _username的值.

从更普遍的角度来看,这是关于表单协作的流行问题.最可靠的解决方案是在表单类中实现适当的接口.请查看我过去的解决方案以获取更多详细信息:如何以两种形式在列表框之间复制所有项目 [
A "parameter" is an attribute of specific programming entities, such as method, SQL query, etc. This is code, making not so much sense, just needs a valid username to assign to the text box text property. You can simply make f2.Username an internal property, reading the value of private _username in its getter.

In a more general view, this is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

—SA


这篇关于如何使用c#在此程序中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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