Important alert: (current site time 7/16/2013 4:15:46 AM EDT)
 

VB icon

Change Form Shape

Email
Submitted on: 2/11/1998
By: David Serrano  
Level: Not Given
User Rating: By 105 Users
Compatibility: VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 65210
 
     Can Change The Shape of any form
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :Change Form Shape
'**************************************
Public Declare Function CreateEllipticRgn Lib "gdi32" _
 (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, _
 ByVal Y2 As Long) As Long
Public Declare Function SetWindowRgn Lib "user32" _
 (ByVal hWnd As Long, ByVal hRgn As Long, _
 ByVal bRedraw As Boolean) As Long
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: Change Form Shape
' Description:Can Change The Shape of any form
' By: David Serrano
'
' Inputs:Look Below
'
' Side Effects:The border can be preatty messed up if you don't know what your doing
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=794&lngWId=1'for details.'**************************************

Private Sub Form_Load()
Show 'The form!
SetWindowRgn hWnd, CreateEllipticRgn(0, 0, 300, 200), True
End Sub
'E-mail Me at BTMSoft@aol.com for more info


Other 4 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
4/12/1999 3:09:00 AMMitchell

David I would like to make a form 480 x 640 that is a landscape oriented rectangle with approximately 1/2 inch radius corners, How? Thank you
(If this comment was disrespectful, please report it.)

 
5/5/1999 9:29:00 PMAdam

I'm working with some chat rooms at the moment and I am trying to make a form about 6" by 3.5" with rounded corners. Will someone please help me out?
(If this comment was disrespectful, please report it.)

 
5/11/1999 8:23:00 PMNocturnal

This code is great Dave! Its alot more precise than alot of others
i have seen.. and much more efficient. Changes the size is a snap and
so is the blending!
Thanks again for posting this one!
-Nocturnal
(If this comment was disrespectful, please report it.)

 
5/11/1999 10:01:00 PMRolf

Very nice but it isnt what i need.. i need to set form window shape by Mask color... not by polyagon type of any kind.. OK here is example.. if form has a picture of solid white circle with pink background, when its running it shows just solid white circle.
(If this comment was disrespectful, please report it.)

 
5/18/1999 12:32:00 AMPasha

Yep, this one looks nice. Except when you maximize the form, it looks kinda weird. :)
(If this comment was disrespectful, please report it.)

 
5/19/1999 2:06:00 AMKiran

Sir,
Code was very simple and neat .thanks
is there anyway that we can make the shape of the form as a rounded Rectangle. It would be of great if u could help me in this.
(If this comment was disrespectful, please report it.)

 
5/25/1999 2:48:00 AMsiva

this is really good
send me any kind of tricks & tips in Code.
Thank you.

(If this comment was disrespectful, please report it.)

 
6/16/1999 11:41:00 AMSpidey

And how can i do the same in VBA? (Excel 97?)
(If this comment was disrespectful, please report it.)

 
6/28/1999 8:48:00 PMAllen

Can anybody suggest the most flexible reporting tool for visual basic other then Crystal Reports. Crystal reports does'nt seem to allow run time customisation and alteration of the fields in the report. An alternative is printing to a text file with lots of code, but the amount of coding involved is discouraging. Any suggestions?

(If this comment was disrespectful, please report it.)

 
7/3/1999 9:55:00 AMScorpion

I think this code is useful.
There is one thing I would like to know however, and that is how I can minimize this form? I have the BorderStyle set to None, so I don't have a titlebar. Is there a way to minimize it? -thanks
(If this comment was disrespectful, please report it.)

 
7/5/1999 4:17:00 AMPrince Zala

sounds Great !

pass me the code david,
I want to make a Stock Ticker with this.
(If this comment was disrespectful, please report it.)

 
7/17/1999 10:23:00 AMMinimize

Lots of people asked how to minimize the form if you have no border.
You can minimize the form by placing a button or something else that supports click event.
Then add this code (Can be used on any borderstyle except for tool windows i think):

Command1_Click
Me.WindowState = 1
End sub
(If this comment was disrespectful, please report it.)

 
7/19/1999 9:12:00 PMET

