如何制作一个用户控件?
VS竟然不提供直线和长方形这种常用的控件,吐槽一个!
如何自作一个呢,很简单,其实控件就像一个windows,我们把windows看成一个长方形,填充我们需要的颜色,不就是一个长方形吗,把长方形拉长拉细,不就是一条直线吗?
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public partial class Line : UserControl { public Line() { InitializeComponent(); } private Color onColor = Color.Green; private Color offColor = Color.Gray; private bool tags = false; public Color OnColor { get => onColor; set => onColor = value; } public Color OffColor { get => offColor; set => offColor = value; } public bool Tags { get { return tags; } set { tags = value; if (tags) this.BackColor = onColor; else this.BackColor = offColor; } } }