Results 1 to 7 of 7

Thread: Adding a through controls.add?

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    2

    Adding a through controls.add?

    This is what I'm doing:
    Code:
    Dim count As New Timer
    controls.add(count)
    Is there an alternative to this? as VB doesn't seem to like it.

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Adding a through controls.add?

    Look at your question. Do we know what controls is or should we assume something? "VB doesn't seem to like it" doesn't mean much.

    What are you trying to accomplish?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Adding a through controls.add?

    VB doesn't like it at all. Timer is not a control!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Adding a through controls.add?

    A timer is a component rather than a control, and the Controls collection can only accept Controls or things derived from Control. Fortunately, this doesn't matter, as there is no good reason to add a timer to a Controls collection. A timer is not contained within anything, but is just a member variable in the form class itself. Since it has no location, or any of the other features of a control, you wouldn't gain in any way by adding it to a collection.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    2

    Re: Adding a through controls.add?

    Quote Originally Posted by Shaggy Hiker View Post
    A timer is a component rather than a control, and the Controls collection can only accept Controls or things derived from Control. Fortunately, this doesn't matter, as there is no good reason to add a timer to a Controls collection. A timer is not contained within anything, but is just a member variable in the form class itself. Since it has no location, or any of the other features of a control, you wouldn't gain in any way by adding it to a collection.
    Ah, I get it... what was I thinking. Very obvious really.

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Adding a through controls.add?

    Frankly, I've made that mistake, as well. Something on the toolbar, such as a timer and all controls, gets dragged onto the form. In that way, you are interacting with all of them in a similar fashion, so it is fairly automatic to assume that they are all the same animal in some way.
    My usual boring signature: Nothing

  7. #7
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Adding a through controls.add?

    The designer tricks you into believing that a parent/child relationship exists between a Form and a Component like a Timer. Only controls have a true relationship via the Form's control collection but with Timers and such, the designer adds it to an IContainer implementation which is referenced by nothing more than a private field generated by the designer. Any class that implements IComponent and has a public constructor that takes an IContainer will be added to the IContainer implementation referenced by the designer generated private field of the Form.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

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