日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C#中对虚拟属性和抽象属性的重写,重写label实例

發布時間:2023/12/18 C# 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C#中对虚拟属性和抽象属性的重写,重写label实例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
從下面這個例子可以看出來區別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

總結

以上是生活随笔為你收集整理的C#中对虚拟属性和抽象属性的重写,重写label实例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。