dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Change the shape of the form in C#

  1. #1
    Join Date
    Aug 2009
    Posts
    19

    Change the shape of the form in C#

    I want to have a form with the shape of a rectangle with rounded corners..

    I have found just how to change it to ellipse form..

    Thanks!

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Change the shape of the form in C#

    Quote Originally Posted by Gbates View Post
    I have found just how to change it to ellipse form..
    Well that is the same way you change it to rectangle. Just change the image that you are using. It shouldn't be difficult.

    By the way, welcome to the forum

  3. #3
    Join Date
    Aug 2009
    Posts
    19

    Re: Change the shape of the form in C#

    I didn't use an image, I used a code.

    thanks :P

    how do I change it with an image?

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Change the shape of the form in C#

    Show us what code have you used.

  5. #5
    Join Date
    Aug 2009
    Posts
    19

    Re: Change the shape of the form in C#

    protected override void OnPaint( System.Windows.Forms.PaintEventArgs e )
    {
    System.Drawing.Drawing2D.GraphicsPath shape = new System.Drawing.Drawing2D.GraphicsPath();
    shape.AddEllipse(0, 0, this.Width, this.Height);
    this.Region = new System.Drawing.Region(shape);
    }

  6. #6
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Change the shape of the form in C#

    You can use Shape.AddRectangle to give it a rectangular look. Or you can use a more easier solution.

    Create the desired image in Paintbrush or a similar application. On the form, set the BackgroundImage property to the new Image that you created. Set the TransparencyKey property to white and FormBorderStyle to none. That is all that you would need to do.

  7. #7
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: Change the shape of the form in C#

    for one corner i calculated the coordination and made the upper left corner round-shaped; you can calculate yourself coordination for other three corners and then make them look rounded just adding a few lines of code to my code. just remember to change my coordination when you add other coordination for other three corners.

    Code:
            protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
            {
                System.Drawing.Drawing2D.GraphicsPath shape = new System.Drawing.Drawing2D.GraphicsPath();
    
                Rectangle rect = new Rectangle(50, 0, this.Width, this.Height);
                Rectangle rect2 = new Rectangle(0, 50, 50, this.Height);
    
                shape.AddPie(0, 0, 100, 100, -90, -90);
                shape.AddRectangle(rect);
                shape.AddRectangle(rect2);
    
                this.Region = new System.Drawing.Region(shape);
            }
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)