In Depth Banner
Skip Navigation Links

Select your preferred language

To create the window region.

 

    private void CreateWindowRegion()

    {

      GraphicsPath gp=new GraphicsPath(FillMode.Winding);

      gp.AddArc(0,0,90,90,180,90);

      gp.AddLine(45,0,this.Size.Width-45,0);

      gp.AddArc(this.Size.Width-90,0,90,90,270,90);

      gp.AddLine(this.Size.Width,45,this.Size.Width,this.Size.Height-45);

      gp.AddArc(this.Size.Width-90,this.Size.Height-90,90,90,0,90);

      gp.AddLine(this.Size.Width-45,this.Size.Height,45,this.Size.Height);

      gp.AddArc(0,this.Size.Height-90,90,90,90,90);

      gp.AddLine(0,this.Size.Height-45,0,45);

      gp.CloseFigure();

 

      OuterPath=gp;

 

      GraphicsPath border=(GraphicsPath)gp.Clone();

 

      border.Widen(new Pen(Color.Black,4));

 

      borderRegion=new Region(border);

 

      System.Drawing.Region r = new Region(gp);

      

      r.Union(new Rectangle(this.Width-(45),45-closerPos,closerPos,closerPos));

 

      this.Region=r;    

    }

 

The area used to contain the close button is a simple rectangular region that can be moved into position step-by-step to reveal the area where the bitmap representing the close button is painted.  The dynamic shape of the window is controlled by the union of the main region and the rectangle. 

 

Return to the article. 

Copyright © Bob Powell 2003-2009. All rights reserved