using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using ControlsDraw;namespace frmDraw { public partial class Form1 : Form { ToolTip tip = new ToolTip(); LableEx lblex = new LableEx("I am LableEx"); RectangleEx rectex = new RectangleEx("I am Rect"); EllipseEx ellex = new EllipseEx("I am Ellipse"); CheckBoxEx chkex = new CheckBoxEx("I am CheckBox"); EntityList elist = new EntityList(); int X; int Y; public Form1() { InitializeComponent(); SetStyle(ControlStyles.OptimizedDoubleBuffer, true); } private void Form1_Load(object sender, EventArgs e) { lblex.StartPoint = new Point(200, 10); elist.Add(lblex); elist.Add(rectex); elist.Add(ellex); elist.Add(chkex); } private void Form1_MouseMove(object sender, MouseEventArgs e) { X = e.X; Y = e.Y; foreach (EntityBase eb in elist) { if (eb.Contains(X, Y)) { tip.Show(eb.Name, this); return; } } tip.Hide(this); } private void Form1_MouseHover(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { //lblex.SetProperty(); Invalidate(); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); lblex.DrawEntity(e); rectex.DrawEntity(e); ellex.DrawEntity(e); chkex.DrawEntity(e); } } }//画圆形的类 public class EllipseEx : EntityBase { GraphicsPath gp = new GraphicsPath(); public EllipseEx(string name) : base() {
this.Name = name; this.StartPoint = new Point(120, 100); this.Size = new Size(30, 30); } public override void DrawEntity(PaintEventArgs e) { using (brush = new SolidBrush(Color.Red)) { g = e.Graphics; gp.AddEllipse(Rect); g.FillPath(brush, gp); } } public override bool Contains(int X, int Y) { return gp.IsVisible(X, Y); } public override void SetProperty() { throw new NotImplementedException(); } }
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ControlsDraw;namespace frmDraw
{
public partial class Form1 : Form
{
ToolTip tip = new ToolTip();
LableEx lblex = new LableEx("I am LableEx");
RectangleEx rectex = new RectangleEx("I am Rect");
EllipseEx ellex = new EllipseEx("I am Ellipse");
CheckBoxEx chkex = new CheckBoxEx("I am CheckBox");
EntityList elist = new EntityList(); int X;
int Y;
public Form1()
{
InitializeComponent();
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
} private void Form1_Load(object sender, EventArgs e)
{
lblex.StartPoint = new Point(200, 10);
elist.Add(lblex);
elist.Add(rectex);
elist.Add(ellex);
elist.Add(chkex);
} private void Form1_MouseMove(object sender, MouseEventArgs e)
{
X = e.X;
Y = e.Y;
foreach (EntityBase eb in elist)
{
if (eb.Contains(X, Y))
{
tip.Show(eb.Name, this);
return;
}
}
tip.Hide(this);
} private void Form1_MouseHover(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
//lblex.SetProperty();
Invalidate();
} protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
lblex.DrawEntity(e);
rectex.DrawEntity(e);
ellex.DrawEntity(e);
chkex.DrawEntity(e);
} }
}//画圆形的类
public class EllipseEx : EntityBase
{
GraphicsPath gp = new GraphicsPath(); public EllipseEx(string name)
: base()
{
this.Name = name;
this.StartPoint = new Point(120, 100);
this.Size = new Size(30, 30);
} public override void DrawEntity(PaintEventArgs e)
{
using (brush = new SolidBrush(Color.Red))
{
g = e.Graphics;
gp.AddEllipse(Rect);
g.FillPath(brush, gp);
}
} public override bool Contains(int X, int Y)
{
return gp.IsVisible(X, Y);
} public override void SetProperty()
{
throw new NotImplementedException();
}
}