Your browser does not seem to support CSS. If images appear below, please disregard them.
toggle
February
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29
Sponsored Links
Latest Postings
Topic Options
Rate This Topic
#17770 - 03/13/02 05:29 PM Tips & Tricks - How to make fancy shmancy forms (Part 1)
Joined: Mar 2002
Posts: 1,273
SilentRage Offline
DollarDNS Owner
SilentRage Offline
DollarDNS Owner

Joined: Mar 2002
Posts: 1,273
OH, USA
I just read in one of Gizmo's mass emails that moderators are actually supposed to ENCOURAGE conversation in their forum, so huh, guess what, I guess I better get off my lazy mod *** and start thinking of something to say to a group of mostly non-programmers.

Wanna create cool looking windows but don't know how because VB tends to by default give you a plain jane window with a title bar and all windowy features? Well looky here, I'm going to talk about making fancy shmancy windows in VB.

first of all, we need to start with a clean slate. To get a plain square window with no features whatsoever, create a form and set the following properties:

BorderStyle = 0
Caption = ""
ControlBox = False
ShowInTaskbar = True
(ShowInTaskbar is automatically set to false when you set the ControlBox to false - you should set it back to true)

There we go! Now it's borderless and has no title bar whatsoever. Now we need to make it cool looking. I'm going to change the background to black (BackColor = 0) and create a label to be my new title bar. I change the label's background and foreground colors and the font type/size and position it and size it where I want it. I'm also going to use the line control to draw a few lines on the edges of my form to create the effect of a border (for the borders, you may want to consider using the shape controls). Feel free to add any pictures or a background or whatever fits your style.

Now all that is pretty obvious stuff. Now for the REAL tip & trick. You want to have your user move the form around right? I chose to have it so that the custom title bar is draggable, but you can make it so that they can drag any part of the form. Here's the best way to do it:

Declare these functions and constants:

Private Declare Sub ReleaseCapture Lib "user32" ()
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
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2

Now I choose any control with a MouseMove event to act as my drag-point. I chose my titlebar label, you may choose your form:

Private Sub lblHeader_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'insert code
End Sub

Here's the code:

If Button = 1 Then
ReleaseCapture
SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End If

Button = 1 will make sure the left button is pressed. ReleaseCapture will release the mouse's capture, and SendMessage will send a message to the window to let it know it needs to be dragged. If you want to be able to drag with either button, say "If Button > 0 Then". Also, I change my cursor to show a user that you can drag (lblHeader.MousePointer = 15)

Example: Pre-release DNS Lookup v2.0

Well that does it! You're well on your way to making fancy shmancy forms. Next time I will tell you how to shape your forms into circles or rounded corners or any shape you want!


Domain Registration, Hosting, Management
http://www.dollardns.net
Top
Sponsored Links
#17771 - 03/13/02 06:25 PM Re: Tips & Tricks - How to make fancy shmancy forms (Part 1)
Joined: Mar 2002
Posts: 143
olosoft Offline
Member
olosoft Offline
Member

Joined: Mar 2002
Posts: 143
.
also, heres a simple way of creating custom graphical buttons.

ok, first of all you have to create the images. you need three images for each button: a normal state, hover state, and down state.

once youve create the images open up your project in vb. i always create one form that just holds all the images in one spot for organizations, say, call it frmImages. open that form up and create an Image. for our example well call it imgOK. set that Picture property to your buttons Normal state. now, copy and paste that Image, when it asks you if you wanna create a control array, say yes. the new image should be called imgOK(1). now set the picture to the Hover state. and copy, paste, and set imgOK(2) to the Down state.

aight, go back to your form where you want the button. create an image, well call it cmdOK. set the default picture to the Norm state. now add this code:

Private Sub cmdOK_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
cmdOK = frmImages.imgOK(2)
End Sub

Private Sub cmd_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not Button = 1 Then
cmdOK = frmImages.imgOK(1)
End If
End Sub

and in the Form_MouseMove add cmdOK = frmImages.imgOK(0)

oh, and you might also wanna add the actualy button's code to the cmdOK_Click event.

example: http://olosoft.topcities.com/suite/Calculator.exe 24kb

example code: http://olosoft.topcities.com/suite/Calculator.zip 22kb

Top
#17772 - 03/13/02 06:29 PM Re: Tips & Tricks - How to make fancy shmancy forms (Part 1)
Joined: Mar 2002
Posts: 143
olosoft Offline
Member
olosoft Offline
Member

Joined: Mar 2002
Posts: 143
.
err, yea, those links dont work, copy them into like Download Accelertor plus, or go to olosoft.topcities.com and then type those links in... god**** free host

Top
#17773 - 03/13/02 07:39 PM Re: Tips & Tricks - How to make fancy shmancy forms (Part 1)
Joined: Feb 2002
Posts: 7,194
Gremelin Offline
Community Owner
Gremelin Offline

Community Owner

