Solved

Circular Command Button

Posted on 2001-06-28
17
203 Views
Last Modified: 2008-02-01
I have the need to make a round command button.  I have the image of the 'UP' or un-pressed state and the 'DOWN' or pressed state.  I've tried using the standard command button using the graphical style, however I don't want to see the square button itself.  I've also tried using picture and image boxes, and changing the picture on the mouse_down and mouse_up events. This works better, but once again it shows me the square outline of the box.  This technique would be ok if I could somehow set a transparency coler key for the image box (so that only the circle button is painted), however I can not think of any way of doing this.  Does anyone have any ideas on how I can do this.  I prefer using win32 API's as I am going to be porting the entire project to C++ once the proof of concept is complete.
0
Comment
Question by:rknepp
  • 8
  • 6
  • 2
  • +1
17 Comments
 
LVL 3

Expert Comment

by:Maxim10553
ID: 6234947
try using the image control. you should be able to change the picture on the mouse events and no annoying outlines.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6235028
i don't know if you've tried this already but try playing around with something like this:

use the graphical style for the button and put image on it

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 Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As _
Long) As Long


Private Sub Form_Load()
   Dim fwidth As Long, fheight As Long
   Dim rval As Long, nhwnd As Long
   
   fwidth = Command1.Width / Screen.TwipsPerPixelX
   fheight = Command1.Height / Screen.TwipsPerPixelY
   
   'Create Elliptic Region
   'nhwnd = CreateEllipticRgn(0, 0, fwidth, fheight)
   'Create Circular Region
   nhwnd = CreateEllipticRgn(0, _
               0, fheight, fheight)
   'Set Created Elliptic Region on form
   rval = SetWindowRgn(Command1.hWnd, nhwnd, True)
   rval = DeleteObject(nhwnd)

End Sub

you'll just have to adjust the x1, y1, x2, y2 coordinates of the circle to make it look right.

good luck!
0
 
LVL 11

Expert Comment

by:Otana
ID: 6235038
Is the background of your up- and down-images transparent?
0
 

Author Comment

by:rknepp
ID: 6235074
The 'UP' and 'DOWN' states of the images are transparent in PaintShopPro however they don't seems to be that way when I put them in the image control.  Do I have to use a specific image type (GIF instead of BMP)?  I have thought of using the 'SetWindowRgn' API call, but haven't tried it yet.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6235083
have you also tried using gifs with transparent backgrounds and the image control and then code something like this?

Private Sub Form_Load()

    Image1.Visible = True
    Image2.Visible = False

End Sub

Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   Image1.Visible = False
   Image2.Visible = True
End Sub

Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
   Image2.Visible = False
   Image1.Visible = True
End Sub
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6235086
yeah, use gif to make transparent
0
 

Author Comment

by:rknepp
ID: 6235107
The 'UP' and 'DOWN' states of the images are transparent in PaintShopPro however they don't seems to be that way when I put them in the image control.  Do I have to use a specific image type (GIF instead of BMP)?  I have thought of using the 'SetWindowRgn' API call, but haven't tried it yet.
0
 

Author Comment

by:rknepp
ID: 6235119
Also, I don't want any focus rectangle around the button once it's been click (plus it won't have tabstop).
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:rknepp
ID: 6235123
Also, I don't want any focus rectangle around the button once it's been click (plus it won't have tabstop).
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 300 total points
ID: 6235127
they won't be there if you use the image control as stated above... at least they aren't there for me.
0
 
LVL 3

Expert Comment

by:Maxim10553
ID: 6235131
did you try using the image control rknepp or are you just avoiding it?
0
 

Author Comment

by:rknepp
ID: 6235140
The above code snippets really helped! Although the line:

nhwnd = CreateEllipticRgn(0, _
              0, fheight, fheight)

should read as follows:

nhwnd = CreateEllipticRgn(0, _
              0, fwidth, fheight)

hehehe :-)

Only problem is that it gives the focus rectangle.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6235162
so you do not want to use the image control? it's easier.
0
 

Author Comment

by:rknepp
ID: 6235168
I am going to try the Image control... I just need some time to make the GIF and it's tranparency...
0
 

Author Comment

by:rknepp
ID: 6235189
Well, how about that! All I really needed was the transparent GIF using the image control, NOT the picture control!
0
 

Author Comment

by:rknepp
ID: 6235200
Now that was quick service!
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6235240
glad to help!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Macro which automatically sends attachment to Outlook 14 61
bit defender blocks good applications 2 81
Put text in a picture ASP.NET C# 2 50
vb6 connector to mongodb 2 48
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now