Results 1 to 3 of 3

Thread: [RESOLVED] Make button work in designer VS2010

  1. #1

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Resolved [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?

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    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.

  3. #3

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    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
  •  



Click Here to Expand Forum to Full Width