Click here to Skip to main content
15,897,371 members
Home / Discussions / C#
   

C#

 
GeneralRe: read jpeg into memory Pin
Leon Radley29-Dec-03 1:49
Leon Radley29-Dec-03 1:49 
GeneralADS Pin
realaravind27-Dec-03 2:59
realaravind27-Dec-03 2:59 
GeneralRe: ADS Pin
Wizard_0127-Dec-03 3:12
Wizard_0127-Dec-03 3:12 
QuestionHow to create menuItems dynamic on Popup event? Pin
Chris Richner27-Dec-03 2:02
Chris Richner27-Dec-03 2:02 
AnswerRe: How to create menuItems dynamic on Popup event? Pin
Wizard_0127-Dec-03 3:05
Wizard_0127-Dec-03 3:05 
GeneralRe: How to create menuItems dynamic on Popup event? Pin
Chris Richner27-Dec-03 3:29
Chris Richner27-Dec-03 3:29 
GeneralRe: How to create menuItems dynamic on Popup event? Pin
Heath Stewart27-Dec-03 5:29
protectorHeath Stewart27-Dec-03 5:29 
GeneralRe: How to create menuItems dynamic on Popup event? - what I did with a couple of classes Pin
Bryan White1-Jan-04 22:20
Bryan White1-Jan-04 22:20 
This is how I do it:
- create a ContextMenuPopup in the application (I do this in the base form, but use it for multiple forms in the same application). I think that I used the GUI designer originally:
this.contextMenuPopup = new System.Windows.Forms.ContextMenu();
- the GUI designer threw this code in; how much is actually used? dunno!
this.contextMenuPopup.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemTitle,
this.menuItemSep1,
this.menuItemOpt1,
this.menuItemOpt2,
this.menuItemOpt3});
this.contextMenuPopup.Popup += new System.EventHandler(this.contextMenuPopup_Popup);
- In the form you want it to apply to, add:
newWindowL.GraphicControl.ContextMenu = contextMenuPopup;
- Write a menu builder
This is tricky; you need to remember that:
- each MenuItem has to be a clone, not an original, if you are "mix'n'match"ing a menu. Well, I found that it helped 'cos some items are duplicated.
- each MenuItem needs an event handler. I use a recursive method to allow multi-level context menus
-MenuItemCommand is derived from MenuItem & does a few fancy things like storing a command object (cf "Command Patterns")
The code has just been copied & pasted. Use it more for ideas/principles than 'as is'; here goes:
#region ContextMenuPopup stuff
private void contextMenuPopup_Popup(object sender, System.EventArgs e)
{
ContextMenu ctxMenu = sender as ContextMenu;
if(ctxMenu == null)
return;
Control ctl = ctxMenu.SourceControl;
if(ctl == null)
return;
// blah blah
contextMenuBuilder.SetContextOptionNames(GarageSystem.Garage, hitStruct4ContextMenu, mEditingMenus, contextMenuPopup);
}

public void SetContextOptionNames(SEComponentMaster topLevel, Structure hitStruct, Menu.MenuItemCollection theMenuCollection,
ContextMenu theContextMenu)//, MenuClicker theEventHandler)
{

MenuClicker theEventHandler = new ContextMenuBuilder.MenuClicker(menuItemDynamicContextEntry_Click);
theContextMenu.MenuItems.Clear();
MenuPlusCommand theFilteredMenu = null;
if(mHitStructure.Owner is IWall)
{
theFilteredMenu = MenuBuilderFromXML.ReturnFirstMenuItemOwnerLike(theMenuCollection[0].MenuItems, "Wall");
}
theContextMenu.MenuItems.Add(mHitStructure.Name);
theContextMenu.MenuItems.Add("-");
if(theFilteredMenu != null)
{
MenuPlusCommand theFilteredMenuCopy = theFilteredMenu;
foreach(MenuItem I in theFilteredMenuCopy.MenuItems)
theContextMenu.MenuItems.Add(I.CloneMenu());
RecursiveSetContextMenuClickEventHandler(theContextMenu.MenuItems, theContextMenu, theEventHandler);
}
}

public static void RecursiveSetContextMenuClickEventHandler(Menu.MenuItemCollection theMenuItems, ContextMenu theContextMenu, MenuClicker theEventHandler)
{
if(theMenuItems != null)
{
foreach(MenuItem I in theMenuItems)
{
MenuPlusCommand thisSubItem = I as MenuPlusCommand;
if(thisSubItem != null)
{
if(thisSubItem.Command.ToString().Length > 1)
{
thisSubItem.Click += new System.EventHandler(theEventHandler);
}
else
{
if(thisSubItem.MenuItems.Count > 0)
{
RecursiveSetContextMenuClickEventHandler(thisSubItem.MenuItems, theContextMenu, theEventHandler);
}
}
}
}
}
}
Hope this helps


Regards

Brewman
GeneralC# and COM - Further information Pin
Tristan Rhodes27-Dec-03 1:17
Tristan Rhodes27-Dec-03 1:17 
GeneralRe: C# and COM - Further information Pin
Nick Parker27-Dec-03 4:30
protectorNick Parker27-Dec-03 4:30 
GeneralRe: C# and COM - Further information Pin
27-Dec-03 5:15
suss27-Dec-03 5:15 
GeneralRe: C# and COM - Further information Pin
Heath Stewart27-Dec-03 5:26
protectorHeath Stewart27-Dec-03 5:26 
QuestionHow can I make a newline in "net send" Pin
bookwormXP26-Dec-03 19:50
bookwormXP26-Dec-03 19:50 
AnswerRe: How can I make a newline in "net send" Pin
leppie27-Dec-03 0:39
leppie27-Dec-03 0:39 
GeneralRe: How can I make a newline in "net send" Pin
bookwormXP27-Dec-03 1:01
bookwormXP27-Dec-03 1:01 
GeneralRe: How can I make a newline in "net send" Pin
leppie27-Dec-03 1:20
leppie27-Dec-03 1:20 
GeneralRe: How can I make a newline in "net send" Pin
bookwormXP27-Dec-03 1:26
bookwormXP27-Dec-03 1:26 
GeneralRe: How can I make a newline in "net send" Pin
LongRange.Shooter30-Dec-03 9:35
LongRange.Shooter30-Dec-03 9:35 
AnswerRe: How can I make a newline in "net send" Pin
Heath Stewart27-Dec-03 5:19
protectorHeath Stewart27-Dec-03 5:19 
AnswerRe: How can I make a newline in "net send" Pin
Mazdak27-Dec-03 8:53
Mazdak27-Dec-03 8:53 
General"The file isn't specified" error for opening documents Pin
tchaka26-Dec-03 15:40
tchaka26-Dec-03 15:40 
GeneralRe: "The file isn't specified" error for opening documents Pin
eggie526-Dec-03 18:04
eggie526-Dec-03 18:04 
GeneralRe: "The file isn't specified" error for opening documents Pin
tchaka26-Dec-03 20:22
tchaka26-Dec-03 20:22 
GeneralRe: "The file isn't specified" error for opening documents Pin
eggie527-Dec-03 6:51
eggie527-Dec-03 6:51 
GeneralRe: "The file isn't specified" error for opening documents Pin
Heath Stewart27-Dec-03 5:16
protectorHeath Stewart27-Dec-03 5:16 

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.