473,544 Members | 2,231 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4174
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*****@oblivi on.com> wrote in message
news:hUR2f.1613 29$tl2.113456@p d7tw3no...
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*****@oblivi on.com> wrote in message
news:hUR2f.1613 29$tl2.113456@p d7tw3no...
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@_spamkille r_bobpowell.net > wrote in message
news:ut******** ******@tk2msftn gp13.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*****@oblivi on.com> wrote in message
news:hUR2f.1613 29$tl2.113456@p d7tw3no...
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 MyUIControlDesi gner
Inherits ControlDesigner

' This will pass click events to the control at design time.
Protected Overrides Function GetHitTest(ByVa l 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.Compone ntModel.Designe r(GetType(MyUIC ontrolDesigner) )>
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.Componen tModel;

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 (FilledGroupBox Designer))]

public class FilledGroupBox : GroupBox

{

Color _innerColor=Col or.CadetBlue;

public Color InnerColor

{

get{return _innerColor;}

set{

_innerColor=val ue;

Invalidate();

}

}

Color _outerColor=Col or.Wheat;

public Color OuterColor

{

get{return _outerColor;}

set{

_outerColor=val ue;

Invalidate();

}

}

Point _focusPoint=new Point(50,50);

public Point FocusPoint

{

get{return _focusPoint;}

set{

_focusPoint=val ue;

Invalidate();

}

}

public FilledGroupBox( )

{

}

protected override void OnPaintBackgrou nd(PaintEventAr gs pevent)

{

GraphicsPath pth=new GraphicsPath();

pth.AddRectangl e(this.ClientRe ctangle);

PathGradientBru sh pgb=new PathGradientBru sh(pth);

pgb.CenterColor =this.InnerColo r;

pgb.SurroundCol ors=new Color[]{this.OuterColo r};

pgb.CenterPoint =this.FocusPoin t;

pevent.Graphics .FillRectangle( pgb,this.Client Rectangle);

pgb.Dispose();

pth.Dispose();

}

}

public class FilledGroupBoxD esigner : 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(ICom ponent component)

{

base.Initialize (component);

//adds handlers to the mouse events of the control

this.Control.Mo useDown+=new MouseEventHandl er(Control_Mous eDown);

this.Control.Mo useUp+=new MouseEventHandl er(Control_Mous eUp);

this.Control.Mo useMove+=new MouseEventHandl er(Control_Mous eMove);

}

protected override void Dispose(bool disposing)

{

//removes handlers from the mouse events of the control

this.Control.Mo useDown-=new MouseEventHandl er(Control_Mous eDown);

this.Control.Mo useUp-=new MouseEventHandl er(Control_Mous eUp);

this.Control.Mo useMove-=new MouseEventHandl er(Control_Mous eMove);

base.Dispose (disposing);

}

protected override void OnPaintAdornmen ts(PaintEventAr gs pe)

{

//paints the grab-handle over the focus point.

base.OnPaintAdo rnments (pe);

FilledGroupBox fgb=(FilledGrou pBox)this.Contr ol;

pe.Graphics.Fil lRectangle(Brus hes.White,fgb.F ocusPoint.X-4,fgb.FocusPoin t.Y-4,8,8);

pe.Graphics.Dra wRectangle(Pens .Black,fgb.Focu sPoint.X-4,fgb.FocusPoin t.Y-4,8,8);

}

protected override bool GetHitTest(Poin t point)

{

//checks to see if the point is in the grab-handle

FilledGroupBox fgb=(FilledGrou pBox)this.Contr ol;

Point pnt=fgb.PointTo Client(point);

Rectangle rc=new Rectangle(fgb.F ocusPoint.X-4,fgb.FocusPoin t.Y-4,8,8);

if(rc.Contains( pnt))

{

_inGrabber=true ;

return true;

}

_inGrabber=fals e;

return base.GetHitTest (point);

}

protected override void OnSetCursor()

{

if(_inGrabber)

Control.Cursor= Cursors.Hand;

else

base.OnSetCurso r ();

}

private void Control_MouseDo wn(object sender, MouseEventArgs e)

{

_mouseDown=true ;

}

private void Control_MouseUp (object sender, MouseEventArgs e)

{

_mouseDown=fals e;

}

private void Control_MouseMo ve(object sender, MouseEventArgs e)

{

if(_mouseDown)

{

//modifies the value in the control

FilledGroupBox fgb=(FilledGrou pBox)this.Contr ol;

MemberDescripto r
md=TypeDescript or.GetPropertie s(fgb,null)["FocusPoint "];

PropertyDescrip tor pd=md as PropertyDescrip tor;

Point oldPoint=(Point )pd.GetValue(fg b);

if(pd!=null)

pd.SetValue(fgb ,new Point(e.X,e.Y)) ;

//update the designer host and the property grid

this.RaiseCompo nentChanging(md );

this.RaiseCompo nentChanged(md, oldPoint,new Point(e.X,e.Y)) ;

fgb.Invalidate( );

}

}

}

}

"Don" <un*****@oblivi on.com> wrote in message
news:q7V2f.1515 46$1i.63468@pd7 tw2no...
Have you got any links on some tutorials on how to create a designer for a
UI control?

- Don
"Bob Powell [MVP]" <bob@_spamkille r_bobpowell.net > wrote in message
news:ut******** ******@tk2msftn gp13.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*****@oblivi on.com> wrote in message
news:hUR2f.1613 29$tl2.113456@p d7tw3no...
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
2800
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 routine. However, when I try to compile, I get an error saying that I can't access that event handler because it is Private. When I change the event...
1
1184
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 associated with that location (i.e. FK into another DB or just say a unique ID and the name of tha location) and load that info (client side) into check box...
6
5040
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 regular defensive programming? (ie if file exists do this, if not do something else) Or should Try + Catch be used TO SUPPLAMENT regular defensive...
22
3348
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 why. Is this true? If so, why? Thanks. STom
11
2558
by: Terry Olsen | last post by:
How can I catch a right-click on a DropDownMenuItem?
8
7012
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 more errors encountered while loading the designer. The errors
5
1822
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 the events which is a composition of the basic events. How to? Where can I find some examples£¿
11
1469
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 method to handle, say, 3 separate events: A, B, and C. I only want all 3 to execute if all 3 can successfully execute. Is that what a try-catch is...
1
4278
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. From your codes, I think the logical is, every time the Timer's elapsed event fires, we call the Check_For_Version_Update() function. From the...
0
7438
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7374
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7783
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7392
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
4930
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3430
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1850
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
996
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
677
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.