从用户控件返回不同的属性值以在另一个用户控件中使用 [英] Returning different property value from a user control to use in another user control

查看:61
本文介绍了从用户控件返回不同的属性值以在另一个用户控件中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个用户控制,如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 to UC1 & UC2 and add a property of the List<[Interface used]> to TX1 pass an object reference to. Now in TX1. 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);
        ...
    }
    ...
}


这篇关于从用户控件返回不同的属性值以在另一个用户控件中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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