Page 3 of 3 FirstFirst 123
Results 81 to 95 of 95

Thread: How to Make nice buttons ?

  1. #81
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to Make nice buttons ?

    When you supply the picbox hWnd to the RegionFromBitmap, you are shaping the picturebox; therefore, the background disappears because it is cut away from the picturebox. The picturebox is no longer a rectangle; this is the key for understanding why you don't get the background color. The region once applied to a window to shape it is no longer yours to play with. Windows owns the region and per MSDN, you are never to reference that region again and are not to delete that region. If you are not setting the region to shape a window, always destroy that region at some point.

    So to draw a border also, you'd call the routine 1 more time and frame the region, a different handle will be returned each time you call that routine. Whether you use AutoRedraw or not is up to you. AutoRedraw will keep the border should you minimize then restore the form or drag another window over your "button"; otherwise, it will be erased and you'll have to draw it again.

    Last but not least, since this is your first time playing with creating GDI objects that need to be destroyed, I'd strongly suggest you spend some time reading my tutorial on Memory Leaks (linked in my signature below). I'd say it is an extremely high probability that you will write leaky code until you become fully aware of how leaks are created and how to prevent them. That tutorial will help.

    As for the order of what you want to do
    1) Shape the window first
    2) Frame the region
    3) Refresh the picturebox as needed
    If you want to get a little more efficient, here's what you can do to call the routine only once
    Code:
    ...
    ' AutoRedraw should be True for this method
    RegionHandle = cRgn.RegionFromBitmap(Picture1.Picture.Handle)
    FrameRgn Picture1.hDC, RegionHandle, hBrush, 1, 1
    SetWindowRgn Picture1.hWnd, RegionHandle, True
    DeleteObject hBrush
    ' don't delete the RegionHandle because you used it to shape the window with SetWindowRgn above
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  2. #82

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: How to Make nice buttons ?

    LaVolpe Thanks a lot for your explications, I will read the mentioned tutorial, am learning lots of things from you, thanks a lot.

    1) Still I don't understand why if i pass the second parameter to 0 to RegionFromBitmap, the picturebox is not shaped and the backgrounds remain ?

    2) I didn't understand why not to do this :
    ' don't delete the RegionHandle because you used it to shape the window with SetWindowRgn above
    I mean if i Called After the SetWindowRgn ,what is wrong with that ?

    vb6 Code:
    1. DeleteObject RegionHandle


    This Code works good

    vb Code:
    1. Private Sub Command2_Click()
    2.  
    3. Dim RegionHandle As Long
    4. Dim cRgn As New clsRegions
    5. hBrush = CreateSolidBrush(vbRed)
    6. Me.BackColor = vbYellow ' just to show the picturebox is indeed shaped
    7.  
    8. ' AutoRedraw should be True for this method
    9. RegionHandle = cRgn.RegionFromBitmap(Picture1.Picture.Handle)
    10. Debug.Print RegionHandle
    11. FrameRgn Picture1.hDC, RegionHandle, hBrush, 1, 1
    12. Picture1.Refresh
    13. SetWindowRgn Picture1.hwnd, RegionHandle, True
    14. DeleteObject hBrush
    15.  
    16. End Sub

  3. #83
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to Make nice buttons ?

    1) It isn't shaped because you didn't pass an hWnd. Passing zero returns the region handle, it doesn't apply the handle to a window because zero was passed. Shaping a window is like taking scissors to it and cutting around the image, excluding the color that is to appear as "transparent"

    2) Reference
    Quote Originally Posted by MSDN
    After a successful call to SetWindowRgn, the system owns the region specified by the region handle hRgn. The system does not make a copy of the region. Thus, you should not make any further function calls with this region handle. In particular, do not delete this region handle. The system deletes the region handle when it no longer needed.
    3) You shouldn't have to call Picture1.Refresh in your sample code. That's what that True parameter in the SetWindowRgn API call is suppose to do
    Last edited by LaVolpe; Nov 21st, 2010 at 12:38 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #84

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: How to Make nice buttons ?

    1) thanks , so calling it with 0, it will just return the handle without shaping it , right ?Thus, if i want to only use this method, i have to call it twice once to shape and once to get the region handle to be able to use it by FrameRgn ,right ?

    2) lol, ok thanks , in fact if i asked this question it's because i tried to delete the handle and no error occured, all worked well, so i said why not to delete it
    but after i see that msdn confirms that they will automatically deleted it, then ok no need let windows do it by its own , i won't help it

  5. #85
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to Make nice buttons ?

    Quote Originally Posted by justgreat View Post
    1) thanks , so calling it with 0, it will just return the handle without shaping it , right ?Thus, if i want to only use this method, i have to call it twice once to shape and once to get the region handle to be able to use it by FrameRgn ,right ?
    Yes. That class was not designed solely to shape windows, but to return regions that could be used for a myriad of other purposes.

    Calling it twice? Depends on whether you use just the class to do the work.
    Either a) call it twice, once to shape the window, once to frame the region & delete handle or b) call it once, frame the region & use same handle in SetWindowRgn call & don't delete handle.

    Edited: Note that the full version of the class (mentioned/linked much earlier in this thread @ post#23) had functions/calls that included about 99.9% of all region-related API calls, including FrameRgn for example. Even if you don't want to use the full version of the class, it can still be a good reference for region-related functions.
    Last edited by LaVolpe; Nov 21st, 2010 at 01:04 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #86

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: How to Make nice buttons ?

    Thanks a lot LaVolpe.

    Is there a way to make nice fonts on the button ? because the fonts i showed above are generated by the website as picture, but now i have to be able to make my own caption to change it depending on the button ?

  7. #87
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to Make nice buttons ?

    You can use whatever fonts your system makes available to you and at whatever size you need. Simply set the usercontrol's Font property to that font and then something like this:
    Code:
    UserControl.CurrentX = someValue
    UserControl.CurrentY = someValue
    UserControl.Print sCaption
    To create fancy fonts where the font interior is filled with color or patterns, then you will want to research paths.

    To use APIs to create fonts and draw text with more advanced options, research DrawText & CreateFontIndirect APIs.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #88

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: How to Make nice buttons ?

    Thank you,

    "research paths"
    ? does this mean search the forum ?


    Yes it seems what i want is what you called fancy fonts(sometimes i don't find the right english words ), like the font used on the picture that i attached above and that i used in my button.

    I will look at pscode for fancy fonts, but didn't get something interesting yet, i will keep searching, if u got any thread about, please let me know.

  9. #89
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to Make nice buttons ?

    "Fancy" is just a word I used. Paths are graphics objects, similar to regions, that can be filled and outlined using APIs. By paths, I'm referring this
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #90

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: How to Make nice buttons ?

    Thanks ,

    I started searching for on pscode and guess what !
    what usually I find that you did already what i want !! You made something called word art HERE !! it's exactly maybe what i want, write something like this on my button !! so if i want to avoid the complicated code in your project what part should i focus on it ?

  11. #91
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to Make nice buttons ?

    Don't recommend jumping to that wordart project. It uses GDI+ and is pretty dang complicated. I'm not supporting the project either. So if you want to use the code therein, use at your own risk. I developed that for self-education purposes.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #92

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: How to Make nice buttons ?

    So what do you suggest me ? simply print a normal caption on the buttons ? or i try to make nice captions by searching for paths ? is it hard to use paths ? or it's simple ?


    Can you check the attached code and tell me if you think it's good to do this effet I used in the attached code the idea you suggested first, to have 3 images (normal, mouse down, hover) and I loaded the 3 images based on the event...using the set property ...

    Plz check (not the code, but the effect) and tell me what do you think ?

    if yes then only thing I still should work on, is the caption
    Attached Files Attached Files

  13. #93

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: How to Make nice buttons ?

    1- Please Can someone Tell me how when I want to write my caption on the picture box button, to specify the size and color of the Caption ?

    2- Is there a way to use an imagecontrol instead of Picture box ? And to be able to write a caption on it ?
    Because I found that the stretch method that has the image control is easiar to make on design time the button size !

    I tried to use the render method of Velop it's stretching the picture, but I can't understand why the stretch of the image control is not exactly the same (maybe it's the ident ?) !

    3)Is there a way when I copy from imagebox to picture box, to make a code that ensure that i have the same stretch and image size as the picture inside the image box ? Thus, i can use the imagebox to strech my image and copy it to use it inside a picture box with beeing sure i have same size, settings, ident etc...

  14. #94

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: How to Make nice buttons ?

    LaVolpe, Is there a way to use your class to make a frame or an option box or such controls transparents ?

  15. #95
    Junior Member
    Join Date
    Dec 2010
    Posts
    23

    Re: How to Make nice buttons ?

    Quote Originally Posted by baja_yu View Post
    Create an image you want to use as a button, then load it into a borderless picturebox and use the pictburebox as a button.

    To get the windows look and feel you can manifest your application to get the XP styles (using regular controls), but the upper method gives you more freedom.

    EDIT: You can do pretty much anything with images. Here's a very old example where I illustrated how to create a custom tab control with images (attachment in post #14) http://www.vbforums.com/showthread.php?t=309279

    EDIT2: In addition, you can create several version of the image like: normal, selected, pressed_down, and use MouseDown event for example to show it pressed down while you hold the mouse then switch back to normal (or to selected) on MouseUp (or Click).
    Thanks this helped me btw.

Page 3 of 3 FirstFirst 123

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