Creating class and Extend control Properties-VBForums
Results 1 to 8 of 8

Thread: Creating class and Extend control Properties

  1. #1

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    673

    Creating class and Extend control Properties

    Hi

    Somebody have a example how can to create a class and extend properties and events of control (It is not Microsoft), ?

    Is possible to do it for any control , same no microsoft ?

    Tia

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,716

    Re: Creating class and Extend control Properties

    The most common way of extending a control is to use a UserControl. Place the control you want to extend inside the usercontrol, add methods/properties that the control normally uses (which would call the actual methods), then add your own custom methods/properties. Generally, all you need to do at that point is to ensure the that contained control resizes properly to your usercontrol size, i.e., UserControl_Resize event
    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}

  3. #3

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    673

    Re: Creating class and Extend control Properties

    Quote Originally Posted by LaVolpe View Post
    The most common way of extending a control is to use a UserControl. Place the control you want to extend inside the usercontrol, add methods/properties that the control normally uses (which would call the actual methods), then add your own custom methods/properties. Generally, all you need to do at that point is to ensure the that contained control resizes properly to your usercontrol size, i.e., UserControl_Resize event
    Thank you, But is possible to build without to use UserControl ? Declaring Object and to use a Class ?

    Tia

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,716

    Re: Creating class and Extend control Properties

    Sort of, without major hacking of VTables. You can create a class with all the methods you want, including all of the ones on the actual control. You would have one additional method where you pass the class the instance of the control, and that reference is cached in the class. When each method of the class is called, call the actual method on the control that applies and call your own custom methods for those that apply.

    The downside with this approach is that you have to establish this class & control-relationship during runtime, this means you can't easily cache custom properties during design-time. The advantage with the usercontrol is that your custom properties can be assigned and cached during design-time.
    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}

  5. #5

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    673

    Re: Creating class and Extend control Properties

    Quote Originally Posted by LaVolpe View Post
    Sort of, without major hacking of VTables. You can create a class with all the methods you want, including all of the ones on the actual control. You would have one additional method where you pass the class the instance of the control, and that reference is cached in the class. When each method of the class is called, call the actual method on the control that applies and call your own custom methods for those that apply.

    The downside with this approach is that you have to establish this class & control-relationship during runtime, this means you can't easily cache custom properties during design-time. The advantage with the usercontrol is that your custom properties can be assigned and cached during design-time.
    Thank you again

    Do you have a little example ? :-(

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,716

    Re: Creating class and Extend control Properties

    Code:
    ' simple example of maybe trying to extend VB's Picturebox
    
    Private m_Control As VB.PictureBox
    
    ' your custom properties must be declared so they can be cached/retrieved
    Private m_FileName As String
    
    ' Start your standard & custom properties and functions/subs
    Public Property Set AttachControl(theControl As VB.PictureBox) ' called to assign class to control
        Set m_Control = theControl
    End Property
    
    ' sample of existing property
    Public Property Let AutoRedraw(newValue As Boolean)
        m_Control.AutoRedraw = newValue
    End Property
    Public Property Get AutoRedraw() As Boolean
        AutoRedraw = m_Control.AutoRedraw
    End PRoperty
    
    ' sample of custom property
    Public Property Let PictureFileName(newValue As String)
        m_FileName = newValue
        ' take action after property changed
    End Property
    Public Property Get PictureFileName() As String
        PictureFileName = m_FileName
    End Property
    
    Private Sub Class_Terminate
        Set m_Control = Nothing
    End Sub
    Now there is a legitimate way of extending any control if you can gain access to the TLB of the control. The idea is to create a new interface that implements the actual control's interface. Theoretically, this new TLB can be used during runtime in a statement similar to the following after declaring the interface:

    Set newInterface = [theControl]

    Now the newInterface can be used to call the control's built-in methods and also your custom methods that are on that new TLB. This falls in the area of TLB design, which I am in no way an expert.
    Last edited by LaVolpe; Jul 15th, 2015 at 11:19 AM.
    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}

  7. #7

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    673

    Re: Creating class and Extend control Properties

    How to use I tried as
    Code:
    Dim frmobjdesenho As objdesenho
    
    Private Sub Form_Activate()
        Set frmobjdesenho.AttachControl  Me.pctfrm
    End Sub

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,716

    Re: Creating class and Extend control Properties

    Code:
     Set frmobjdesenho.AttachControl = Me.pctfrm
    You forgot the equal sign

    If creating class properties or creating usercontrols is new to you. You have a lot of experimenting and playing in your near future.
    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}

Tags for this Thread

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.