|
-
Apr 1st, 2000, 06:42 AM
#1
Thread Starter
Hyperactive Member
Is there a special OCX or can you do this on a normal command button?
I saw a program that uses icons on buttons.
It acts like a normal button but with an icon on it.
But unlike the command buttons icon, This icon always stays on the same spot!
it always stays on the very left side of the button. Can anyone tell me a good way to do this?
-
Apr 1st, 2000, 07:32 AM
#2
Junior Member
Hi,
You can try to build your own CommandButton, so you'll be able to do what you want, without ocx.
There is an example that I often use.
You'll need a PictureBox (size it as you want, it's your button), put an image control in it (on the left side if you want) load your icon in this image control. Then put 4 lines on your form.
'general declarations
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
'In form_load
Line1.X1 = Picture1.Left - 10
Line1.X2 = Picture1.Left + Picture1.Width
Line1.Y1 = Picture1.Top - 10
Line1.Y2 = Line1.Y1
Line2.X1 = Picture1.Left
Line2.X2 = Picture1.Left + Picture1.Width
Line2.Y1 = Picture1.Top + Picture1.Height
Line2.Y2 = Line2.Y1
Line3.X1 = Picture1.Left - 10
Line3.X2 = Line3.X1
Line3.Y1 = Picture1.Top
Line3.Y2 = Picture1.Top + Picture1.Height
Line4.X1 = Picture1.Left + Picture1.Width
Line4.X2 = Line6.X1
Line4.Y1 = Picture1.Top
Line4.Y2 = Picture1.Top + Picture1.Height + 10
Line1.BorderColor = &HE0E0E0
Line2.BorderColor = &H808080
Line3.BorderColor = &HE0E0E0
Line4.BorderColor = &H808080
'The caption of your button
msg = "ClickHere"
Picture1.FontSize = 8
HalfWidth = Picture1.TextWidth(msg) / 2 - 90
HalfHeight = Picture1.TextHeight(msg) / 2
Picture1.CurrentX = Picture1.ScaleWidth / 2 - HalfWidth
Picture1.CurrentY = Picture1.ScaleHeight / 2 - HalfHeight
Picture1.Print msg
'Picture1 mouse_down
Line1.BorderColor = &H808080
Line2.BorderColor = &HE0E0E0
Line3.BorderColor = &H808080
Line4.BorderColor = &HE0E0E0
'Picture1 mouse_up
Line1.BorderColor = &HE0E0E0
Line2.BorderColor = &H808080
Line3.BorderColor = &HE0E0E0
Line4.BorderColor = &H808080
'Picture1 mouse_move (to hilite the caption in blue when
'mouse is over the button)
Dim MouseEnter As Boolean
Dim HalfWidth, HalfHeight, msg
MouseEnter = (0 <= X) And (X <= Picture1.Width) And (0 <= Y) And (Y <= Picture1.Height)
If MouseEnter Then
Picture1.ForeColor = &HFF0000
Picture1.Cls
msg = "ClickHere"
Picture1.FontSize = 8
HalfWidth = Picture1.TextWidth(msg) / 2 - 90
HalfHeight = Picture1.TextHeight(msg) / 2
Picture1.CurrentX = Picture1.ScaleWidth / 2 - HalfWidth
Picture1.CurrentY = Picture1.ScaleHeight / 2 - HalfHeight
Picture1.Print msg
SetCapture Picture1.hwnd
Else
Picture1.ForeColor = &H80000012
Picture1.Cls
msg = "ClickHere"
Picture1.FontSize = 8
HalfWidth = Picture1.TextWidth(msg) / 2 - 90
HalfHeight = Picture1.TextHeight(msg) / 2
Picture1.CurrentX = Picture1.ScaleWidth / 2 - HalfWidth
Picture1.CurrentY = Picture1.ScaleHeight / 2 - HalfHeight
Picture1.Print msg
Line1.BorderColor = &HE0E0E0
Line2.BorderColor = &H808080
Line3.BorderColor = &HE0E0E0
Line4.BorderColor = &H808080
ReleaseCapture
End If
You can of course change some settings depending on the size of your icon (here 16x16), fonts...
Claude.
[Edited by Claudi on 04-01-2000 at 07:35 PM]
-
Apr 1st, 2000, 07:35 AM
#3
Frenzied Member
Open a paint program and open a new bitmap the same size as your command button. Cut and paste your icon onto it form another instance of paint where you wan't it on the command button and put your text on the picture too. Save this
Then set your buttons style property to graphical and double click on your picture box.
From the file browser select your bitmap file and voila.
NB if you set your buttons scalemode property to pixels you can read of it's size in pixels from the scaleheight and scalewidth properties, then change it back to twips.
Hope this helps
-
Apr 1st, 2000, 07:50 AM
#4
Thread Starter
Hyperactive Member
Yes. This is a way but i didn't tell it in detail. Sorry.
I want to use Icon files, And an image list.
I have icons in the image list.
I want people to be able to change the Command Buttons IMAGE with something in the image list. And i want them to be able to change the text around.
This may be harder... Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|