惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
Recent Commits to openclaw:main
Recent Commits to openclaw:main
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
罗磊的独立博客
V
Visual Studio Blog
爱范儿
爱范儿
H
Help Net Security
J
Java Code Geeks
I
InfoQ
Recent Announcements
Recent Announcements
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recorded Future
Recorded Future
Jina AI
Jina AI
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
GbyAI
GbyAI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Y
Y Combinator Blog
Google DeepMind News
Google DeepMind News
Scott Helme
Scott Helme
S
SegmentFault 最新的问题
S
Securelist
L
LINUX DO - 热门话题
Cyberwarzone
Cyberwarzone
C
Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
T
The Blog of Author Tim Ferriss
博客园_首页
B
Blog
F
Fortinet All Blogs
AWS News Blog
AWS News Blog
V
Vulnerabilities – Threatpost
S
Secure Thoughts
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Schneier on Security
Project Zero
Project Zero
Martin Fowler
Martin Fowler
C
Cybersecurity and Infrastructure Security Agency CISA
N
Netflix TechBlog - Medium
N
News and Events Feed by Topic

博客园 - 桂圆

经典语句(人生经典语句 爱情经典语句) 我对GOOGLE MAP API 的一些简单调用 - 桂圆 关于FileUpload上传大文件的问题解决办法 搁浅了我也 无法启动IIS服务解决办法 我对FreeTextBox简单使用 C#格式化数据结果表 - 桂圆 - 博客园 使用JavaScript 为GridView 行添加淡入淡出效果 C#文件操作 - 桂圆 - 博客园 获取GridView中指定的控件 - 桂圆 - 博客园 ScriptManager调用 无参数WebService 通用不间断滚动JS封装类 prototype 轻量级WEB开发的首选ajax框架 使用UrlRewritingNet.Dll实现URL 重写 【软件设计精要与模式】到手 JS应用(资料很全) SQLServer Transact SQL全集(转) JavaScript基础知识 使用ICSharpCode.TextEditor.dll 做的一个代码高亮记事本
WinForm控件开发【转载】
桂圆 · 2007-05-18 · via 博客园 - 桂圆

http://www.cnblogs.com/luqingfei/archive/2007/03/1...

用VS建两个项目(CustomControlSample, TestControl), 项目类型分别是类库(不是内裤!!!), Windows应用程序.

using System.Windows.Forms;
 using System.Drawing;
 
 namespace CustomControlSample
 {
   public class FirstControl : Control
   {
       private int simpleField;
 
        public int SimpleProperty
        {
            get { return simpleField; }
            set { simpleField = value; }
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            e.Graphics.DrawRectangle(Pens.Red, new Rectangle(Point.Empty, new Size(Width - 1, Height - 1)));
        }
    }
}
 
写完后 生成 DLL 文件 
然后在 WINFORM 窗体 引用这个DLL 文件 
 
 
 

只有一个属性的控件!!!
拖到windows 窗体上:

在属性浏览器中可以看到该控件的唯一属性:

一个最最简单的Dot net winform控件做好了.

     在这里用到 属性(Attribute),  属性(Attribute)与属性(Property)不同, 前者是用来描述编程元素的,后都是用来描述对象的. 简单地说, 错了不要骂我!!!
将上代码稍稍改动了一点:

 using System.ComponentModel;
 using System.Windows.Forms;
 using System.Drawing;
 
 namespace CustomControlSample
 {
public class FirstControl : Control
{
private int simpleField;
 
        [Category("我是属性,我怕谁!")]
        [Description("我是属性,故我在(属性浏览器中)!")]
 public int SimpleProperty
 {
 get { return simpleField; }
 set { simpleField = value; }
        }
 
 protected override void OnPaint(PaintEventArgs e)
 {
 base.OnPaint(e);
            e.Graphics.DrawRectangle(Pens.Red, new Rectangle(Point.Empty, new Size(Width - 1, Height - 1)));
        }
    }
}