Click here to Skip to main content
15,915,513 members
Home / Discussions / C#
   

C#

 
GeneralRe: FileSystemWatcher Pin
Chals30-Mar-05 4:37
Chals30-Mar-05 4:37 
Generalneed help to improve selected color filter logic Pin
montu337729-Mar-05 23:26
montu337729-Mar-05 23:26 
GeneralRe: need help to improve selected color filter logic Pin
Sebastian Schneider29-Mar-05 23:40
Sebastian Schneider29-Mar-05 23:40 
GeneralRe: need help to improve selected color filter logic Pin
montu337730-Mar-05 0:22
montu337730-Mar-05 0:22 
Generalcontext menu problems Pin
ekynox29-Mar-05 23:23
ekynox29-Mar-05 23:23 
GeneralRe: context menu problems Pin
Sebastian Schneider29-Mar-05 23:59
Sebastian Schneider29-Mar-05 23:59 
GeneralRe: context menu problems Pin
ekynox30-Mar-05 1:49
ekynox30-Mar-05 1:49 
GeneralRe: context menu problems Pin
Sebastian Schneider30-Mar-05 10:31
Sebastian Schneider30-Mar-05 10:31 
This is how I would solve the problem. You still need to find a way to put your identifiers to some use.

I used this technique to load Plugins into a MenuItem and fire those events, with the user being able to freely change the item's menu position without having to re-assign events.

How that worked?

The user copies plugin dlls into the apps directory. each plugin has a GUID of some sort, which is used as the identifier on both the plugin and the item. This way, I can simply load the plugins up and let the user arrange them the way he needs them. I then simply look up the plugin via the identifier and let it do its stuff.

OK, some people will frown now. You are right, and it just occured to me as I read my explanation, that I am so freaking dumb.

This IS a solution to your described problem, but its totally crap for what I did. I was assuming that, as the Item Position changes when you modify MenuItem.Index, the associated handlers would somehow swich items. Bullshit. I never needed those, I just had to assing the plugin.dostuff to the appropiate MenuItem. NAAAAAAAAAAAAAAAAAARGH! Frown | :(

I guess I need more sleep Wink | ;)

/*<br />
 * Created by SharpDevelop.<br />
 * User: PiLLe<br />
 * Date: 30.03.2005<br />
 * Time: 22:53<br />
 * <br />
 * To change this template use Tools | Options | Coding | Edit Standard Headers.<br />
 */<br />
using System;<br />
using System.Drawing;<br />
using System.Windows.Forms;<br />
<br />
namespace contextdemo<br />
{<br />
	/// <summary><br />
	/// Description of MainForm.<br />
	/// </summary><br />
	public class MainForm : System.Windows.Forms.Form<br />
	{<br />
		private System.Windows.Forms.Panel panel1;<br />
		private System.Windows.Forms.ContextMenu contextMenu1;<br />
		private System.Windows.Forms.TextBox tbItems;<br />
		private System.Windows.Forms.MenuItem menuItem1;<br />
		private System.Windows.Forms.Button bCreate;<br />
		public MainForm()<br />
		{<br />
			//<br />
			// The InitializeComponent() call is required for Windows Forms designer support.<br />
			//<br />
			InitializeComponent();<br />
			<br />
			//<br />
			// TODO: Add constructor code after the InitializeComponent() call.<br />
			//<br />
		}<br />
		<br />
		[STAThread]<br />
		public static void Main(string[] args)<br />
		{<br />
			Application.Run(new MainForm());<br />
		}<br />
		<br />
		#region Windows Forms Designer generated code<br />
		/// <summary><br />
		/// This method is required for Windows Forms designer support.<br />
		/// Do not change the method contents inside the source code editor. The Forms designer might<br />
		/// not be able to load this method if it was changed manually.<br />
		/// </summary><br />
		private void InitializeComponent() {<br />
			this.bCreate = new System.Windows.Forms.Button();<br />
			this.menuItem1 = new System.Windows.Forms.MenuItem();<br />
			this.tbItems = new System.Windows.Forms.TextBox();<br />
			this.contextMenu1 = new System.Windows.Forms.ContextMenu();<br />
			this.panel1 = new System.Windows.Forms.Panel();<br />
			this.SuspendLayout();<br />
			// <br />
			// bCreate<br />
			// <br />
			this.bCreate.Location = new System.Drawing.Point(144, 160);<br />
			this.bCreate.Name = "bCreate";<br />
			this.bCreate.Size = new System.Drawing.Size(96, 24);<br />
			this.bCreate.TabIndex = 2;<br />
			this.bCreate.Text = "Create X Items";<br />
			this.bCreate.Click += new System.EventHandler(this.BCreateClick);<br />
			// <br />
			// menuItem1<br />
			// <br />
			this.menuItem1.Index = 0;<br />
			this.menuItem1.Text = "Standard Menu Item. Not generated.";<br />
			this.menuItem1.Click += new System.EventHandler(this.standardMenuItem_Click);<br />
			// <br />
			// tbItems<br />
			// <br />
			this.tbItems.Location = new System.Drawing.Point(32, 160);<br />
			this.tbItems.Name = "tbItems";<br />
			this.tbItems.Size = new System.Drawing.Size(88, 20);<br />
			this.tbItems.TabIndex = 1;<br />
			this.tbItems.Text = "5";<br />
			// <br />
			// contextMenu1<br />
			// <br />
			this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {<br />
						this.menuItem1});<br />
			// <br />
			// panel1<br />
			// <br />
			this.panel1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255)));<br />
			this.panel1.ContextMenu = this.contextMenu1;<br />
			this.panel1.Location = new System.Drawing.Point(24, 32);<br />
			this.panel1.Name = "panel1";<br />
			this.panel1.Size = new System.Drawing.Size(144, 80);<br />
			this.panel1.TabIndex = 0;<br />
			// <br />
			// MainForm<br />
			// <br />
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
			this.ClientSize = new System.Drawing.Size(292, 237);<br />
			this.Controls.Add(this.bCreate);<br />
			this.Controls.Add(this.tbItems);<br />
			this.Controls.Add(this.panel1);<br />
			this.Name = "MainForm";<br />
			this.Text = "MainForm";<br />
			this.ResumeLayout(false);<br />
		}<br />
		#endregion<br />
		void BCreateClick(object sender, System.EventArgs e)<br />
		{<br />
			int noOfItems = 0;<br />
			try<br />
			{<br />
				noOfItems = Int32.Parse(tbItems.Text);				<br />
			}<br />
			catch (Exception ex)<br />
			{<br />
				MessageBox.Show("There was a problem. Creating 5 items instead.\r\n" + ex.Message);<br />
				noOfItems = 5;<br />
			}<br />
			for (int i = 0; i < noOfItems; i++)<br />
			{<br />
				IndexedMenuItem itemToAdd = new IndexedMenuItem(i+1);<br />
				itemToAdd.Click += new System.EventHandler(this.indexedMenuItem_Click);<br />
				itemToAdd.Text = "Generated IndexedMenuItem No. " + (i + 1).ToString();<br />
				contextMenu1.MenuItems.Add(itemToAdd);<br />
			}<br />
			MessageBox.Show("Items created");<br />
			<br />
			<br />
		}<br />
		<br />
		void standardMenuItem_Click(object sender, System.EventArgs e)<br />
		{<br />
			MessageBox.Show("The standard MenuItem was clicked.");<br />
		}<br />
		void indexedMenuItem_Click(object sender, System.EventArgs e)<br />
		{<br />
			MessageBox.Show("A generated IndexedMenuItem was clicked. The item clicked had the identifier " + ((IndexedMenuItem)sender).Identifier.ToString());<br />
		}<br />
		<br />
	}<br />
	<br />
	public class IndexedMenuItem : System.Windows.Forms.MenuItem<br />
	{<br />
		private int identifier;<br />
		public int Identifier<br />
		{<br />
			get<br />
			{<br />
				return identifier;<br />
			}<br />
		}<br />
		<br />
		public IndexedMenuItem(int newIndex)<br />
		{<br />
			identifier = newIndex;<br />
		}<br />
		<br />
	<br />
	}<br />
}


