473,385 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 4156
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: George | last post by:
I'm having a weird problem. When I double-click a Web server control that I have on my design-time Web form, such as a button, it puts the event handler in the Code Behind as a Private Sub...
1
by: collegeCoder | last post by:
Please help I want to show a mapPoint map on a web page with say thumbtacks or som other marker to show where a location is. When the user clicks on tha location I want to take some data...
6
by: Martin Ortiz | last post by:
Which is best approach? Should Try + Catch be used to only deal with "catastrophic" events (like divide by zero, non-existant file, etc...etc...) Or should Try + Catch be used IN PLACE of...
22
by: STom | last post by:
I heard someone mention to me that the use of try catch exception handling is very expensive (in relative terms of slowing an app down) if it is used frequently. Of course they could not explain...
11
by: Terry Olsen | last post by:
How can I catch a right-click on a DropDownMenuItem?
8
by: dbuchanan | last post by:
Hello, What does this error mean? "The event click is read-only and cannot be changed" This is a design-time error. It is displayed instead of the form. Here is the full text \\ "One or...
5
by: sleepinglord | last post by:
An example: I have a select input. I wanna catch those onclick events which is not a onchange events. How to implement it? And in general, there's some basic kinds of events, and I wanna catch...
11
by: darrel | last post by:
Trying to get back into .net again after being out of it for a while. I'm trying to figure out the proper way to handle multiple events via a try catch. What I'm confused about is the proper...
1
by: \Ji Zhou [MSFT]\ | last post by:
Hello Jason, Thanks for using Microsoft Newsgroup Support Service, my name is Ji Zhou and I will be working on this issue with you. I have tried to but cannot reproduce your issue on my side....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.