Click here to Skip to main content
15,892,674 members
Home / Discussions / C#
   

C#

 
QuestionC# dynamic controls Pin
Software200731-Dec-10 5:18
Software200731-Dec-10 5:18 
AnswerRe: C# dynamic controls Pin
Interflo31-Dec-10 5:40
Interflo31-Dec-10 5:40 
GeneralRe: C# dynamic controls Pin
Software200731-Dec-10 5:50
Software200731-Dec-10 5:50 
GeneralRe: C# dynamic controls Pin
Henry Minute31-Dec-10 6:09
Henry Minute31-Dec-10 6:09 
GeneralRe: C# dynamic controls Pin
Espen Harlinn1-Jan-11 8:17
professionalEspen Harlinn1-Jan-11 8:17 
GeneralRe: C# dynamic controls Pin
Henry Minute1-Jan-11 8:24
Henry Minute1-Jan-11 8:24 
AnswerRe: C# dynamic controls Pin
Bernhard Hiller2-Jan-11 21:48
Bernhard Hiller2-Jan-11 21:48 
QuestionSubclassing a Checkbox within a ToolStrip Warning Question Pin
Rafone31-Dec-10 4:23
Rafone31-Dec-10 4:23 
I am trying to subclassing a checkbox inside a toolstrip. Works OK but the VS interface does not remember the checkboxs after running the app.
Ran the profiler and got this warning...
Warning 11 CA2000 : Microsoft.Reliability : In method 'ToolStripCheckBox.ToolStripCheckBox()', call System.IDisposable.Dispose on object 'new CheckBox()' before all references to it are out of scope.

So I'm not sure where to place the System.IDisposable.Dispose in my checkbox class. Can someone assist me in this.
Below is the code ...

using System;
using System.Windows.Forms;
using System.Windows.Forms.Design;

[System.ComponentModel.DesignerCategory("code")]
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.ToolStrip)]

public class ToolStripCheckBox : ToolStripControlHost
{
   
    public ToolStripCheckBox() : base(new CheckBox())
    {
        
    }

    public CheckBox CheckBoxControl
    {
        get { return Control as CheckBox; }
    }

    public bool Checked
    {
        get { return CheckBoxControl.Checked; }
        set { CheckBoxControl.Checked = value; }
    }

    public event EventHandler CheckedChanged;

    public void OnCheckedChanged(object sender, EventArgs e)
    {
        // not thread safe!
        if (CheckedChanged != null)
        {
            CheckedChanged(sender, e);
        }
    }

    protected override void OnSubscribeControlEvents(Control control)
    {
        base.OnSubscribeControlEvents(control);
        (control as CheckBox).CheckedChanged += OnCheckedChanged;
    }

    protected override void OnUnsubscribeControlEvents(Control control)
    {
        base.OnUnsubscribeControlEvents(control);
        (control as CheckBox).CheckedChanged -= OnCheckedChanged;
    }
}



tia
Rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...

AnswerRe: Subclassing a Checkbox within a ToolStrip Warning Question Pin
Not Active31-Dec-10 7:15
mentorNot Active31-Dec-10 7:15 
GeneralRe: Subclassing a Checkbox within a ToolStrip Warning Question Pin
Rafone31-Dec-10 10:04
Rafone31-Dec-10 10:04 
GeneralRe: Subclassing a Checkbox within a ToolStrip Warning Question Pin
Not Active31-Dec-10 10:19
mentorNot Active31-Dec-10 10:19 
GeneralRe: Subclassing a Checkbox within a ToolStrip Warning Question Pin
Rafone31-Dec-10 10:54
Rafone31-Dec-10 10:54 
GeneralRe: Subclassing a Checkbox within a ToolStrip Warning Question Pin
Not Active31-Dec-10 13:25
mentorNot Active31-Dec-10 13:25 
GeneralRe: Subclassing a Checkbox within a ToolStrip Warning Question Pin
Rafone31-Dec-10 13:38
Rafone31-Dec-10 13:38 
GeneralRe: Subclassing a Checkbox within a ToolStrip Warning Question Pin
Not Active31-Dec-10 14:42
mentorNot Active31-Dec-10 14:42 
GeneralRe: Subclassing a Checkbox within a ToolStrip Warning Question Pin
Rafone1-Jan-11 4:28
Rafone1-Jan-11 4:28 
GeneralRe: Subclassing a Checkbox within a ToolStrip Warning Question Pin
Not Active1-Jan-11 5:14
mentorNot Active1-Jan-11 5:14 
GeneralRe: Subclassing a Checkbox within a ToolStrip Warning Question Pin
Rafone1-Jan-11 5:37
Rafone1-Jan-11 5:37 
GeneralRe: Subclassing a Checkbox within a ToolStrip Warning Question Pin
Not Active1-Jan-11 6:18
mentorNot Active1-Jan-11 6:18 
GeneralRe: Subclassing a Checkbox within a ToolStrip Warning Question Pin
Rafone1-Jan-11 7:00
Rafone1-Jan-11 7:00 
GeneralRe: Subclassing a Checkbox within a ToolStrip Warning Question Pin
Bernhard Hiller2-Jan-11 22:06
Bernhard Hiller2-Jan-11 22:06 
GeneralRe: Subclassing a Checkbox within a ToolStrip Warning Question Pin
Rafone3-Jan-11 2:41
Rafone3-Jan-11 2:41 
QuestionConverting a unicode value (with a surrogate pair) to a character in C# Pin
vnmatt31-Dec-10 4:03
vnmatt31-Dec-10 4:03 
QuestionRe: Converting a unicode value (with a surrogate pair) to a character in C# Pin
Richard MacCutchan31-Dec-10 4:53
mveRichard MacCutchan31-Dec-10 4:53 
AnswerRe: Converting a unicode value (with a surrogate pair) to a character in C# Pin
vnmatt31-Dec-10 5:06
vnmatt31-Dec-10 5:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.