|
-
Jun 22nd, 2011, 04:11 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Make button work in designer VS2010
I am designing a program that will have 2 panels on top of each other with different controls in them. The user will be able to switch between the panels with a button outside of them.
I remember a custom tab control here on these forums that had a button with which you could switch to next tab, but the amazing thing was that the button worked in the designer. If you clicked it you switched to next tab in the designer.
I want the switch button I have to also work in the designer, so I can easily switch between the panels when changing their content.
What code do I need to make that happen?
-
Jun 22nd, 2011, 05:34 PM
#2
Re: Make button work in designer VS2010
What you need to do is create your own ControlDesigner. You would then apply that Designer to your new inherited Button. Inside your custom ControlDesigner you would override the GetHitTest function where you would determine whether or not mouse events at the specified location should be processed. To use my example below you will need to add a reference to System.Design.
Code:
public class ButtonDesigner : ControlDesigner
{
protected override bool GetHitTest(Point point)
{
if (this.Control is DesignerButton)
{
//test if the click occurred inside the button
if (this.Control.ClientRectangle.Contains(
this.Control.PointToClient(Cursor.Position)))
return true;
}
//nothing for us to do so let the base class process this call
return base.GetHitTest(point);
}
}
[Designer(typeof(ButtonDesigner))]
public class DesignerButton : Button
{
protected override void OnMouseClick(MouseEventArgs e)
{
//this code will get run at design time
MessageBox.Show("Clicked!");
base.OnMouseClick(e);
}
}
If you add these classes to your project, build, and add the DesignerButton from the ToolBox, and click it, you will see the MessageBox.
-
Jun 22nd, 2011, 06:07 PM
#3
Thread Starter
Hyperactive Member
Re: Make button work in designer VS2010
thx now I get it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|