I don't know if this will help anyone, but...
Remember the 4 numbers in this line:
SetWindowRgn hWnd, CreateEllipticRgn(0, 0, 300, 200), True ?
Changing those numbers makes the form look different.
(If this comment was disrespectful, please report it.)

 
9/5/1999 6:16:00 PMfatboy_k

thanks for the code, it helped me out
(If this comment was disrespectful, please report it.)

 
9/7/1999 7:24:00 AMJonathan

this code is pretty good ...
however when u drag the form u can see the rectangle outline of it
has anyone found a way to fix this ?
(If this comment was disrespectful, please report it.)

 
9/9/1999 11:02:00 PMKobie

How can U make a source code that U will use an unbound control to be appended to record that has already been made?
(If this comment was disrespectful, please report it.)

 
10/7/1999 11:25:00 PMcindy

Do you have any Questions and answers form to share?
(If this comment was disrespectful, please report it.)

 
10/9/1999 4:44:00 AMNakarin

this is really goodsend me any kind of tricks & tips in Code.Thank you.
(If this comment was disrespectful, please report it.)

 
10/18/1999 8:06:00 PMToM

Yo this code is way sweet. keep up figuring out this cool useful code man! :)
(If this comment was disrespectful, please report it.)

 
10/30/1999 4:35:00 AMITGuy

I want to make a form the shape of Kilimanjaro, HOW?

(If this comment was disrespectful, please report it.)

 
11/4/1999 2:38:00 PMRyan Rife

Try:

Option Explicit
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long

Private Sub Form_Resize()
SetWindowRgn hWnd, CreateRoundRectRgn(0, 0, Me.Width / Screen.TwipsPerPixelX, Me.Height / Screen.TwipsPerPixelY, 15, 15), True
End Sub
(If this comment was disrespectful, please report it.)

 
11/6/1999 3:15:00 PMcuzc0

thax ryan.
(If this comment was disrespectful, please report it.)

 
11/8/1999 9:36:00 AMThinh

very wonderful code
(If this comment was disrespectful, please report it.)

 
12/15/1999 12:08:03 PMSuat

Good. Very good. And thank you increase my technical imagine.
(If this comment was disrespectful, please report it.)

 
1/24/2000 1:15:34 AMWalter Narvasa

David,

Code was very simple and yet very cool !!, thanks for the tip..i am currently creating a PC STRATEGY GAME with lots of graphics & simulation in it, if you want to help or join me just email me man..
By the way, is there anyway that we can
make the shape of the form as a rounded
Rectangle. Can you help me out..thanks..
(If this comment was disrespectful, please report it.)

 
5/8/2000 2:14:08 AMAgnyeya

Kinda funny
(If this comment was disrespectful, please report it.)

 
7/4/2000 7:44:54 AM¤KEEL¤

Hola David:Espero que hables español,
nesecito tu ayuda , mira mi problema es
el siguiente , soy totalmente nuevo en
este campo de programacion ynesecito
saber como escribir o como ordenarle a
la pc para que haga lo que yo quiero
(me explico )yo quiero aprender a crear
mi propio code pero desconozco como
escribir lo que tengo en mente no se
cuando usar simbolos como *,"",= etc
hay alguna forma de aprender atranslate
mis ordenes al programa como se hace?
Por favor te agradecera eternamente si
me puedes brindar tu ayuda con algun
consejo Email me a kazz@ProgenIC.zzn.com
(If this comment was disrespectful, please report it.)

 
7/15/2000 1:00:48 PMHelper

To make your form a rectangle with rounded edges just increase the numbers under form load! Make the circle BIGGER!
(If this comment was disrespectful, please report it.)

 
8/11/2002 12:00:31 AM

:( Doesn't work under XP!!!!
(If this comment was disrespectful, please report it.)

 
7/3/2005 9:18:29 AM

nice code examples here. all works sweet in vb6 under winxp. keep up good work.
(If this comment was disrespectful, please report it.)

 
3/31/2006 4:16:58 AMabhimanoj2004

good
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.