Click here to Skip to main content
15,912,400 members
Home / Discussions / C#
   

C#

 
GeneralVisual Styles Pin
eggie530-Jul-04 19:26
eggie530-Jul-04 19:26 
GeneralRe: Visual Styles Pin
Heath Stewart30-Jul-04 23:20
protectorHeath Stewart30-Jul-04 23:20 
GeneralWant to make a good C# window Application Pin
softp_vc30-Jul-04 17:33
softp_vc30-Jul-04 17:33 
GeneralRe: Want to make a good C# window Application Pin
Heath Stewart30-Jul-04 19:10
protectorHeath Stewart30-Jul-04 19:10 
GeneralRe: Want to make a good C# window Application Pin
softp_vc1-Aug-04 17:48
softp_vc1-Aug-04 17:48 
GeneralRe: Want to make a good C# window Application Pin
Heath Stewart4-Aug-04 5:00
protectorHeath Stewart4-Aug-04 5:00 
GeneralMenuItem adding and removing at run time Pin
StephenMcAllister30-Jul-04 15:10
StephenMcAllister30-Jul-04 15:10 
GeneralRe: MenuItem adding and removing at run time Pin
Heath Stewart30-Jul-04 19:19
protectorHeath Stewart30-Jul-04 19:19 
You do realize that arrays in .NET are 0-based, so that the second MenuItem actually starts at index 1, don't you? You're starting at index 2, which is actually the third MenuItem (which could cause problems depending on the current state of your application).

Also keep in mind that when you're removing items from the MenuItem.MenuItems collection property, the collection is being re-indexed. You should actually have a reverse for-loop that starts with Count - 1 and works back to > 0, or at leat loop without changing the value passed to RemoveAt. Examples of each way follows:
for (int i=menuItem1.MenuItems.Count - 1; i > 0; i++)
  menuItem1.MenuItems.RemoveAt(i);
 
// OR
 
for (int i=1; i < menuItem1.MenuItems.Count - 1; i++)
  menuItem1.MenuItems.RemoveAt(1);


Also, context-sensitive menus are typically better to fill before being opened. This is a good use of the MenuItem.Popup event. Handle this instead of re-filling your menu list when an item is invoked. This gives you must getter control over what gets displayed and is similar to what many other applications do to provide context-sensitive menus (the Windows shell, various Office applications, Visual Studio, etc.).

 

Microsoft MVP, Visual C#
My Articles
GeneralDisabling Mouse wheel scrolling - Scenario Pin
Tristan Rhodes30-Jul-04 14:16
Tristan Rhodes30-Jul-04 14:16 
GeneralRe: Disabling Mouse wheel scrolling - Scenario Pin
Heath Stewart30-Jul-04 19:08
protectorHeath Stewart30-Jul-04 19:08 
GeneralMessage pump exception catching Pin
Hugo Hallman30-Jul-04 13:21
Hugo Hallman30-Jul-04 13:21 
GeneralRe: Message pump exception catching Pin
Heath Stewart30-Jul-04 19:06
protectorHeath Stewart30-Jul-04 19:06 
GeneralApplication displaying Japanese, German, and English text. Pin
jerrycainjr30-Jul-04 12:28
jerrycainjr30-Jul-04 12:28 
GeneralRe: Application displaying Japanese, German, and English text. Pin
Heath Stewart30-Jul-04 12:59
protectorHeath Stewart30-Jul-04 12:59 
GeneralHighlighting a object selected &amp; dynamic resizing Pin
smartyosu30-Jul-04 12:18
smartyosu30-Jul-04 12:18 
Generaltab control problem Pin
blankg30-Jul-04 10:59
blankg30-Jul-04 10:59 
Generaldifferentiating between MouseDown and single click Pin
smartyosu30-Jul-04 9:28
smartyosu30-Jul-04 9:28 
GeneralRe: differentiating between MouseDown and single click Pin
Heath Stewart30-Jul-04 9:32
protectorHeath Stewart30-Jul-04 9:32 
GeneralEvent Handler Pin
eggie530-Jul-04 7:42
eggie530-Jul-04 7:42 
GeneralRe: Event Handler Pin
Heath Stewart30-Jul-04 8:25
protectorHeath Stewart30-Jul-04 8:25 
QuestionWhere is the Activitybar? Pin
matthias s.30-Jul-04 4:36
matthias s.30-Jul-04 4:36 
Questionhow can i navigate between controls on a form using enter key in c# Pin
ch_faf30-Jul-04 4:01
ch_faf30-Jul-04 4:01 
AnswerRe: how can i navigate between controls on a form using enter key in c# Pin
Michael P Butler30-Jul-04 4:21
Michael P Butler30-Jul-04 4:21 
AnswerRe: how can i navigate between controls on a form using enter key in c# Pin
Heath Stewart30-Jul-04 7:36
protectorHeath Stewart30-Jul-04 7:36 
GeneralArray&#180;s via reflection... Pin
Norman-Timo30-Jul-04 3:09
Norman-Timo30-Jul-04 3:09 

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.