Quick Search for:  in language:    
ANY,TEXT,FONT,SIZE,ever,wanted,make,your,form
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Visual Basic Stats

 Code: 3,014,970. lines
 Jobs: 119. postings

 How to support the site

 
Sponsored by:

 

You are in:

 
Login



Latest Code Ticker for Visual Basic.
DBTool
By Make Strömberg on 7/2


Click here to see a screenshot of this code!MSChart Simple Example
By Sebastian Pereira on 7/2

(Screen Shot)

CString v1.5
By Ultimatum on 7/2


Tablature Pro
By Michael McMullen on 7/2


Click here to see a screenshot of this code!MSN Password Decryptor
By Muhammad Sufyan Ansari on 7/2

(Screen Shot)

Mp3 Paker
By Michael McMullen on 7/2


Suppress Run Time Script Errors
By Nuclear_1000G on 7/2


Click here to see a screenshot of this code!List Maker
By KBM-00 on 7/1

(Screen Shot)

Web Update Checker
By knormalnight on 7/1


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

Character shaped forms!!

Print
Email
 

Submitted on: 1/12/2000
By:  
Level: Intermediate
User Rating: By 10 Users
Compatibility:VB 5.0, VB 6.0

Users have accessed this code 10356 times.
 
(About the author)
 
     Have you ever wanted to make your form's shape odd? Ok, there are several samples and programs around that can make your forms like a shape(circle, rounded box or something a little bit more complicated). But here is the example to make your form's shape to be ANY TEXT, in ANY FONT, in ANY SIZE and also any two colour's gradient. It's a really good example. Imagine you can shape the form not to be just plain text, but the shape of special fonts(such as Windings and Webdings). Just change the GetTextRgn function's variables(Font, Size, Text) and the variable Color1 and Color2. Easy. And the result is outstanding! You can also use the Chr$ function to add a text(this is useful for spec. chars).
 
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: Character shaped forms!!
' Description:Have you ever wanted to ma
'     ke your form's shape odd? Ok, there are 
'     several samples and programs around that
'     can make your forms like a shape(circle,
'     rounded box or something a little bit mo
'     re complicated). But here is the example
'     to make your form's shape to be ANY TEXT
'     , in ANY FONT, in ANY SIZE and also any 
'     two colour's gradient. It's a really goo
'     d example. Imagine you can shape the for
'     m not to be just plain text, but the sha
'     pe of special fonts(such as Windings and
'     Webdings). Just change the GetTextRgn fu
'     nction's variables(Font, Size, Text) and
'     the variable Color1 and Color2. Easy. An
'     d the result is outstanding! You can als
'     o use the Chr$ function to add a text(th
'     is is useful for spec. chars).
' By: 
'
' Inputs:Change the GetTextRgn function'
'     s variables(Font, Size, Text) and the va
'     riable Color1 and Color2. Easy. And the 
'     result is outstanding! You can also use 
'     the Chr$ function to add a text(this is 
'     useful for spec. chars).
'
' Assumes:Copy ALL the code to a blank f
'     orm.(remove Form_Load() first) Then afte
'     r setting the parameters mentioned (or l
'     eave them for first check) run the proje
'     ct.
'
'This code is copyrighted and has' limited warranties.Please see http://w
'     ww.Planet-Source-Code.com/vb/scripts/Sho
'     wCode.asp?txtCodeId=5448&lngWId;=1'for details.'**************************************

Option Explicit
Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
    End Type
    'API calls required for doing this cool 
    '     stuff

Private Declare Function BeginPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Private Declare Function EndPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function PathToRegion Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetRgnBox Lib "gdi32" (ByVal hRgn As Long, lpRect As RECT) As Long
Private Declare Function CreateRectRgnIndirect Lib "gdi32" (lpRect As RECT) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const WM_NCLBUTTONDOWN = &HA1;
    Private Const HTCAPTION = 2
    Private Const RGN_AND = 1
    Dim Color1 As Long
    Dim Color2 As Long
Private Function GetTextRgn(Font As String, Size As Integer, Text As String) As Long

