Subclassing a Checkbox within a ToolStrip Warning Question
-
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 ...
-
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 ...
Implement the Disposable pattern
I know the language. I've read a book. - _Madmatt
-
Implement the Disposable pattern
I know the language. I've read a book. - _Madmatt
-
Thanks for the Info Mark...based on the error text I gathered that this is what I am supposed to do. If I knew how I wouldn't have had to ask... rafone
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
Ever heard of GOOGLE :rolleyes:
I know the language. I've read a book. - _Madmatt
-
Ever heard of GOOGLE :rolleyes:
I know the language. I've read a book. - _Madmatt
Yea as a matter of fact I have read 17 articles before posting and about 25 since posting. I guess I'm just not as good at understanding it as you are! rafone
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
-
Yea as a matter of fact I have read 17 articles before posting and about 25 since posting. I guess I'm just not as good at understanding it as you are! rafone
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
Rafone wrote:
I have read 17 articles before posting and about 25 since posting
Absolutely pathetic. :rolleyes: In all of your searching you couldn't even find this: Implementing Finalize and Dispose[^] Hell even here the first five of 140,000 hits show exact code to implement it. Disposal Pattern .NET[^] You will never get any where in this field by feigning such ignorance and having others do the work for you.
I know the language. I've read a book. - _Madmatt
-
Rafone wrote:
I have read 17 articles before posting and about 25 since posting
Absolutely pathetic. :rolleyes: In all of your searching you couldn't even find this: Implementing Finalize and Dispose[^] Hell even here the first five of 140,000 hits show exact code to implement it. Disposal Pattern .NET[^] You will never get any where in this field by feigning such ignorance and having others do the work for you.
I know the language. I've read a book. - _Madmatt
Yes found and read both of those you sight. As I said before finding articles to read is not the problem understanding them is.... I guess if you understood then you would have been helping me to understand instead of pointing me in the direction I had already taken. thanks for your time though... rafone
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
-
Yes found and read both of those you sight. As I said before finding articles to read is not the problem understanding them is.... I guess if you understood then you would have been helping me to understand instead of pointing me in the direction I had already taken. thanks for your time though... rafone
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
Rafone wrote:
I guess if you understood then you would have been helping me
The links present you with clear, concise and full implementations of this pattern. Perhaps you should state clearly what part of it you don't understand rather than down voting.
I know the language. I've read a book. - _Madmatt
-
Rafone wrote:
I guess if you understood then you would have been helping me
The links present you with clear, concise and full implementations of this pattern. Perhaps you should state clearly what part of it you don't understand rather than down voting.
I know the language. I've read a book. - _Madmatt
It appears this is a bug in VS2010 I am seeing a CA200 Warning (call Dispose) on a variable declared within a using statement. Type: Bug ID: 521027 Opened: 12/17/2009 2:10:58 PM Access Restriction: Public 0 Workaround(s) 7 User(s) can reproduce this bug
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
-
It appears this is a bug in VS2010 I am seeing a CA200 Warning (call Dispose) on a variable declared within a using statement. Type: Bug ID: 521027 Opened: 12/17/2009 2:10:58 PM Access Restriction: Public 0 Workaround(s) 7 User(s) can reproduce this bug
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
First you can't understand the code, now you think it is a bug. Do you understand the code now?
I know the language. I've read a book. - _Madmatt
-
First you can't understand the code, now you think it is a bug. Do you understand the code now?
I know the language. I've read a book. - _Madmatt
It was the warning I was trying to understand....After searching and reading post after post I did find that error report on Microsoft Connect. I thought becase the Form was disposing all components including the hosted toolstrip (that I provided code for) that it was being disposed. According to the bug report that warning can be generated erronously with VS2010. I'm not sure why you are so persistant in making be feel that my knowledge is so lacking. I know that I am not an expert. I don't do this as a profession I do it like some people do crossword puzzles to relax a little bit. I am a miner by profession. I'm sorry if I have offended any and all readers of this forum but I though this is where I could ask questions of experts to help my simplistic knowledge of C# expand. Again thanks for the time you have spent and I apoligize to you and the group for not being on the same level as you guys. rafone
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
-
It was the warning I was trying to understand....After searching and reading post after post I did find that error report on Microsoft Connect. I thought becase the Form was disposing all components including the hosted toolstrip (that I provided code for) that it was being disposed. According to the bug report that warning can be generated erronously with VS2010. I'm not sure why you are so persistant in making be feel that my knowledge is so lacking. I know that I am not an expert. I don't do this as a profession I do it like some people do crossword puzzles to relax a little bit. I am a miner by profession. I'm sorry if I have offended any and all readers of this forum but I though this is where I could ask questions of experts to help my simplistic knowledge of C# expand. Again thanks for the time you have spent and I apoligize to you and the group for not being on the same level as you guys. rafone
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
Rafone wrote:
It was the warning I was trying to understand
In your first post you said, "I'm not sure where to place the System.IDisposable.Dispose". You give no mention or indication in any subsequent post that it is the warning you don't understand. Again you posted, "based on the error text I gathered that this is what I am supposed to do. If I knew how I wouldn't have had to ask...". Once again this implies you are having difficulty with implementation of the Disposal Pattern code, not the original error message.
Rafone wrote:
I though this is where I could ask questions of experts to help my simplistic knowledge of C# expand.
It is. However, you have the responsibility to clear and accurately state your question and intentions. We don't read minds and are not working in the same room with you on the same project on the same piece of code. You can't assume we will know implicitly what you mean or are referring to. Down voting an answer because you feel it isn't what you wanted to hear is extremely rude, unproductive and won't win you any points here. It will make it even less likely that others will want to help you in the future.
I know the language. I've read a book. - _Madmatt
-
Rafone wrote:
It was the warning I was trying to understand
In your first post you said, "I'm not sure where to place the System.IDisposable.Dispose". You give no mention or indication in any subsequent post that it is the warning you don't understand. Again you posted, "based on the error text I gathered that this is what I am supposed to do. If I knew how I wouldn't have had to ask...". Once again this implies you are having difficulty with implementation of the Disposal Pattern code, not the original error message.
Rafone wrote:
I though this is where I could ask questions of experts to help my simplistic knowledge of C# expand.
It is. However, you have the responsibility to clear and accurately state your question and intentions. We don't read minds and are not working in the same room with you on the same project on the same piece of code. You can't assume we will know implicitly what you mean or are referring to. Down voting an answer because you feel it isn't what you wanted to hear is extremely rude, unproductive and won't win you any points here. It will make it even less likely that others will want to help you in the future.
I know the language. I've read a book. - _Madmatt
So then... Was this correct thinking? I thought becase the Form was disposing all components including the hosted toolstrip (that I provided code for) that it was being disposed. rafone
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
-
It appears this is a bug in VS2010 I am seeing a CA200 Warning (call Dispose) on a variable declared within a using statement. Type: Bug ID: 521027 Opened: 12/17/2009 2:10:58 PM Access Restriction: Public 0 Workaround(s) 7 User(s) can reproduce this bug
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...
Sometimes compiler warnings can be very annoying. Long ago, when I had to work with C++ and Visual Studio 6, there were those "performance warnings" of the compiler because of casting a BOOL into a bool (or vice versa) would slow down the application. That's when I learned to ignore the warnings. Do not get discouraged by some of the replies you received to your post. It is true that there were some posts by people who were simply too lazy to do some basic research in the web and expected other CodeProject members to be obliged to spoon-feed them the solution, and then the tone in the forums deteriorated. We should return to a more friendly behavior.
-
Sometimes compiler warnings can be very annoying. Long ago, when I had to work with C++ and Visual Studio 6, there were those "performance warnings" of the compiler because of casting a BOOL into a bool (or vice versa) would slow down the application. That's when I learned to ignore the warnings. Do not get discouraged by some of the replies you received to your post. It is true that there were some posts by people who were simply too lazy to do some basic research in the web and expected other CodeProject members to be obliged to spoon-feed them the solution, and then the tone in the forums deteriorated. We should return to a more friendly behavior.
Thanks for the info Bernhard.... I work in a vacuum here….I don’t have to rely on this as an income I play with this stuff because it’s fun. But from time-to-time I need someone to bounce stuff off of because there is a sea of information out there but to be honest most of it is not very useful. There’s big difference between reading information and understanding it. Thanks to all for your time and responses rafome
Statistics are like bikini's... What they reveal is astonishing ... But what they hide is vital ...