472,145 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

Catch Click Event at Design Time

Don
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
Nov 21 '05 #1
5 4073
Well AFAIK and if i understand you correctly this is not possible

ofcourse you can find the event code of the click if the clicked object
supports a click event , but that is as far as it goes

regards

Michel Posseth

"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

Nov 21 '05 #2
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

Nov 21 '05 #3
Don
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


Nov 21 '05 #4
Don
I figured it out by creating a ControlDesigner class for my UI Control
class.
The ControlDesigner class code looks like this:

Friend Class MyUIControlDesigner
Inherits ControlDesigner

' This will pass click events to the control at design time.
Protected Overrides Function GetHitTest(ByVal point As Point) As Boolean

Return True

End Function

End Class
The UI Control needs to have this designer attached to it via the following:

<System.ComponentModel.Designer(GetType(MyUIContro lDesigner))>
Public Class MyUIControl
...
End Class
That seemed to do the trick...

- Don
Nov 21 '05 #5
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



Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by collegeCoder | last post: by
22 posts views Thread by STom | last post: by
11 posts views Thread by Terry Olsen | last post: by
5 posts views Thread by sleepinglord | last post: by
11 posts views Thread by darrel | last post: by
1 post views Thread by \Ji Zhou [MSFT]\ | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.