Click here to Skip to main content
15,906,558 members
Articles / Programming Languages / C#
Article

Interactive Shaped Forms

Rate me:
Please Sign up or sign in to vote.
2.59/5 (14 votes)
19 Mar 2002 103K   2.7K   61   8
This Demo show how to create shaped form and customized buttons using the Region, GraphicsPath and picture class

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

    C#
    protected override void  OnPaint(PaintEventArgs e)

    or add a new Handler

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

  3. Using Region and GraphicsPath to set the Region that you want to display.
    C#
    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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralHelp wanted!!!! Pin
nanu_babu5-Jun-03 20:39
sussnanu_babu5-Jun-03 20:39 
QuestionUrrrm..Object not defined? Pin
drutch21-Apr-03 4:04
drutch21-Apr-03 4:04 
AnswerRe: Urrrm..Object not defined? Pin
Anonymous30-Jan-05 18:54
Anonymous30-Jan-05 18:54 
GeneralPlatform specific Pin
Nikhil Dabas20-Mar-02 1:20
Nikhil Dabas20-Mar-02 1:20 
GeneralRe: Platform specific Pin
Swinefeaster14-Apr-02 20:46
Swinefeaster14-Apr-02 20:46 
GeneralRe: Platform specific Pin
ori_yq31-Dec-02 3:23
ori_yq31-Dec-02 3:23 
GeneralRe: Platform specific Pin
Nikhil Dabas2-Jan-03 10:07
Nikhil Dabas2-Jan-03 10:07 
GeneralRe: Platform specific Pin
Heath Stewart28-Jan-03 2:25
protectorHeath Stewart28-Jan-03 2:25 

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

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