PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
How do i make a control that doesnt go on a form?-VBForums
Results 1 to 16 of 16

Thread: How do i make a control that doesnt go on a form?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2016
    Location
    UK
    Posts
    27

    How do i make a control that doesnt go on a form?

    when you add an image list or a timer control they don't appear on the main form, instead they get put into an area beneath the form. How is that done?

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,286

    Re: How do i make a control that doesnt go on a form?

    That's because they are not controls. Did you think to read the documentation for those classes? Doing so for either would have shown you that they both inherit the System.ComponentModel.Component class. That is what makes a type able to be designed. The System.Windows.Forms.Control class, which is the base class for all controls, itself inherits the System.ComponentModel.Component, so a control is a specialised component.

    If you check the Project menu for a Windows Forms project, you'll see that Add Component is one of the primary options. Using that will add a class that inherits Component and provides a design surface as well as code, much like a form. It's just that what you do on the design surface won't be visible in the UI. It's much like the component tray you see at the bottom of the form design window.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,286

    Re: How do i make a control that doesnt go on a form?

    For an example of a component built from scratch, check this out:

    http://www.vbforums.com/showthread.p...rays-in-VB-NET

    In that particular case, I used the Class item template rather than the Component item template and then just added the Inherits line myself. You can do that if you don't intend to use the designer at all. If I had used the Component item template then, just like for a form, there would have been two code files - one for designer and one for user - and the Inherits line would have been in the designer code file.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 2016
    Location
    UK
    Posts
    27

    Re: How do i make a control that doesnt go on a form?

    Very much appreciated info jmcilhinney, thank you. Do you always have to make a person feel bad before you attempt to help them?
    Last edited by LucasCain; Aug 12th, 2018 at 04:13 AM.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,286

    Re: How do i make a control that doesnt go on a form?

    Quote Originally Posted by LucasCain View Post
    Do you always have to make a person feel bad before you attempt to help them?
    My point of view is that if someone hands you the answer every time then that will encourage you to ask the question every time, whereas if someone gives you reason to think about doing what you can for yourself then you're far more likely to do that. I'm absolutely in favour of people using forums - I've asked questions here myself - but only after doing what they can for themselves first. That's not necessarily banging your head against a brick wall for days but reading the documentation is not an onerous task so everyone should be doing that at least. If anyone should be using the Help menu in a software application, it's software developers. I think that learning how to find information for yourself is critical to becoming the best developer you can be. If people are more likely to do that if they want to avoid a caustic remark from me then I'll provide that caustic remark. The best way to avoid those remarks is to do what you can for yourself first and only ask questions here when you can't find what you need or can't understand what you find. There are plenty of such questions on this site that I've replied to without a caustic remark.
    Last edited by jmcilhinney; Aug 12th, 2018 at 07:04 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    21,886

    Re: How do i make a control that doesnt go on a form?

    Quote Originally Posted by jmcilhinney View Post
    My point of view is that if someone hands you the answer every time then that will encourage you to ask the question every time, whereas if someone gives you reason to think about doing what you can for yourself then you're far more likely to do that.
    You're lucky to get a thankyou. I rarely do these days

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Nov 2016
    Location
    UK
    Posts
    27

    Re: How do i make a control that doesnt go on a form?

    Good information is always appreciated.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Nov 2016
    Location
    UK
    Posts
    27

    Re: How do i make a control that doesnt go on a form?

    Quote Originally Posted by jmcilhinney View Post
    My point of view is that if someone hands you the answer every time then that will encourage you to ask the question every time, whereas if someone gives you reason to think about doing what you can for yourself then you're far more likely to do that.
    My point of view is that if i am stuck on something i do not know i have no choice but to ask for help. Its never a happy moment to have to ask about something i don't know, but forums are not just about one person getting an answer. They also act as a repository of useful information open to the public.

    Lets face it if we don't know something we just search for someone who has asked the same question we are asking. If we find a thread that matches our problem we read it. If there's a good answer and the problem is solved and the person who asked the question is not made to feel stupid then we are going to like that site and probably feel comfortable asking for help there if we cant find an answer to anything we get stuck on in the future. For me forums where people give you the answer and then tell you how you could have worked it out for yourself are awesome. If they can do it without making you feel bad for asking the question then that's super awesome and ill be putting that site into my bookmarks toolbar. if its a friendly place then i might even start hanging out there to help others myself.

    jmcilhinney did give me some good info and i appreciate it even though it was slightly caustic but i have to admit i never look forward to having to ask for help here.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Nov 2016
    Location
    UK
    Posts
    27

    Re: How do i make a control that doesnt go on a form?

    Thanks, that worked out justy fine.

    I went to Project in the toolbar menu in visual studio and picked 'add component'

    Then all i had to do was add
    Code:
    Inherits System.ComponentModel.Component
    inside my new class as jmcilhinney did in his example and after clicking 'rebuild solution' my new class showed up in the toolbox menu. when i dragged it onto the form it appeared in the area below the form and not on it. Awesome

    I still don't know what that area is called though lol
    Last edited by LucasCain; Aug 17th, 2018 at 05:28 AM.

  10. #10
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,286

    Re: How do i make a control that doesnt go on a form?

    Quote Originally Posted by LucasCain View Post
    I went to Project in the toolbar menu in visual studio and picked 'add component'

    Then all i had to do was add
    Code:
    Inherits System.ComponentModel.Component
    inside my new class
    Actually, no you didn't. If you had selected 'Add Class' then you would have but if you selected 'Add Component' then you would have got two code files - designer and user - and that line would already be in the designer code file. It's just like when you select 'Add Windows Form' and you don't have to add a line to inherit from the Form class because it's already in the designer code file.
    Quote Originally Posted by LucasCain View Post
    I still don't know what that area is called though lol
    I mentioned that earlier:
    Quote Originally Posted by jmcilhinney View Post
    It's much like the component tray you see at the bottom of the form design window.
    It is literally an instance of the ComponentTray class.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Nov 2016
    Location
    UK
    Posts
    27

    Re: How do i make a control that doesnt go on a form?

    Thanks, I did try that first.

    I hit Add Component, gave it a name, an empty sub that i was going to fill out later and then hit rebuild. It showed up in the toolbox but when i dragged it onto the form i got an error and the new class was removed from the toolbox. Then i added 'Inherits system.ComponentModel.Component' , did a rebuild and this time it dropped down into the the Component Tray.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Nov 2016
    Location
    UK
    Posts
    27

    Re: How do i make a control that doesnt go on a form?

    Thanks, I did try that first.

    sry, double post.

  13. #13
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,286

    Re: How do i make a control that doesnt go on a form?

    That's weird. It sounds like something is broken in your IDE. Try adding a another component the same way, click the Show All Files button at the top of the Solution Explorer, expand your component item and double-click the Designer.vb subitem. That's the designer code file and that should include the Inherits line. Here's what my designer code file looks like without any changes:
    vb.net Code:
    1. Partial Class TestComponent
    2.     Inherits System.ComponentModel.Component
    3.  
    4.     <System.Diagnostics.DebuggerNonUserCode()> _
    5.     Public Sub New(ByVal container As System.ComponentModel.IContainer)
    6.         MyClass.New()
    7.  
    8.         'Required for Windows.Forms Class Composition Designer support
    9.         If (container IsNot Nothing) Then
    10.             container.Add(Me)
    11.         End If
    12.  
    13.     End Sub
    14.  
    15.     <System.Diagnostics.DebuggerNonUserCode()> _
    16.     Public Sub New()
    17.         MyBase.New()
    18.  
    19.         'This call is required by the Component Designer.
    20.         InitializeComponent()
    21.  
    22.     End Sub
    23.  
    24.     'Component overrides dispose to clean up the component list.
    25.     <System.Diagnostics.DebuggerNonUserCode()> _
    26.     Protected Overrides Sub Dispose(ByVal disposing As Boolean)
    27.         Try
    28.             If disposing AndAlso components IsNot Nothing Then
    29.                 components.Dispose()
    30.             End If
    31.         Finally
    32.             MyBase.Dispose(disposing)
    33.         End Try
    34.     End Sub
    35.  
    36.     'Required by the Component Designer
    37.     Private components As System.ComponentModel.IContainer
    38.  
    39.     'NOTE: The following procedure is required by the Component Designer
    40.     'It can be modified using the Component Designer.
    41.     'Do not modify it using the code editor.
    42.     <System.Diagnostics.DebuggerStepThrough()> _
    43.     Private Sub InitializeComponent()
    44.         components = New System.ComponentModel.Container()
    45.     End Sub
    46.  
    47. End Class
    I did just what I described to add a component and, after a build, I was able to add an instance to a form with no issues.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,286

    Re: How do i make a control that doesnt go on a form?

    Quote Originally Posted by LucasCain View Post
    Thanks, I did try that first.

    sry, double post.
    When the forum tells you that you can post again for 29 seconds or whatever, it actually has submitted your post. You can actually see it listed on that page where it tells you to wait. It's been an issue since the site upgrade so you should check before trying to post again.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Nov 2016
    Location
    UK
    Posts
    27

    Re: How do i make a control that doesnt go on a form?

    Yep, your right, that worked ok. Maybe i didnt hit rebuild solution first.

    Easily done, its 11am here and i've been up all night. Your on the other side of the planet so must be late for you. Hows the weather, ive heard its crazy cold there right now?

  16. #16
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,286

    Re: How do i make a control that doesnt go on a form?

    Quote Originally Posted by LucasCain View Post
    Your on the other side of the planet so must be late for you. Hows the weather, ive heard its crazy cold there right now?
    It's only just after 9 PM here right now. We've actually had a fairly mild winter where I am. It's been hovering around 20 Celsius but we had a max of 25 on Wednesday and I was walking home from the station at about 8 PM in just a t-shirt. It would have been "shirt off and skip work for the beach" weather in your part of the world. ;-) Mind you, you've had a fair bit of that this year I think. I'm actually of UK origin and I'm an England cricket fan so I'm relatively aware of the summer weather in England and all the talk has been about how hot and dry it has been and how good that was going to be for India... right up until the Test series actually started and the weather remembered it was England. ;-)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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