Me.Font = Font Me.FontSize = Size Dim hRgn1 As Long, hRgn2 As Long Dim rct As RECT BeginPath hdc TextOut hdc, 10, 10, Text, Len(Text) EndPath hdc hRgn1 = PathToRegion(hdc) GetRgnBox hRgn1, rct hRgn2 = CreateRectRgnIndirect(rct) CombineRgn hRgn2, hRgn2, hRgn1, RGN_AND DeleteObject hRgn1 GetTextRgn = hRgn2 End Function
Private Sub GradateColors(Colors() As Long, ByVal Color1 As Long, ByVal Color2 As Long)
On Error Resume Next Dim i As Integer Dim dblR As Double, dblG As Double, dblB As Double Dim addR As Double, addG As Double, addB As Double Dim bckR As Double, bckG As Double, bckB As Double dblR = CDbl(Color1 And &HFF;) dblG = CDbl(Color1 And &HFF00;&) / 255 dblB = CDbl(Color1 And &HFF0000;) / &HFF00;& bckR = CDbl(Color2 And &HFF;&) bckG = CDbl(Color2 And &HFF00;&) / 255 bckB = CDbl(Color2 And &HFF0000;) / &HFF00;& addR = (bckR - dblR) / UBound(Colors) addG = (bckG - dblG) / UBound(Colors) addB = (bckB - dblB) / UBound(Colors) For i = 0 To UBound(Colors) dblR = dblR + addR dblG = dblG + addG dblB = dblB + addB If dblR > 255 Then dblR = 255 If dblG > 255 Then dblG = 255 If dblB > 255 Then dblB = 255 If dblR < 0 Then dblR = 0 If dblG < 0 Then dblG = 0 If dblG < 0 Then dblB = 0 Colors(i) = RGB(dblR, dblG, dblB) Next
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'these are for moving the form without i ' ts titlebar ReleaseCapture SendMessage hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0& End Sub
Private Sub Form_Paint()
Dim Colors() As Long Dim Iter As Long Const Banding = 8 ReDim Colors(ScaleHeight \ Banding) As Long GradateColors Colors(), Color1, Color2 For Iter = 0 To ScaleHeight Step Banding Line (0, Iter)-(ScaleWidth, Iter + Banding), Colors(Iter \ Banding), BF Next
End Sub
Private Sub Form_Load()
Dim hRgn As Long hRgn = GetTextRgn("Wingdings", 100, "J" & "<") 'change the values: Font, Size (font), Text SetWindowRgn hWnd, hRgn, 1 Color1 = vbBlack 'set this colours For gradient effect (use vb colour constants for easy use) Color2 = vbBlue Me.Refresh End Sub


Other 13 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Intermediate 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
1/12/2000 7:10:38 PM:^DaRk^
YEA! this is pretty cool, great work, 
im impressed
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
1/13/2000 7:49:14 AM:Olga
I don't know how to make practical use 
of this, but it's great!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
1/13/2000 10:18:55 AM:bbence
Olga
Maybe you could use the forms as 
a splash screen.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
1/13/2000 2:00:58 PM:DrF
This is great, thanks
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
1/26/2000 8:52:04 AM:RiverRaid
This is quite cool!!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
1/26/2000 5:07:13 PM:Michael Barnathan
I have to admit, this takes skill to 
code! Good job! I can actually use this 
to rebuild my On-screen display for my 
easy access keys. Thanks!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
1/27/2000 5:54:56 PM:Jared Collums
WOW. That was sooooo cool. I'm voting 
it EXCELLENT.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/4/2000 7:07:49 AM:Ahmed
Pls u Send Us your new software 
Thanks & best Regards.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/5/2000 5:51:49 AM:Megalos
nice idea...i may use this for a about 
message....splash...and i belive many 
places for warnings..its cool.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/23/2000 12:14:28 PM:bbence
I just wanted to thank you for the good 
ratings and feedback. Thank you guys!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
4/3/2000 11:06:47 PM:etrask
This is the sweetest code ever
How 
do you change from the smiley face
and 
the disk? I want t ohave my name up 
there
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
4/16/2000 5:07:51 PM:bbence
Change the variables of the GetTextRgn 
function.
retval = GetTextRgn(Fontname 
as String, Fontsize as Integer, Text as 
String) 
bbence
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/9/2000 4:53:51 AM:Seldon
Awesome code! Thanks for posting this, 
it's quite an achievement.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/21/2000 3:37:14 PM:Geoff
Great code!!!
Does anybody know how to 
hide the rectangular border that you 
see while dragging it?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/27/2000 2:24:08 PM:Jason Foral
Cool! You get my excellent vote! Is 
there anyway I can make the form's 
shape that of a Image or picture? If 
so, let me know!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/20/2000 12:41:28 PM:bbence
Justin Moser: i don't have any clue. 
Please if somebody tried it on win2000, 
tell. 
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
12/20/2000 11:46:40 AM:S-Car
hey i just tried it in win2k, it works 
and looks REALLY cool!!!!!!!!!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/4/2002 2:00:26 PM:Ozan Yasin Dogan
it is how a tutorial code must 
be!
excellent explanation, works fine, 
5+
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
12/11/2002 11:52:42 AM:
Cool! 
Great job...
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Visual Basic Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.