Results 1 to 38 of 38

Thread: how do I create a rounded button

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    how do I create a rounded button

    Look at the attached image of a button. I want to create the same kind of button rounded button. The part that I am stuck on is how to draw different (3D) borders around the button. It's easy for a simple rectangle but I've no clue how to do that of anything other than a rectangle.
    I am creating a custome button using a picture box. So any code given can use a picture box to draw stuff on it.

    Any idea?
    Attached Images Attached Images  
    Baaaaaaaaah

  2. #2

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Here is an unzoomed view of the button.
    Baaaaaaaaah

  3. #3
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    Are you trying to make a new .OCX for this, or what?
    Not really sure what you need here...
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  4. #4

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Yes, I'm trying to make a new OCX that supports different shapes for a command button
    Baaaaaaaaah

  5. #5
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    Well, I suggest that in the Click/MouseDown events you check the X/Y to see if it hits the button or not - that will enhance the effect of curves, etc.

    But I'm still not really sure where your problem lies. The picture you had looks fine to me...
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  6. #6
    New Member
    Join Date
    Nov 2001
    Location
    Raleigh, NC
    Posts
    4
    Try the attached button. I just flipped 180o on Photoshop and then pasted the label as it was originally.

    Regards,
    Juba
    Attached Images Attached Images  

  7. #7

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    The thing is that the picture attached is not the button created by myself
    I want to create the same button using MY code. The problem is drawing that rouned rectangle around the button. I don't need to work with any mouse interface for now, but I want to create a button that has a 3D border around that. If I create a rectangular button, there is an API called "DrawEdge" that I can use to draw 3D borders but it only works for rectangular buttons. If I have circular, triangular, or rounded button, how would I draw a 3D border? I need to draw some kind of lines of rectangles manually using white colour of the left and top sides edges of the button, and drawing the same kind of lines using gray or black colour on the bottom and right sides of the button. Hopefully, you get the problem now
    Baaaaaaaaah

  8. #8
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    The Dark Side of the Moon
    Posts
    448
    Just a suggestion, not that i know a lot about this kind of thing, but I remember someone making a odd shaped form by using API to drawn it like a polygon. They then created their shape using a jagged shaped polygon (with more than 3 points).

  9. #9
    AIS_DK
    Guest
    Since I already did one of those, I'll help you a little bit.

    Check the API call:
    VB Code:
    1. 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

    It creates a rectangular rounded region, on which you draw a border with the call:
    [Highlight=VB]
    Private Declare Function FrameRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
    [Highlight=VB]

    Last but not least, you change the standard retangular window region of your usercontrol to the newly created region by using:
    VB Code:
    1. Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long

    For more information about using Regions, check either the platform SDK or msdn.microsoft.com

  10. #10

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Originally posted by AIS_DK
    Since I already did one of those, I'll help you a little bit.

    Check the API call:
    VB Code:
    1. 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

    It creates a rectangular rounded region, on which you draw a border with the call:
    [Highlight=VB]
    Private Declare Function FrameRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
    [Highlight=VB]
    Last but not least, you change the standard retangular window region of your usercontrol to the newly created region by using:
    VB Code:
    1. Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long

    For more information about using Regions, check either the platform SDK or msdn.microsoft.com
    Thanks, but I was able to create a rounded region of a picture box. But if you look carefully, the picture boxbecomes totally flat because it cuts off its edges from all 4 sides. Now, how do I draw that 3D rounded border around the regioned picture?
    Baaaaaaaaah

  11. #11
    haravinth
    Guest

    Talking

    I don't have no idea how to make a round button in visual basic.



  12. #12

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Originally posted by haravinth
    I don't have no idea how to make a round button in visual basic.


    Hi dude, you are interviewing with the teacher and I'm seeing this thread on your computer's screen
    Caught you!
    Baaaaaaaaah

  13. #13

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Anybody has any idea how to do that??
    Baaaaaaaaah

  14. #14
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    Abdul..Ive done it..But I used an image. Since an image is clickable and can react to mousedown/up.

    draw to pics. One on the button up...one down.

    add an imagelist to your app.
    put the up and down pics in.

    on load...set the image to the up image of the list...

    on mousedown..set it to the down pic..
    on mouseup...return it to the original.

    then use the click event to run the code.

    works and looks good.


    if you dont like that. Give a Yell to Kedaman. He has done something similar and may be able to help you.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  15. #15
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    I might be totally wrong , but can't you just use bitblt to mask your image and draw a rounded image?

  16. #16
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    You can use that to Draw the button, but what is really needed is to draw the 3d border effects, not a premade picture.
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  17. #17

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Using different pictureboxes to create a rounded button is the easiest way, I think.
    But how about the manual stuff like the button you see on this website:
    www.vbthunder.com (rainbow button)

    geoff_xrx:
    Has Kedaman done that picture switching or the actual rounded button using API?
    Last edited by abdul; Dec 5th, 2001 at 03:38 PM.
    Baaaaaaaaah

  18. #18
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    Keda has created a shape that can be changed which has click events, mouseover and mouseoff events. its call the LCARS control. pretty cool. I am guessing it uses some similar API to what your needing. Drop him an email
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  19. #19

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    I have sent a PM to Kedaman, and now I'm waiting for his answer
    Baaaaaaaaah

  20. #20
    Hyperactive Member TiPeRa's Avatar
    Join Date
    Apr 2001
    Location
    In between
    Posts
    464
    I haven't read all the posts but you might like to try this. Just add a button to the form.
    VB Code:
    1. Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    2. Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    3. Private Sub Command1_Click()
    4.     Dim hRgn As Long
    5.     Form1.BackColor = vbBlue
    6.     hRgn = CreateEllipticRgn(0, 0, Command1.Width, Command1.Height)
    7.     Call SetWindowRgn(Command1.hWnd, hRgn, True)
    8. End Sub
    I hope it helps :-) It will work on anything with a hWnd.
    W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
    (Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)

  21. #21
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    go to www.planet-source-code.com and go to the contest page and it will be like a buttons thing or somethin and it shows you how

  22. #22
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Here is a cheeky alternative:



    A)bort, R)etry, I)nfluence with large hammer:
    Last edited by Nucleus; Dec 6th, 2001 at 05:11 PM.

  23. #23
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    you forgot the form

  24. #24
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Amended the attachment to include the form

  25. #25

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Originally posted by Nucleus
    Amended the attachment to include the form
    There is still no form
    Baaaaaaaaah

  26. #26

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Originally posted by Motoxpro
    go to www.planet-source-code.com and go to the contest page and it will be like a buttons thing or somethin and it shows you how
    Can you please provide the actual link?
    Baaaaaaaaah

  27. #27

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Originally posted by TiPeRa
    I haven't read all the posts but you might like to try this. Just add a button to the form.
    VB Code:
    1. Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    2. Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    3. Private Sub Command1_Click()
    4.     Dim hRgn As Long
    5.     Form1.BackColor = vbBlue
    6.     hRgn = CreateEllipticRgn(0, 0, Command1.Width, Command1.Height)
    7.     Call SetWindowRgn(Command1.hWnd, hRgn, True)
    8. End Sub
    I hope it helps :-) It will work on anything with a hWnd.
    I can create the region (which is the first thing you do if you want to create a button other than rectangular one), but if notice, the button is all flat because creating a region cuts out all the edges so it takes off the 3D border around the button. Now, I want to create a rounded 3D border around the button. How would you go about doing that?
    Baaaaaaaaah

  28. #28
    DaoK
    Guest
    Abdul here some link who you may will like to took a look.

    PSP Link 1
    PSP Link 2
    PSP link 3

  29. #29
    DaoK
    Guest
    Here is an other link who show you how to make VB button who look as XP button very nice interface.

    http://www.planet-source-code.com/xq/ASP/txtCodeId.27437/lngWId.1/qx/vb/scripts/ShowCode.htm

  30. #30
    DaoK
    Guest
    A perfect Round Button : PSP link 5


    Hope all these links will help you.

  31. #31

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    Brilliant search Doak!

    Thanks a lot for link #2, that's exactly what I was looking for
    I'll have to now study the code
    Baaaaaaaaah

  32. #32
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Yo. Why don't you just create your buttons in Photoshop and use a imagebox to display them? Set all the pictures in a imagelist and call the picture for the mouse down and mouse up events.

    You have to set a transparent label on top of the imagebox to allow the user to change caption ect...


    This would be the best way to do it.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  33. #33
    DaoK
    Guest
    He just wants to create his own control OCX are hard to make and can be a good project.

  34. #34

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Originally posted by Arc
    Yo. Why don't you just create your buttons in Photoshop and use a imagebox to display them? Set all the pictures in a imagelist and call the picture for the mouse down and mouse up events.

    You have to set a transparent label on top of the imagebox to allow the user to change caption ect...


    This would be the best way to do it.
    Yes, but what if I wanted to do, let us say, gradiants on that button or some other effects?
    That's why I want to leave the pictures out for this kind of effect.
    Baaaaaaaaah

  35. #35

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Originally posted by DaoK
    He just wants to create his own control OCX are hard to make and can be a good project.
    Actually, this is a part of my big project - a messenger or chat program, in which I want to allow the user to use different skins and lots of other stuff
    Baaaaaaaaah

  36. #36
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    btw, OCX's are very easy to make if you know what you are doing...(IMHO)
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  37. #37

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    I was just looking for some code no matter in which form it was (OCX or just simple code). Now, I will create another OCX out of it that has some more features.
    Baaaaaaaaah

  38. #38
    DaoK
    Guest
    You can make a really big OCX with a lots of feature and it can be hard, I have read the Tutorial on that website and I can not make everything than I have in my head about OCX but I do not worry because I hate adding OCX in my project

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width