组件类

个人第一次接触,对于新手可以借鉴,也多谢一位大佬的告知

多话不说直接贴代码拉,选中的部分就是添加的组件类啦,此组件类中你可以自己添加,此类中CS中添加代码

using System;

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


namespace WindowsFormsApplication1
{
public partial class TESTPIC : Control
{
public TESTPIC()
{
InitializeComponent();
}
//第一个属性  检查状态
public enum StateInspection
{
/// <summary>
/// 尚未检查
/// </summary>
uncheck,
/// <summary>
/// 检查中
/// </summary>
checking,
/// <summary>
/// 查到错误
/// </summary>
check_error,
/// <summary>
/// 检查通过
/// </summary>
check_pass,
            /// <summary>
            /// 谢谢大佬您的教诲
            /// </summary>
            check_pass1
}
        //第一个属性  检查状态
private StateInspection fECheckState;


[EditorBrowsable(EditorBrowsableState.Always)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Browsable(true)]
[Description("检查状态"), Category("数据"), DefaultValue(StateInspection.uncheck)]
public StateInspection FECheckState
{
get
{
return fECheckState;
}


set
{
fECheckState = value;
}
}


//第二个属性  错误数量 
private int fEerrorCount;
[EditorBrowsable(EditorBrowsableState.Always)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Browsable(true)]
[Description("错误数量"), Category("数据"), DefaultValue(0)]
public int FEerrorCount
{
get
{
return fEerrorCount;
}
set
{
if (FECheckState == StateInspection.check_error)
{
fEerrorCount = value;
}
}
}
//将其大小固定为140*120
protected override void OnResize(EventArgs e)
{
this.Height = 140;
this.Width = 120;
base.OnResize(e);
}
//重载OnPaint事件
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = this.CreateGraphics();
Font font1 = new Font("微软雅黑", 12);
Font font2 = new Font("微软雅黑", 11);
Point pi = new Point(25, 90);
Point pi2 = new Point(70, 60);
Image im = null;
if (FECheckState == StateInspection.uncheck)
{

im = Resource1.state1;
g.DrawImage(im, 30, 20, 60, 60);
g.DrawString("尚未检查", font1, Brushes.Gray, pi);
}
else if (FECheckState == StateInspection.checking)
{
im = Resource1.state2;
g.DrawImage(im, 30, 20, 60, 60);
g.DrawString("正在检查", font1, Brushes.Blue, pi);
}
else if (FECheckState == StateInspection.check_error)
{
im = Resource1.state4;
g.DrawImage(im, 30, 20, 60, 60);
g.DrawString("存在问题", font1, Brushes.Red, pi);
g.DrawString(FEerrorCount.ToString(), font2, Brushes.Red, pi2);
}
else if (FECheckState == StateInspection.check_pass)
{
im = Resource1.state3;
g.DrawImage(im, 30, 20, 60, 60);
g.DrawString("检查通过", font1, Brushes.Green, pi);
}
            else
            {
                im = Resource1.大佬谢谢;
                g.DrawImage(im, 30, 20, 60, 60);
                g.DrawString("谢谢大佬", font1, Brushes.Green, pi);
            }
base.OnPaint(e);
}
}

}

生成成功啦你可直接在你的工具箱中找到你自己定义的那个类,这个类可以直接生成一个控件,如果你添加的是用户控件生成一个dll变成一个dll文件,别人在工具箱添加你的dll也可以使用此控件多话不说在贴照片

这个控件的名字便是你刚看到的那个类名,再看一下你的控件属性在看图

选中部分和选中部分的下面便是你自己定义的属性

这便是自己定义的一个控件的简单属性的全过程,感谢那位大佬,自己也算是摸明白啦,也给自己写个总结,用户控件的这一部分和组件类相同的做法,只是用户控件会生成dll文件,用户控件主要用于防止外人查看你的源码,这个我不喜欢用,因为不说,源码地址



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值