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

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

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
ToolStripCheckBox-VBForums
Results 1 to 18 of 18

Thread: ToolStripCheckBox

  1. #1

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,277

    ToolStripCheckBox

    I've recently wanted a CheckBox in a ToolStrip and while that control doesn't exist in the framework, I did some googling and made my own:
    Code:
    Imports System.Windows.Forms.Design
    
    <ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip), DebuggerStepThrough()> _
    Public Class ToolStripCheckBox
        Inherits ToolStripControlHost
    
        Public Sub New()
            MyBase.New(New System.Windows.Forms.CheckBox())
            ToolStripCheckBoxControl.BackColor = Color.Transparent
        End Sub
    
        Public ReadOnly Property ToolStripCheckBoxControl() As CheckBox
            Get
                Return TryCast(Control, CheckBox)
            End Get
        End Property
    
        Public Property ToolStripCheckBoxEnabled() As Boolean
            Get
                Return ToolStripCheckBoxControl.Enabled
            End Get
            Set(ByVal value As Boolean)
                ToolStripCheckBoxControl.Enabled = value
            End Set
        End Property
    
        Public Property Checked() As Boolean
            Get
                Return ToolStripCheckBoxControl.Checked
            End Get
            Set(ByVal value As Boolean)
                ToolStripCheckBoxControl.Checked = value
            End Set
        End Property
    
        Protected Overrides Sub OnSubscribeControlEvents(ByVal c As Control)
            MyBase.OnSubscribeControlEvents(c)
            AddHandler DirectCast(c, CheckBox).CheckedChanged, AddressOf OnCheckedChanged
        End Sub
    
        Protected Overrides Sub OnUnsubscribeControlEvents(ByVal c As Control)
            MyBase.OnUnsubscribeControlEvents(c)
            RemoveHandler DirectCast(c, CheckBox).CheckedChanged, AddressOf OnCheckedChanged
        End Sub
    
        Public Event CheckedChanged As EventHandler
    
        Private Sub OnCheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
            RaiseEvent CheckedChanged(Me, e)
        End Sub
    End Class
    Just add that code to your project , build it then simply click the AddItem DropDown arrow on a ToolStrip and at the bottom, there it is.

    Here's a screenshot of it being used:
    Name:  ToolStripCheckBoxExample.png
