[VB6] Template: Custom Button-VBForums
Results 1 to 7 of 7

Thread: [VB6] Template: Custom Button

  1. #1

    Thread Starter
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    12,625

    [VB6] Template: Custom Button

    The CustomButton template is just that: a template. It was designed to replicate a VB button's actions, it does not include usable code to draw the caption, icons, or anything else related to the display of the button. Some drawing code is provided for example purposes only. Why? These routines cannot be easily provided in a template because some users may want captions aligned one way or the other, support unicode or not, allow caption-less/image-only buttons, and a myriad of other scenarios. The button's display is your responsibility, the button's actions are mine.

    I think that if you want to create your own custom button, this template is a perfect starting point. It does all the hard work of making the button responsive to the user and to the coder. I have attempted to replicate the VB button's actions exactly and believe I have done it 100%, or at least 99.9%. Events are fired in the same order as VB's button, overridable event parameters are supported same as VB's button, and in the case of MouseEnter/MouseLeave events, I used my own logic since VB buttons don't provide these.

    There are 2 CustomButton templates. The one with the project has minimal drawing routines added to it so that it can be used with the sample project and is for the sample project only. It is derived from the raw template. The other, in the ResuableTemplate folder, is the raw template.

    You can even add the raw template (.ctl file) to your VB templates folder [C:\Program Files\Microsoft Visual Studio\VB98\Template\Userctls]. And it will appear when you opt to Add|User Control from your project tree/explorer.

    Edited: Error noted by PatVB. When usercontrol is used to unload a form it is on by clicking the control, an error stating that the control is no longer sited occurs. This is happening because the mouse up of the click event is trying to send the form a MouseUp event. But since the control is "unloaded", the error occurs. The patch is simple:
    1. As the first line of the UserControl_MouseUp event, add: On Error GoTo EH
    2. As the very last line in the same event, add: EH:
    Attached Files Attached Files
    Last edited by LaVolpe; Apr 22nd, 2010 at 03:26 PM.
    Insomnia is just a byproduct of, "It can't be done"

    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} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  2. #2
    Member
    Join Date
    Sep 2008
    Location
    Turkey
    Posts
    37

    Thumbs up Re: [VB6] Template: Custom Button

    Quote Originally Posted by LaVolpe
    The CustomButton template is just that: a template. It was designed to replicate a VB button's actions, it does not include usable code to draw the caption, icons, or anything else related to the display of the button. Some drawing code is provided for example purposes only. Why? These routines cannot be easily provided in a template because some users may want captions aligned one way or the other, support unicode or not, allow caption-less/image-only buttons, and a myriad of other scenarios. The button's display is your responsibility, the button's actions are mine.

    I think that if you want to create your own custom button, this template is a perfect starting point. It does all the hard work of making the button responsive to the user and to the coder. I have attempted to replicate the VB button's actions exactly and believe I have done it 100%, or at least 99.9%. Events are fired in the same order as VB's button, overridable event parameters are supported same as VB's button, and in the case of MouseEnter/MouseLeave events, I used my own logic since VB buttons don't provide these.

    There are 2 CustomButton templates. The one with the project has minimal drawing routines added to it so that it can be used with the sample project and is for the sample project only. It is derived from the raw template. The other, in the ResuableTemplate folder, is the raw template.

    You can even add the raw template (.ctl file) to your VB templates folder [C:\Program Files\Microsoft Visual Studio\VB98\Template\Userctls]. And it will appear when you opt to Add|User Control from your project tree/explorer.
    Thanks.And very Difficult :\

  3. #3
    Addicted Member
    Join Date
    Oct 2002
    Location
    Connecticut
    Posts
    135

    Angry Re: [VB6] Template: Custom Button

    I am trying to modify the Ctrl to add a Bitmap picture on it. When I run it, Igert this error message: "Line 9: Property Picture in CustomButton had an invalid file reference.". I am sure that I'm doing something wrong...any ideas

    Thanks

  4. #4

    Thread Starter
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    12,625

    Re: [VB6] Template: Custom Button

    Well, let's see the code you added/changed.
    Insomnia is just a byproduct of, "It can't be done"

    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} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5
    Addicted Member
    Join Date
    Oct 2002
    Location
    Connecticut
    Posts
    135

    Re: [VB6] Template: Custom Button

    Lavolpe,

    I reload the program without the error. But I am stuck trying to put another skin on the Ctrl.
    The problem is, I set the picture property of the template to a bitmap and size it accordingly. When I run the test program, the bitmap is showing on a corner of the ctrl as oppose to over the whole ctrl....Any ideas

    Thanks for your reply....I am under the gun trying to put a skin on a CommandButton control.

  6. #6
    Addicted Member
    Join Date
    Oct 2002
    Location
    Connecticut
    Posts
    135

    Re: [VB6] Template: Custom Button

    I am trying to use

    Private Sub UserControl_Resize()
    ? = UserControl.Width
    ?= UserControl.Height
    End Sub

  7. #7

    Thread Starter
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    12,625

    Re: [VB6] Template: Custom Button

    Set the control's AutoRedraw to True. Use PaintPicture to stretch the image to the control's dimensions. Please post additional questions in the VB6 forum as it appears you do not have a specific issue with the control's functionality; but rather with VB in general.

    If you do post in the VB6 forum, be sure to give plenty of details and some sample code of what you are trying to do.
    Insomnia is just a byproduct of, "It can't be done"

    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} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.