public partial class UCCheck : UserControl { [Browsable(true), Category("修改属性"), Description("控件标识,用来判断同类型的不同对象")] public string Identification { get; set; } private bool isStatus = false; /// <summary> /// 关门状态,true选中,false关 /// </summary> [Browsable(true), Category("修改属性"), Description("是否选择,true选中")] public bool IsStatus { get { return isStatus; } set { isStatus = value; pbxMove.Image = isStatus?Properties.Resources.check_box: Properties.Resources.check_def; //Image.FromFile(isStatus ? @"imgcheck_box.png" : @"imgcheck_def.png"); } } /// <summary> /// 关门状态,true开,false关 /// </summary> [Browsable(true), Category("修改属性"), Description("显示文字")] public string ShowTxt { get { return label2.Text; } set { label2.Text = value; } } public delegate void CheckHandle(object sender, EventArgs e); [Browsable(true), Category("子控件的事件"), Description("勾选事件")] public event CheckHandle CheckClicked; public UCCheck() { InitializeComponent(); } private void pbxMove_Click(object sender, EventArgs e) { IsStatus = !IsStatus; CheckClicked?.Invoke(this, e); } }
namespace LUserControl { partial class UCCheck { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region 组件设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要修改 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.label2 = new System.Windows.Forms.Label(); this.pbxMove = new System.Windows.Forms.PictureBox(); ((System.ComponentModel.ISupportInitialize)(this.pbxMove)).BeginInit(); this.SuspendLayout(); // // label2 // this.label2.AutoSize = true; this.label2.Font = new System.Drawing.Font("微软雅黑", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.label2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(117)))), ((int)(((byte)(117)))), ((int)(((byte)(117))))); this.label2.Location = new System.Drawing.Point(33, 2); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(62, 31); this.label2.TabIndex = 42; this.label2.Text = "本柜"; // // pbxMove // this.pbxMove.BackColor = System.Drawing.Color.Transparent; this.pbxMove.BackgroundImage = global::LUserControl.Properties.Resources.check_def; this.pbxMove.Dock = System.Windows.Forms.DockStyle.Left; this.pbxMove.Location = new System.Drawing.Point(0, 0); this.pbxMove.Name = "pbxMove"; this.pbxMove.Size = new System.Drawing.Size(40, 40); this.pbxMove.TabIndex = 43; this.pbxMove.TabStop = false; this.pbxMove.Click += new System.EventHandler(this.pbxMove_Click); // // UCCheck // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Controls.Add(this.pbxMove); this.Controls.Add(this.label2); this.Name = "UCCheck"; this.Size = new System.Drawing.Size(100, 40); ((System.ComponentModel.ISupportInitialize)(this.pbxMove)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Label label2; private System.Windows.Forms.PictureBox pbxMove; } }