终于,从System.Windows.Forms.Control继承了一下。
一个好网页,不错,聊天记录,记下。
前天发的这个随笔,里面记载了一些资源,由于真正接触.NET(Win Form?)还是比较晚,所以目前为止还是笨鸟,还是后飞。
仔细看了里面一些资源,终于做出来了第一个Control,庆祝一下吧。
前天发的这个随笔,里面记载了一些资源,由于真正接触.NET(Win Form?)还是比较晚,所以目前为止还是笨鸟,还是后飞。
仔细看了里面一些资源,终于做出来了第一个Control,庆祝一下吧。
using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Design;
namespace DividerPanel
{
/// <summary>
/// My First Control.
/// </summary>
[ToolboxItem(true)]
[ToolboxBitmap(typeof(MyFirstControl))]
public class MyFirstControl : System.Windows.Forms.Control
{
private System.Drawing.Drawing2D.GraphicsPath graphicsPath = new GraphicsPath(System.Drawing.Drawing2D.FillMode.Alternate);
private Color backColor = Color.Black;
public MyFirstControl()
{
this.graphicsPath.AddPolygon(new Point[]{
new Point(10, 0),
new Point(10, 10),
new Point(0, 10),
new Point(0, 90),
new Point(10, 90),
new Point(10, 100),
new Point(190, 100),
new Point(190, 90),
new Point(200, 90),
new Point(200, 10),
new Point(190, 10),
new Point(190, 0)
});
this.Region = new Region(graphicsPath);
}
private void InitializeComponent()
{
}
protected override void OnPaint(PaintEventArgs e)
{
LinearGradientBrush b = new LinearGradientBrush(this.ClientRectangle,
this.backColor, this.backColor, 0, false);
e.Graphics.FillRectangle(b, this.ClientRectangle);
}
protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus (e);
this.backColor = Color.Red;
this.Invalidate();
}
protected override void OnLostFocus(EventArgs e)
{
base.OnLostFocus (e);
this.backColor = Color.Black;
this.Invalidate();
}
protected override void OnClick(EventArgs e)
{
base.OnClick (e);
this.Focus();
}
}
}
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Design;
namespace DividerPanel
{
/// <summary>
/// My First Control.
/// </summary>
[ToolboxItem(true)]
[ToolboxBitmap(typeof(MyFirstControl))]
public class MyFirstControl : System.Windows.Forms.Control
{
private System.Drawing.Drawing2D.GraphicsPath graphicsPath = new GraphicsPath(System.Drawing.Drawing2D.FillMode.Alternate);
private Color backColor = Color.Black;
public MyFirstControl()
{
this.graphicsPath.AddPolygon(new Point[]{
new Point(10, 0),
new Point(10, 10),
new Point(0, 10),
new Point(0, 90),
new Point(10, 90),
new Point(10, 100),
new Point(190, 100),
new Point(190, 90),
new Point(200, 90),
new Point(200, 10),
new Point(190, 10),
new Point(190, 0)
});
this.Region = new Region(graphicsPath);
}
private void InitializeComponent()
{
}
protected override void OnPaint(PaintEventArgs e)
{
LinearGradientBrush b = new LinearGradientBrush(this.ClientRectangle,
this.backColor, this.backColor, 0, false);
e.Graphics.FillRectangle(b, this.ClientRectangle);
}
protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus (e);
this.backColor = Color.Red;
this.Invalidate();
}
protected override void OnLostFocus(EventArgs e)
{
base.OnLostFocus (e);
this.backColor = Color.Black;
this.Invalidate();
}
protected override void OnClick(EventArgs e)
{
base.OnClick (e);
this.Focus();
}
}
}