Cheers
Sid
GeneralRe: context menu problems Pin
Sebastian Schneider30-Mar-05 10:36
Sebastian Schneider30-Mar-05 10:36 
GeneralRe: context menu problems Pin
ekynox1-Apr-05 1:11
ekynox1-Apr-05 1:11 
GeneralCompile and execute code Pin
lindiwe29-Mar-05 23:23
lindiwe29-Mar-05 23:23 
GeneralRe: Compile and execute code Pin
Stanciu Vlad29-Mar-05 23:43
Stanciu Vlad29-Mar-05 23:43 
GeneralRe: Compile and execute code Pin
Sebastian Schneider30-Mar-05 0:02
Sebastian Schneider30-Mar-05 0:02 
GeneralRe: Compile and execute code Pin
Kodanda Pani30-Mar-05 2:29
Kodanda Pani30-Mar-05 2:29 
Generalsystem class Pin
computer_eng29-Mar-05 22:50
computer_eng29-Mar-05 22:50 
GeneralRe: system class Pin
Sabry190529-Mar-05 23:55
Sabry190529-Mar-05 23:55 
GeneralRe: system class Pin
AristotleYu13-Jun-05 22:15
AristotleYu13-Jun-05 22:15 
Generalclose a dialog box when a text box has focus Pin
steve_rm29-Mar-05 22:05
steve_rm29-Mar-05 22:05 
GeneralRe: close a dialog box when a text box has focus Pin
Stanciu Vlad29-Mar-05 22:30
Stanciu Vlad29-Mar-05 22:30 
GeneralRe: close a dialog box when a text box has focus Pin
Luis Alonso Ramos30-Mar-05 7:49
Luis Alonso Ramos30-Mar-05 7:49 
GeneralRe: close a dialog box when a text box has focus Pin
S. Senthil Kumar30-Mar-05 19:30
S. Senthil Kumar30-Mar-05 19:30 
Generalwin32 datatype in C#.NET Pin
Babarsaeed29-Mar-05 22:00
Babarsaeed29-Mar-05 22:00 
GeneralRe: win32 datatype in C#.NET Pin
Stanciu Vlad29-Mar-05 22:10
Stanciu Vlad29-Mar-05 22:10 
GeneralRe: win32 datatype in C#.NET Pin
Anonymous1-Apr-05 17:26
Anonymous1-Apr-05 17:26 
GeneralRe: win32 datatype in C#.NET Pin
Stanciu Vlad1-Apr-05 20:02
Stanciu Vlad1-Apr-05 20:02 

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.