Joined: Feb 2002
Posts: 7,194
Portland, OR; USA
good boy ::rubs yoru head::


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
Top
#17774 - 03/13/02 07:43 PM Re: Tips & Tricks - How to make fancy shmancy forms (Part 1)
Joined: Mar 2002
Posts: 256
ninjaneo Offline
UGN Security Staff
ninjaneo Offline
UGN Security Staff

Joined: Mar 2002
Posts: 256
CA, USA
Heh, I guess that means me to hey SR?...

Umm... I could show you guys how to make rounf forms.. If you want to know go ahead ans ask me. :rolleyes:

Top
#17775 - 03/13/02 09:01 PM Re: Tips & Tricks - How to make fancy shmancy forms (Part 1)
Joined: Mar 2002
Posts: 143
olosoft Offline
Member
olosoft Offline
Member

Joined: Mar 2002
Posts: 143
.
sure, tell us how to make rounf forms
/me isnt a big fan of that whole BitBlt thing tho...

Top
#17776 - 03/14/02 09:37 AM Re: Tips & Tricks - How to make fancy shmancy forms (Part 1)
Joined: Mar 2002
Posts: 6
GeneX Offline
Junior Member
GeneX Offline
Junior Member

Joined: Mar 2002
Posts: 6
Sample to make round form (put this behind form):
---------------------------------------------
Private Declare Function CreateEllipticRgn Lib "gdi32" _
(ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, _
ByVal Y2 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 Sub Form_Load()
SetWindowRgn hWnd, CreateEllipticRgn(0, 0, Form1.Width * 15, Form1.Heigth * 15), True
End Sub

Top
#17777 - 03/15/02 06:20 PM Re: Tips & Tricks - How to make fancy shmancy forms (Part 1)
Joined: Mar 2002
Posts: 256
ninjaneo Offline
UGN Security Staff
ninjaneo Offline
UGN Security Staff

Joined: Mar 2002
Posts: 256
CA, USA
Well, I guess that would work my way was a little bit different and you could control roundness of corners and hiegth / width of forum... :rolleyes:

Top
#17778 - 04/08/03 08:06 AM Re: Tips & Tricks - How to make fancy shmancy forms (Part 1)
Joined: Apr 2003
Posts: 27
nomel Offline
Junior Member
nomel Offline
Junior Member

Joined: Apr 2003
Posts: 27
CA, USA
Fancy Buttons!

You can make nice buttons with labels.
Just set the border option to single and do the normal name_click() function for it. Makes nice little flat buttons.

I like making everything Flat instead of 3D too...


Written using the Dvorak keyboard layout.
Top
#17779 - 04/08/03 12:40 PM Re: Tips & Tricks - How to make fancy shmancy forms (Part 1)
Joined: Mar 2002
Posts: 1,273
SilentRage Offline
DollarDNS Owner
SilentRage Offline
DollarDNS Owner

Joined: Mar 2002
Posts: 1,273
OH, USA
I have fixed the link in the first post to the example form. of course, now DNS Lookup v2 is no longer pre release.


Domain Registration, Hosting, Management
http://www.dollardns.net
Top
#17780 - 04/08/03 07:15 PM Re: Tips & Tricks - How to make fancy shmancy forms (Part 1)
Joined: Mar 2002
Posts: 599
BackSlash Offline
UGN's Resident Homo
BackSlash Offline
UGN's Resident Homo

Joined: Mar 2002
Posts: 599
TN
i think you could make the form draggable without api if you did the following....
Code:
Dim lastx, lasty

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
lastx = X
lasty = Y
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Form1.Left = Form1.Left + (X - lastx)
Form1.Top = Form1.Top + (Y - lasty)
End If
End Sub  
you could put that code for a label instead of the form to drag the form with the title bar.


"It's better to burn out, than to fade away."
Top
#17781 - 04/08/03 09:37 PM Re: Tips & Tricks - How to make fancy shmancy forms (Part 1)
Joined: Mar 2002
Posts: 1,273
SilentRage Offline
DollarDNS Owner
SilentRage Offline
DollarDNS Owner

Joined: Mar 2002
Posts: 1,273
OH, USA
yes, but that requires more code than the API technique. And besides, why reinvent the wheel? Just use technology already in place. It's more efficient.


Domain Registration, Hosting, Management
http://www.dollardns.net
Top

Member Spotlight
Gremelin

Gremelin
Portland, OR; USA
Posts: 7,194
Joined: February 2002
Show All Member Profiles 
Forum Statistics
Forums46
Topics43,856
Posts79,030
Members2,157
Most Online1,567
Apr 25th, 2010
Top Posters(All Time)
UGN Security 37,019
Gremelin 7,194
§intå× 3,255
SilentRage 1,273
Ice 1,146
pergesu 1,136
Infinite 1,041
jonconley 955
Girlie 908
unreal 860
Newest Members
Herbert_Sherbert, codemauve, Lillysdragon1984, Brewwit, boa
2157 Registered Users
Who's Online Now
0 registered members (), 1 guest and 0 spiders.
Latest News