Home > Backend Development > C#.Net Tutorial > C# .net custom control properties

C# .net custom control properties

徐壮壮
Release: 2020-04-29 10:42:31
Original
266 people have browsed it

The first step is to add a custom control: The second step is to right-click on the form to view the code or press F7: The third step is to add attributes:

You can also use the following code to achieve

 [Description("修改此值,可修改分割线的颜色"), Category("自定义属性")]
        // 控件的自定义属性值 
        public Color DrawLineColor                   
        {  
            get  
            {  
                return drawLineColor;  
            }  
            set  
            {  
                drawLineColor = value;    
                // 此处修改,为自定义属性变动时,执行的操作  
                // 此处当颜色值属性变动时,使用新的颜色,使自定义控件重绘 
                this.Invalidate();   
            }  
        }
        // 自定义事件的参数类型
        public delegate void select_Handle(object sender, EventArgs e, string orther);    
        [Description("当点击控件时发生,调用选中当前控件逻辑"), CateGory("自定义事件")]
        // 自定义事件名, 
        public event select_Handle ThisLine_Selected;                                       
  
        // 在当前控件的某个默认事件中调用自定义事件,此处使用默认的Click事件时,调用自定义的选中事件This_Selected  
        private void SplITLineHorizontal_Click(object sender, EventArgs e)  
        {
            // 定义选中控件时,显示为红色
            //DrawColor = Color.Red;     
            //调用自定义事件
            if (ThisLine_Selected != null) ThisLine_Selected(this, new EventArgs(), "其它参数");  
        }  
    }
Copy after login

The above is the detailed content of C# .net custom control properties. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template