博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#中对虚拟属性和抽象属性的重写,重写label实例
阅读量:4302 次
发布时间:2019-05-27

本文共 3170 字,大约阅读时间需要 10 分钟。

从下面这个例子可以看出来区别       public abstract class A        {            //抽象属性不能有实现代码            public abstract string AbstractProperty { get; set; }            string s;            //虚拟属性可以有实现代码            public virtual string VritualProperty            {                get { return this.s; }                set { this.s = value.ToUpper(); }            }        }        public class B : A        {            string message;            //在继承类(子类)中必须提供抽象属性的实现            public override string AbstractProperty            {                get { return message; }                set { this.message = value; }            }            //重写属性可以调用基类中的实现            public override string VritualProperty            {                get                {                    return base.VritualProperty;                }                set                {                    base.VritualProperty = value;                }            }        }

 

//********************重写label

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ETES.AutoControl_ES.Controls

{
   public class MyLabel:Label
    {

        public override string Text {

            
            get
            {
                return base.Text;
            }

            set

            {
                string str="";
                for(int i=0;i<value.Length;i++)
                {
                    str += value[i];
                    if (i % 10==0) str += "\r\n";
                }
                 base.Text = str;
            }
        }

    }
}
//***************************

  #region //控制按钮标题

        public MyLabel lb = new MyLabel();
        public void InitialTitleManager()
        {
            //lb.Parent = this;
            lb.Visible = true;
            lb.AutoSize = true;
            lb.Font=new System.Drawing.Font("宋体", 9, System.Drawing.FontStyle.Bold);
            foreach (Control v in this.groupBox_CAutoScanSet.Controls)
            {
                if (v.Name.Contains("label"))
                {

                    v.MouseHover += TitleMouseHover;

                    v.MouseLeave += TitleMouseLeave;

                }

            }

            //  MessageBox.Show(" comboBox_AxisType.MouseHover+= TitleMouseHover;");
          
            comboBox_AxisType.MouseHover+= TitleMouseHover;
            comboBox_AxisType.MouseLeave += TitleMouseLeave;
        }
        public void TitleMouseHover(object sender, EventArgs e)
        {
            Control control = sender as Control;

            lb.Location = new System.Drawing.Point(control.Location.X + control.Width, control.Location.Y);

            string titile = "";

            //MessageBox.Show(control.Name);//2020.4.1注释
            if (control.Name.Contains("label"))
            {
                //MessageBox.Show(control.Name);//2020.4.1注释
                string tempStr = "";
                if(control.Text.Contains("AX2"))
                {
                    tempStr = control.Text.Substring(0, 3);
                }
                else
                {
                    tempStr = control.Text.Substring(0, 2);
                }
                if (StepModule.AxisDescription.ContainsKey(tempStr))
                {
                    titile = StepModule.AxisDescription[tempStr];
                }

            }

            else if(control.Name.Contains("comboBox"))
            {
                //MessageBox.Show(control.Name);//2020.4.1注释
                titile = StepModule.AxisDescription[control.Text];

            }
            lb.Parent = control.Parent;
            lb.Visible = true;
            lb.BringToFront();
            lb.Location = new System.Drawing.Point(control.Location.X + control.Width, control.Location.Y);
            lb.Text = titile;
        }
           
        
    public void TitleMouseLeave(object sender, EventArgs e)
    {

        Control control = sender as Control;//此处control只是局部变量,函数结束后,control释放,control引用的对象不会释放

        lb.Location = new System.Drawing.Point(control.Location.X + control.Width, control.Location.Y);

        lb.Visible = false;
        lb.AutoSize = true;
        lb.Text = "";

    }

    #endregion

转载地址:http://ezlws.baihongyu.com/

你可能感兴趣的文章
java设计基本原则----单一职责原则
查看>>
HashMap的实现
查看>>
互斥锁 synchronized分析
查看>>
java等待-通知机制 synchronized和waity()的使用实践
查看>>
win10 Docke安装mysql8.0
查看>>
docker 启动已经停止的容器
查看>>
order by 排序原理及性能优化
查看>>
Lock重入锁
查看>>
docker安装 rabbitMq
查看>>
git 常用命令 入门
查看>>
linux安装docker
查看>>
关闭selinx nginx无法使用代理
查看>>
shell 脚本部署项目
查看>>
spring cloud zuul网关上传大文件
查看>>
springboot+mybatis日志显示SQL
查看>>
工作流中文乱码问题解决
查看>>
maven打包本地依赖包
查看>>
spring boot jpa 实现拦截器
查看>>
jenkins + maven+ gitlab 自动化部署
查看>>
Pull Request流程
查看>>