从用户控件返回不同的属性值以在另一个用户控件中使用
我有两个用户控制,如UC1& UC2和他们有如下属性:
(浮动)InletPressure
(浮动)OutletPressure
(浮动)PressutreDrop
(浮动)FlowRate
我有其他用户控制作为TX1,它有一个文本框和一个名为Owner的属性。
我需要能够将所有者引用到UC1或UC2中的一个并且文本框返回UC1或UC2中上述属性之一的值,如下所示:
TextBox1.Text = Owner.InletPressure.ToString();
或TextBox1.Text = Owner.OutletPressure.ToString();
等等。
我的尝试:
我对此一无所知。请帮我找一个参考。
I have Two user control as UC1 & UC2 and they have properties as follow :
(float) InletPressure
(float) OutletPressure
(float) PressutreDrop
(float) FlowRate
I have other user control as TX1 and it has a textbox and a Property named Owner.
I need to be able to reference 'Owner' to one of UC1 or UC2 and textbox return the value of one of the above-mentioned property in UC1 or UC2 as follow :
TextBox1.Text=Owner.InletPressure.ToString();
or TextBox1.Text=Owner.OutletPressure.ToString();
and so on.
What I have tried:
I have not any Idea about. Please help me to find a reference for.
我要定义一个界面 [ ^ ]包含共享属性和方法。将其应用于UC1
&UC2
并添加List< [Interface used]>的属性到TX1
传递一个对象引用。现在在TX1
。类似的东西......
I would define an Interface[^] with the shared properties and methods. Apply it toUC1
&UC2
and add a property of the List<[Interface used]> toTX1
pass an object reference to. Now inTX1
. Something Like...
public interface IFeedBack
{
string InletPressure { get; set; }
string OutletPressure { get; set; }
}
然后在 UC1
& UC2
Then in the UC1
& UC2
public UC1 : Control, IFeedback
{
...
public string InletPressure { get; set; }
public OutletPressure { get; set; }
...
}
public UC2 : Control, IFeedback
{
...
public string InletPressure { get; set; }
public OutletPressure { get; set; }
...
}
和 TX1
And the TX1
public TX1 : Control
{
...
public List<IFeedBack> FeedbackControls { get; } = new List<IFeedBack>();
...
private void UpdateFeedback()
{
...
txtInletPressure.Text = FeedbackControls[0].InletPressure;
...
}
}
使用...
To use...
class Form1
{
...
private void HookupControls()
{
...
// TX1, UC1, UC2, controls
feedBackControl.FeedbackControls.AddRange(PressureControl1, PressureControl2);
...
}
...
}