Click here to Skip to main content
Licence 
First Posted 19 Mar 2002
Views 87,233
Downloads 1,947
Bookmarked 56 times

Interactive Shaped Forms

By Jibin Pan | 19 Mar 2002
This Demo show how to create shaped form and customized buttons using the Region, GraphicsPath and picture class
6 votes, 42.9%
1
1 vote, 7.1%
2
2 votes, 14.3%
3

4
5 votes, 35.7%
5
2.59/5 - 16 votes
μ 2.50, σa 3.23 [?]

Sample Image - ShapedForm.jpg

Introduction

This Demo show how to create shaped form and customized buttons using the Region, GraphicsPath and picture class. It also demonstrates using the picture control to display animated pictures.

All graphics are from Microsoft Media Player and have been resized to make the graphic files smaller.

The procedures:

  1. Create a form with some background color, then set the property TransparenceKey to that color and set the FormBorderStyle to None.

  2. Override the Form_Paint function

    You can do it by

    protected override void  OnPaint(PaintEventArgs e)

    or add a new Handler

    this.Paint += new System.Windows.Form.PaintEventHandler(Form_Paint)

  3. Using Region and GraphicsPath to set the Region that you want to display.
    im = new Bitmap("mediaPlayer.jpg"); 
    
    private void Form_Paint(object sender, PaintEventArgs e) 
    { 
       Graphics g = e.Graphics; 
    
       Rectangle mainRect = new Rectangle(0, 0, 695, 278); 
    
       Region mainRegion = new Region(mainRect); 
    
       e.Graphics.SetClip(mainRegion, CombineMode.Replace); 
    
       // Create a GraphicsPath object and add a curve. 
       GraphicsPath myPath = new GraphicsPath(); 
    
       ... 
    
       Region ExcludeRegion3 = new Region(myPath); 
    
       e.Graphics.ExcludeClip(ExcludeRegion3); 
    
       ... 
    
       e.Graphics.DrawImage(im, 0, 0, 495,278); 
    
       // Reset clipping region to infinite. 
       e.Graphics.ResetClip(); 
    } 
    

Note: Keep all the graphics in the bin/debug directory.

If you have any comments, I would love to hear about it. You can reach me at Jibin Pan.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Jibin Pan



United States United States

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralHelp wanted!!!! Pinsussnanu_babu21:39 5 Jun '03  
QuestionUrrrm..Object not defined? PinsussDrutch5:04 21 Apr '03  
AnswerRe: Urrrm..Object not defined? PinsussAnonymous19:54 30 Jan '05  
GeneralPlatform specific PinmemberNikhil Dabas2:20 20 Mar '02  
GeneralRe: Platform specific Pinmemberswinefeaster21:46 14 Apr '02  
GeneralRe: Platform specific Pinmemberori_yq4:23 31 Dec '02  
GeneralRe: Platform specific PinmemberNikhil Dabas11:07 2 Jan '03  
You have to do something like this:
 
GraphicsPath ellipsePath = new GraphicsPath();
ellipsePath.AddEllipse(2, 22, 300, 100);
Form.Region = new Region(ellipsePath);
 
You'll get an elliptical form with this. See the docs on GraphicsPath for creating other shapes.
 
Hope this helps.
 
A list is only as strong as its weakest link. - Don Knuth

GeneralRe: Platform specific PinmemberHeath Stewart3:25 28 Jan '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120210.1 | Last Updated 20 Mar 2002
Article Copyright 2002 by Jibin Pan
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid