Results 1 to 12 of 12

Thread: Create Class and put new methods/property for a control

  1. #1

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

    Create Class and put new methods/property for a control

    Hi

    How can I to Reference a control inside Class and put new methods, How can I to Call this class and new methods and property ?

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Create Class and put new methods/property for a control

    Sounds like what you want is a user control

  3. #3

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

    Re: Create Class and put new methods/property for a control

    Quote Originally Posted by DataMiser View Post
    Sounds like what you want is a user control
    Sorry, but I do not want to buiild a new user control , only methods and property , The user must put in Reference inside project
    , is only the class , but I do know how can to do It

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Create Class and put new methods/property for a control

    Quote Originally Posted by mutley View Post
    Hi

    How can I to Reference a control inside Class and put new methods, How can I to Call this class and new methods and property ?
    In your Class module you reference a control which will be on some Form (not in the Class module) like this:

    Form1.control where control is a control on Form1. To reference one of it's properties you do this:

    Form1.control.someproperty

    I am assuming you already know how to set up your class

    However, I don't think you are really asking about a class. I think you are asking about a user control and how do you reference the methods and properties of the uc


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Create Class and put new methods/property for a control

    But... you should never ever access a control on a form using the form name from a class module, defeats the purpose of using a class and limits it to only being able to work with that form.

    Instead you should pass the form as a parameter so it will work no matter what the form name is.

    That said if you want to extend a control by adding properties and methods then the simple solution is to create a user control

  6. #6
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: Create Class and put new methods/property for a control

    mutley,

    Can you verify if you are using VB6 and not VB.NET?
    In VB.NET what you are asking about is called inheritance.

    VB6 does not support that directly.

    There are work arounds.

    A user control is one. You would have to map all the existing properties if you want them as well.

    Another option is to create a class that incorporates a variable of the control type and exposes its events with the 'WithEvents' clause.

    You would create a collection of instances of the class in form load attaching the relevant controls in a loop.
    All in all it is a kludge, but it can solve some difficult problems. (I still use it occasionally in VBA.)

    I can dig up a sample if this is what you want.
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

  7. #7

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

    Re: Create Class and put new methods/property for a control

    Quote Originally Posted by Gruff View Post
    mutley,

    Can you verify if you are using VB6 and not VB.NET?
    In VB.NET what you are asking about is called inheritance.

    VB6 does not support that directly.

    There are work arounds.

    A user control is one. You would have to map all the existing properties if you want them as well.

    Another option is to create a class that incorporates a variable of the control type and exposes its events with the 'WithEvents' clause.

    You would create a collection of instances of the class in form load attaching the relevant controls in a loop.
    All in all it is a kludge, but it can solve some difficult problems. (I still use it occasionally in VBA.)

    I can dig up a sample if this is what you want.
    Thank you, I would like !!!

  8. #8
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Create Class and put new methods/property for a control

    Quote Originally Posted by DataMiser View Post
    But... you should never ever access a control on a form using the form name from a class module, defeats the purpose of using a class and limits it to only being able to work with that form.

    Instead you should pass the form as a parameter so it will work no matter what the form name is.

    That said if you want to extend a control by adding properties and methods then the simple solution is to create a user control
    Yes, I know that but that was what I thought he was asking so I showed him even though I knew you should not do that (I give the benefit of doubt to the OP)


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  9. #9
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: Create Class and put new methods/property for a control

    Work-us Interruptus.

    Will get back when I have more time.
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Create Class and put new methods/property for a control

    There is a sort of inside-out way to do this where you write a Class where every method and property accepts a reference to the control to be "twiddled with" as a parameter. It only works well for some sorts of operations and can be very confusing for others to stumble upon in your code if they've never seen it before.

    For example the attached TBX object demo shows such a Class used to implement "extended properties" for VB's intrinsic TextBox control. In this case the goal is to be able to use TextBox controls for huge amounts of text.

    In Form1 of the demo you'll see things like:

    Code:
    MsgBox "Text1 contains " & Format$(TBX.Length(Text1), "#,##0") & " characters"
    ... where Text1 is a VB TextBox. There TBX.Length returns the size of the contents of the TextBox in characters, up to approx. 2 billion at least in theory.
    Attached Files Attached Files

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

    Re: Create Class and put new methods/property for a control

    VB has an Extender object that has many of the typical properties/events of a control
    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. #12
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: Create Class and put new methods/property for a control

    Guess this was what I was thinking of. LINK
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

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
  •  



Click Here to Expand Forum to Full Width