How do you create a C# property that can subscribe to another WinForm control at design time?

后端 未结 1 1375
半阙折子戏
半阙折子戏 2020-12-11 06:32

I want to create a property in a control that will act as a viewer that will be able to connect to another non-visual control to show its current status. In this example let

相关标签:
1条回答
  • 2020-12-11 07:01

    To have non-UI elements that can be used at design-time in the designer, you can inherit from Component.

    using System.ComponentModel;
    
    public interface IHeater
    {
        int Temperature { get; set; }
    }
    
    public class Heater : Component, IHeater
    {
        public int Temperature 
        {
            get;
            set;
        }
    }
    
    public class HeaterMonitor:Component
    {
        public IHeater Source { get; set; }
    }
    

    Then you can use them in design-mode (in component tray):

    And select the source this way:

    0 讨论(0)
提交回复
热议问题