After my signature you'll find a simple control and a designer that reacts
to mouse clicks and movements at desighn time. You will be able to use these
principles to do what you want, I think .
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace WellFormed
{
/// <summary>
/// Summary description for FilledGroupBox.
/// </summary>
[Designer(typeof(FilledGroupBoxDesigner))]
public class FilledGroupBox : GroupBox
{
Color _innerColor=Color.CadetBlue;
public Color InnerColor
{
get{return _innerColor;}
set{
_innerColor=value;
Invalidate();
}
}
Color _outerColor=Color.Wheat;
public Color OuterColor
{
get{return _outerColor;}
set{
_outerColor=value;
Invalidate();
}
}
Point _focusPoint=new Point(50,50);
public Point FocusPoint
{
get{return _focusPoint;}
set{
_focusPoint=value;
Invalidate();
}
}
public FilledGroupBox()
{
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
GraphicsPath pth=new GraphicsPath();
pth.AddRectangle(this.ClientRectangle);
PathGradientBrush pgb=new PathGradientBrush(pth);
pgb.CenterColor=this.InnerColor;
pgb.SurroundColors=new Color[]{this.OuterColor};
pgb.CenterPoint=this.FocusPoint;
pevent.Graphics.FillRectangle(pgb,this.ClientRecta ngle);
pgb.Dispose();
pth.Dispose();
}
}
public class FilledGroupBoxDesigner : ControlDesigner
{
//True when the mouse is down
bool _mouseDown;
//True when the mouse is in the grab-handle.
bool _inGrabber;
//Called when the designer is initialized
public override void Initialize(IComponent component)
{
base.Initialize (component);
//adds handlers to the mouse events of the control
this.Control.MouseDown+=new MouseEventHandler(Control_MouseDown);
this.Control.MouseUp+=new MouseEventHandler(Control_MouseUp);
this.Control.MouseMove+=new MouseEventHandler(Control_MouseMove);
}
protected override void Dispose(bool disposing)
{
//removes handlers from the mouse events of the control
this.Control.MouseDown-=new MouseEventHandler(Control_MouseDown);
this.Control.MouseUp-=new MouseEventHandler(Control_MouseUp);
this.Control.MouseMove-=new MouseEventHandler(Control_MouseMove);
base.Dispose (disposing);
}
protected override void OnPaintAdornments(PaintEventArgs pe)
{
//paints the grab-handle over the focus point.
base.OnPaintAdornments (pe);
FilledGroupBox fgb=(FilledGroupBox)this.Control;
pe.Graphics.FillRectangle(Brushes.White,fgb.FocusP oint.X-4,fgb.FocusPoint.Y-4,8,8);
pe.Graphics.DrawRectangle(Pens.Black,fgb.FocusPoin t.X-4,fgb.FocusPoint.Y-4,8,8);
}
protected override bool GetHitTest(Point point)
{
//checks to see if the point is in the grab-handle
FilledGroupBox fgb=(FilledGroupBox)this.Control;
Point pnt=fgb.PointToClient(point);
Rectangle rc=new Rectangle(fgb.FocusPoint.X-4,fgb.FocusPoint.Y-4,8,8);
if(rc.Contains(pnt))
{
_inGrabber=true;
return true;
}
_inGrabber=false;
return base.GetHitTest (point);
}
protected override void OnSetCursor()
{
if(_inGrabber)
Control.Cursor=Cursors.Hand;
else
base.OnSetCursor ();
}
private void Control_MouseDown(object sender, MouseEventArgs e)
{
_mouseDown=true;
}
private void Control_MouseUp(object sender, MouseEventArgs e)
{
_mouseDown=false;
}
private void Control_MouseMove(object sender, MouseEventArgs e)
{
if(_mouseDown)
{
//modifies the value in the control
FilledGroupBox fgb=(FilledGroupBox)this.Control;
MemberDescriptor
md=TypeDescriptor.GetProperties(fgb,null)["FocusPoint"];
PropertyDescriptor pd=md as PropertyDescriptor;
Point oldPoint=(Point)pd.GetValue(fgb);
if(pd!=null)
pd.SetValue(fgb,new Point(e.X,e.Y));
//update the designer host and the property grid
this.RaiseComponentChanging(md);
this.RaiseComponentChanged(md,oldPoint,new Point(e.X,e.Y));
fgb.Invalidate();
}
}
}
}
"Don" <un*****@oblivion.com> wrote in message
news:q7V2f.151546$1i.63468@pd7tw2no...
Have you got any links on some tutorials on how to create a designer for a
UI control?
- Don
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:ut**************@tk2msftngp13.phx.gbl... You can create a designer for your object and subscribe to any event so
that the designer processes the event.
Usually this will result in the designer altering properties and so-on.
It's not neccesarily a good idea to try and run the control at design
time as you would at runtime.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"Don" <un*****@oblivion.com> wrote in message
news:hUR2f.161329$tl2.113456@pd7tw3no... Is there a way to capture click events in the form designer? I'm trying
to create a control similar to the TabControl (which seems to handle
clicks in design mode) and would like to be able to click on parts of
the control in design mode and have the control react, but I can't seem
to trap the events in design mode.
- Don