Views: 3192
Size:  75.5 KB

    I've also included a class file as well as an example project for this.
    Attached Files Attached Files
    Last edited by JuggaloBrotha; Jul 25th, 2012 at 08:10 AM.

  2. #2
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Re: ToolStripCheckBox

    Nice! I'm going to test it out as soon as I get a chance. This definitely seems useful
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  3. #3

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,277

    Re: ToolStripCheckBox

    I modified the code so the internal checkbox's backcolor is transparent, allows the toolstrip's gradient backcolor to show through the text

  4. #4
    New Member
    Join Date
    Jul 2012
    Posts
    4

    Re: ToolStripCheckBox

    I am messing with a control like this for the first time. This code provided where would you put this? In a new Class or an existing class?

  5. #5
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Re: ToolStripCheckBox

    Quote Originally Posted by The_Virus_TCH View Post
    I am messing with a control like this for the first time. This code provided where would you put this? In a new Class or an existing class?
    It's a control. So you can either create a control and paste in this code or just create a new class.

    If you look at the code, it's a class. So you can't really put it in another class:

    VB.NET Code:
    1. Public Class ToolStripCheckBox
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  6. #6
    New Member
    Join Date
    Jul 2012
    Posts
    4

    Re: ToolStripCheckBox

    Yea i knew it was a coded as a class. I guess my issue is once i add it to a new class I cannot figure out how to get it into my ToolStrip.

    I read about adding it to the construct of the toolstrip, but I have never done this before. I go into the Designer of the Form but it throughs any when attempting this. Sorry I have dome a lot of things with code before just never tried building a control like this before.
    Last edited by The_Virus_TCH; Jul 24th, 2012 at 07:36 PM.

  7. #7
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Re: ToolStripCheckBox

    Quote Originally Posted by The_Virus_TCH View Post
    Yea i knew it was a coded as a class. I guess my issue is once i add it to a new class I cannot figure out how to get it into my ToolStrip. I read about adding it to the construct of the toolstrip, but I have never done this before. I go into the Designer of the Form but it throughs any when attempting this. SOrry I have dome a lot of things with code before just never tried building a control like this before.
    The point I was making was that you can't put a class in a class.

    There's nothing you need to do. Create the class, build the project, add the toolstrip to the form, and add the checkbox like you would any other native child control.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  8. #8
    New Member
    Join Date
    Jul 2012
    Posts
    4

    Re: ToolStripCheckBox

    This is the error i get

    Constructor on type 'System.Windows.Forms.ToolStripControlHost' not found.

  9. #9
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Re: ToolStripCheckBox

    Quote Originally Posted by The_Virus_TCH View Post
    This is the error i get

    Constructor on type 'System.Windows.Forms.ToolStripControlHost' not found.
    C'mon, man. You're not even trying. I'm not going to do this for you. Hover over the error.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  10. #10
    New Member
    Join Date
    Jul 2012
    Posts
    4

    Re: ToolStripCheckBox

    I am a MORON sorry about that was trying to work from home and my 4 year old had me milti-tasking. Thanks for your help.

  11. #11

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,277

    Re: ToolStripCheckBox

    Quote Originally Posted by weirddemon View Post
    The point I was making was that you can't put a class in a class.

    There's nothing you need to do. Create the class, build the project, add the toolstrip to the form, and add the checkbox like you would any other native child control.
    Actually you can:
    vb Code:
    1. Public Class OutterClass
    2.  
    3.   Private m_InnerClass As InnerClass
    4.  
    5.   Public Sub New()
    6.     m_InnerClass = New InnerClass
    7.   End Sub
    8.  
    9.   Private Class InnerClass
    10.     Public Sub New()
    11.     End Sub
    12.   End Clas
    13.  
    14. End Class

    Quote Originally Posted by The_Virus_TCH View Post
    This is the error i get

    Constructor on type 'System.Windows.Forms.ToolStripControlHost' not found.
    See post #1, I've included an example project, the control as a class file & a screenshot for ya.

  12. #12
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Re: ToolStripCheckBox

    Quote Originally Posted by JuggaloBrotha View Post
    Actually you can:
    vb Code:
    1. Public Class OutterClass
    2.  
    3.   Private m_InnerClass As InnerClass
    4.  
    5.   Public Sub New()
    6.     m_InnerClass = New InnerClass
    7.   End Sub
    8.  
    9.   Private Class InnerClass
    10.     Public Sub New()
    11.     End Sub
    12.   End Clas
    13.  
    14. End Class

    See post #1, I've included an example project, the control as a class file & a screenshot for ya.
    Yeah. I don't know what I was thinking. I have classes within classes on several of my projects.

    Maybe the context of the control confused me.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  13. #13
    Addicted Member
    Join Date
    Mar 2013
    Location
    San Francisco, CA
    Posts
    234

    Re: ToolStripCheckBox

    Quote Originally Posted by The_Virus_TCH View Post
    This is the error i get

    Constructor on type 'System.Windows.Forms.ToolStripControlHost' not found.
    Did you ever figure out why this error happens? I can get the ToolStripCheckBox working on my form, and I can use <F7> to look at the code, but the error happens when I try to view the Designer (double-click the ToolStripCheckBox.vb class module or <Shift F7>).

  14. #14

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,277

    Re: ToolStripCheckBox

    Quote Originally Posted by Mark@SF View Post
    Did you ever figure out why this error happens? I can get the ToolStripCheckBox working on my form, and I can use <F7> to look at the code, but the error happens when I try to view the Designer (double-click the ToolStripCheckBox.vb class module or <Shift F7>).
    This isn't a control you can open in the visual designer as it has to be rendered in a ToolStripControlHost. Right click on it in the solution explorer and click "View Code" to see how it's made.

  15. #15
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    1,848

    Re: ToolStripCheckBox

    Juggalo ... I'm having some issues with this control. I added the class to my project by copying & pasting your code from post #1 above. I add a ToolStrip to my form from the toolbox. I then add a CheckBox to the ToolStrip by picking it from the dropdown & it shows up in the ToolStrip as expected. I then run the project & the form shows on the screen with the CheckBox in the ToolStrip as expected, great. I now close the form & the CheckBox control disappears from the ToolStrip in the designer, along with the dropdown. When I run the project again the CheckBox still shows in the ToolStrip. But back in the designer I cannot see, select or delete the CheckBox or add other controls to the ToolStrip. If I delete the ToolStrip from the form & run the project again the ToolStrip still shows up along with the CheckBox on it. Any idea what's going on? I'd like to use this control, but certainly not with this behavior. Thanks for any help. BTW, I am using VS 2012, 4.0 framework & Windows 8.

  16. #16

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,277

    Re: ToolStripCheckBox

    Quote Originally Posted by nbrege View Post
    Juggalo ... I'm having some issues with this control. I added the class to my project by copying & pasting your code from post #1 above. I add a ToolStrip to my form from the toolbox. I then add a CheckBox to the ToolStrip by picking it from the dropdown & it shows up in the ToolStrip as expected. I then run the project & the form shows on the screen with the CheckBox in the ToolStrip as expected, great. I now close the form & the CheckBox control disappears from the ToolStrip in the designer, along with the dropdown. When I run the project again the CheckBox still shows in the ToolStrip. But back in the designer I cannot see, select or delete the CheckBox or add other controls to the ToolStrip. If I delete the ToolStrip from the form & run the project again the ToolStrip still shows up along with the CheckBox on it. Any idea what's going on? I'd like to use this control, but certainly not with this behavior. Thanks for any help. BTW, I am using VS 2012, 4.0 framework & Windows 8.
    Try closing the form in the designer, then reopening it and everything should appear to be normal.
    I don't have Win8 or VS2012/2013, but using Win7 Ultimate x64 and VS 2010 Ultimate I am unable to reproduce your situation.
    Last edited by JuggaloBrotha; Jan 22nd, 2014 at 10:45 AM.

  17. #17
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    1,848

    Re: ToolStripCheckBox

    Juggalo ... I have revisited this post as I would like to use this control in a project, but I am still having the same issue I described in post #15. Closing the form & reopening it works, but everytime I run the project & then stop it, everything on the ToolStrip disappears again. It's a real pain to have to close & reopen the form designer everytime. Is there anything that can be done to eliminate this issue? I'm running VS2013/Windows 8 64bit. Thanks.

  18. #18

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,277

    Re: ToolStripCheckBox

    Can you zip & upload your project?
    I still don't have Win8 or VS2012/2013, I'm running Win7 Ultimate x64 & VS2010, I'm not able to reproduce your issues at all.

    Probably by the end of this year I'll have Win10 x64 & VS2015 to try it out with.

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