如何在c#中将文本框值从一个用户控件获取到另一个用户控件

编程入门 行业动态 更新时间:2024-10-27 22:34:43
本文介绍了如何在c#中将文本框值从一个用户控件获取到另一个用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的Windows窗体应用程序中有两个用户控件。在第一个用户控件中,我有一个文本框和一个保存按钮。 我在另一个用户控件中有另一个文本框。 当我点击保存 按钮然后用户控件中的文本框中的值必须显示在另一个用户控件文本框中。 我试过这样的

Hi, I hav two user control''s in my windows form application. In the first user control i have one "textbox" and one "save" button. I have another "Textbox" in another user control. when i click "save" button then what ever the value in "textbox" in user control one has to display in another user control "Textbox". I have tried like this

namespace project { public partial class ucSample : UserControl { private double transferVolume; public double TransferVolume { get { return transferVolume; } set { transferVolume = value; } } public ucSample() { InitializeComponent(); } private void btnSave_Click(object sender, EventArgs e) { TransferVolume = double.Parse(txtSamplevolume.Text); } } }

在另一个用户控件中我尝试如下所示。

In another user control i am trying like as shown below.

namespace project { public partial class ucSettings : UserControl { ucSample samplevolume = new ucSample(); public ucSettings() { InitializeComponent(); } private void txtvolumeMin_TextChanged(object sender, EventArgs e) { txtvolumeMin.Text = samplevolume.TransferVolume.ToString(); } } }

请允许任何人帮我解决我在这里犯的错误。我正在使用财产来转移价值。我无法弄清楚这是什么错误。或者任何其他最佳方式。 提前致谢。

Please can any one help me what mistake i am doing here. I am using property to transfer value. I am not able figure it out what is the mistake. or any other best way to do this . Thanks in advance.

推荐答案

这很简单,但你的方法是错误的。 看看这个:在两种形式之间传递信息,第3部分:儿童与儿童 [ ^ ]并且在任何地方它都说形式为用户控制 - 原理和技术正是如此同样。 This is pretty simple, but you are going about it the wrong way. Have a look at this: Transfering information between two forms, Part 3: Child to Child[^] and everywhere it says "form" read "user control" - the principle and techniques are exactly the same.

更多推荐

如何在c#中将文本框值从一个用户控件获取到另一个用户控件

本文发布于:2023-11-11 11:47:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578353.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   用户   中将   文本框   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!