Click here to Skip to main content
15,890,579 members
Home / Discussions / C#
   

C#

 
AnswerRe: Detecting low memory Pin
T M Gray27-Aug-10 4:23
T M Gray27-Aug-10 4:23 
AnswerRe: Detecting low memory [modified] Pin
Paul Michalik29-Aug-10 0:38
Paul Michalik29-Aug-10 0:38 
AnswerRe: Detecting low memory Pin
PIEBALDconsult29-Aug-10 4:12
mvePIEBALDconsult29-Aug-10 4:12 
QuestionReflection with Dynamic Objects (System.__ComObject) Pin
Tony Richards27-Aug-10 0:38
Tony Richards27-Aug-10 0:38 
AnswerRe: Reflection with Dynamic Objects (System.__ComObject) [modified] Pin
Paul Michalik27-Aug-10 3:54
Paul Michalik27-Aug-10 3:54 
QuestionC# Squrid My Program Up Pin
C.CoderCreator26-Aug-10 22:43
C.CoderCreator26-Aug-10 22:43 
AnswerRe: C# Squrid My Program Up PinPopular
Pete O'Hanlon26-Aug-10 23:17
mvePete O'Hanlon26-Aug-10 23:17 
AnswerRe: C# Squrid My Program Up Pin
OriginalGriff26-Aug-10 23:54
mveOriginalGriff26-Aug-10 23:54 
Firstly a few presentation points:

If you ever post code again, use the "code block" and "inline code" buttons differently.
You used "inline code":
private void CMS_CheckChanged(object sender, EventArgs e)<br />
{<br />
// this needs help so moake sure if the boxes will be checked or not<br />
foreach (ToolStripItem item in ((ToolStripDropDownItem)sender).Owner.Items)<br />
{<br />
if (item.GetType() == typeof(ToolStripMenuItem))<br />
{<br />
if (item == sender)<br />
((ToolStripMenuItem)item).Checked = true;<br />
else ((ToolStripMenuItem)item).Checked = false;<br />
}<br />
}<br />
}



If you had used "code block" instead it would have preserved the formatting:
C#
private void CMS_CheckChanged(object sender, EventArgs e)
   {
   // this needs help so moake sure if the boxes will be checked or not
   foreach (ToolStripItem item in ((ToolStripDropDownItem)sender).Owner.Items)
      {
      if (item.GetType() == typeof(ToolStripMenuItem))
         {
         if (item == sender)
            ((ToolStripMenuItem)item).Checked = true;
         else ((ToolStripMenuItem)item).Checked = false;
         }
      }
   }
See how much easier it is to read?

There is a "Preview" button at the bottom - try it and see if it looks readable!

Also, don't post your whole file - just the relevant bits! Otherwise we have to scroll through the whole lot to get to the reply button - this discourages people from bothering...


Secondly general good things to do in code:
In the example above (and others) you are casting the sender parameter directly to a ToolStripDropDownItem. What happens if you re-use the method? Answer: your program crashes with a "cannot convert" error. Instead, always check before you cast. Either use:
if (sender is ToolStripDropDownItem_
   {
   ToolStripDropDownItem item = (ToolStripDropDownItem) sender;
   ...
   } 
or
ToolStripDropDownItem item = sender as ToolStripDropDownItem;
if (item != null)
   {
   ...
   }
I prefer the later as it makes the null check explicit.
This is part of what is called "Defensive Programming" and trust me, it is something well worth getting into the habit of!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

AnswerRe: C# Squrid My Program Up Pin
J a a n s27-Aug-10 0:20
professionalJ a a n s27-Aug-10 0:20 
AnswerRe: C# Squrid My Program Up Pin
Luc Pattyn27-Aug-10 2:06
sitebuilderLuc Pattyn27-Aug-10 2:06 
AnswerRe: C# Squrid My Program Up Pin
T M Gray27-Aug-10 4:32
T M Gray27-Aug-10 4:32 
GeneralRe: C# Squrid My Program Up Pin
Chris Trelawny-Ross27-Aug-10 5:53
Chris Trelawny-Ross27-Aug-10 5:53 
AnswerRe: C# Squrid My Program Up Pin
The Man from U.N.C.L.E.27-Aug-10 6:17
The Man from U.N.C.L.E.27-Aug-10 6:17 
AnswerRe: C# Squrid My Program Up Pin
Paul Michalik27-Aug-10 23:01
Paul Michalik27-Aug-10 23:01 
QuestionHow to create Microsoft Excel 2007 add-in in C#2010 Pin
soe htet26-Aug-10 22:32
soe htet26-Aug-10 22:32 
AnswerRe: How to create Microsoft Excel 2007 add-in in C#2010 Pin
Łukasz Nowakowski27-Aug-10 0:32
Łukasz Nowakowski27-Aug-10 0:32 
Questionvideo chat Pin
sardar.nale26-Aug-10 22:09
sardar.nale26-Aug-10 22:09 
AnswerRe: video chat Pin
Pete O'Hanlon26-Aug-10 22:22
mvePete O'Hanlon26-Aug-10 22:22 
AnswerRe: video chat Pin
J4amieC26-Aug-10 22:27
J4amieC26-Aug-10 22:27 
AnswerRe: video chat Pin
Pete O'Hanlon26-Aug-10 22:31
mvePete O'Hanlon26-Aug-10 22:31 
AnswerRe: video chat Pin
OriginalGriff26-Aug-10 22:32
mveOriginalGriff26-Aug-10 22:32 
AnswerRe: video chat Pin
Luc Pattyn27-Aug-10 2:10
sitebuilderLuc Pattyn27-Aug-10 2:10 
Questionthe transparency goes when the panel is invalidated Pin
prasadbuddhika26-Aug-10 21:27
prasadbuddhika26-Aug-10 21:27 
AnswerRe: the transparency goes when the panel is invalidated Pin
OriginalGriff26-Aug-10 22:07
mveOriginalGriff26-Aug-10 22:07 
GeneralRe: the transparency goes when the panel is invalidated Pin
prasadbuddhika26-Aug-10 22:22
prasadbuddhika26-Aug-10 22:22 

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.