Click here to Skip to main content
15,884,177 members
Articles / Programming Languages / XML

.NET Based Add-in/Plug-in Framework with Dynamic Toolbars and Menus

Rate me:
Please Sign up or sign in to vote.
4.74/5 (43 votes)
2 May 20066 min read 177.6K   2.2K   211  
An article on a .NET based add-in/plug-in framework, with dynamic toolbars and menus.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Xml;

namespace ProjectFramework
{
	/// <summary>
	/// Summary description for AddinSettings.
	/// </summary>
	public class AddinSettings : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button buttonOK;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.CheckedListBox checkedListBoxAddinSettings;
		private System.Windows.Forms.CheckBox checkBoxLoadAddins;
		public AddinProjectFramework ProjectFramework;
		public AddinSettings()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.buttonOK = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.checkBoxLoadAddins = new System.Windows.Forms.CheckBox();
			this.checkedListBoxAddinSettings = new System.Windows.Forms.CheckedListBox();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// buttonOK
			// 
			this.buttonOK.Location = new System.Drawing.Point(220, 228);
			this.buttonOK.Name = "buttonOK";
			this.buttonOK.Size = new System.Drawing.Size(92, 24);
			this.buttonOK.TabIndex = 1;
			this.buttonOK.Text = "OK";
			this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.checkBoxLoadAddins);
			this.groupBox1.Controls.Add(this.checkedListBoxAddinSettings);
			this.groupBox1.Location = new System.Drawing.Point(24, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(288, 216);
			this.groupBox1.TabIndex = 2;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Available Addins";
			// 
			// checkBoxLoadAddins
			// 
			this.checkBoxLoadAddins.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.checkBoxLoadAddins.ForeColor = System.Drawing.SystemColors.ActiveCaption;
			this.checkBoxLoadAddins.Location = new System.Drawing.Point(8, 176);
			this.checkBoxLoadAddins.Name = "checkBoxLoadAddins";
			this.checkBoxLoadAddins.Size = new System.Drawing.Size(272, 32);
			this.checkBoxLoadAddins.TabIndex = 2;
			this.checkBoxLoadAddins.Text = "Load all addins when starting the application";
			// 
			// checkedListBoxAddinSettings
			// 
			this.checkedListBoxAddinSettings.Location = new System.Drawing.Point(16, 24);
			this.checkedListBoxAddinSettings.Name = "checkedListBoxAddinSettings";
			this.checkedListBoxAddinSettings.Size = new System.Drawing.Size(240, 139);
			this.checkedListBoxAddinSettings.TabIndex = 1;
			this.checkedListBoxAddinSettings.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.checkedListBoxAddinSettings_ItemCheck);
			// 
			// AddinSettings
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(330, 256);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.buttonOK);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "AddinSettings";
			this.Text = "Addin Settings";
			this.Load += new System.EventHandler(this.AddinSettings_Load);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void buttonOK_Click(object sender, System.EventArgs e)
		{
			try
			{
				for(int i=0;i<checkedListBoxAddinSettings.Items.Count;i++)
				{
					bool bCheck=Convert.ToBoolean(checkedListBoxAddinSettings.GetItemChecked(i));
					ProjectFramework.m_PluginManager.UpdateAddinMenuStatus(i,bCheck);
				}
				//Get the load all addin status
				ProjectFramework.m_PluginManager.m_bLoadAddinsOnStartup=checkBoxLoadAddins.Checked;
				ProjectFramework.m_PluginManager.SavePluginDetailsToXML();
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
			this.Close();
		}

		private void AddinSettings_Load(object sender, System.EventArgs e)
		{
			if(ProjectFramework.m_PluginManager.m_bLoadAddinsOnStartup)
			{
				for(int i=0;i<ProjectFramework.m_PluginManager.AddinInfoArray.Length;i++)
				{
					if(ProjectFramework.m_PluginManager.AddinInfoArray[i].strAddinName!=null)
					{
						checkedListBoxAddinSettings.Items.Add(ProjectFramework.m_PluginManager.AddinInfoArray[i].strAddinName);  
						checkedListBoxAddinSettings.SetItemChecked(i,ProjectFramework.m_PluginManager.AddinInfoArray[i].bLoadAddin);
					}
				}
			}
			checkBoxLoadAddins.Checked=ProjectFramework.m_PluginManager.m_bLoadAddinsOnStartup;
		}

		private void checkedListBoxAddinSettings_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
		{
			ProjectFramework.m_PluginManager.AddinInfoArray[e.Index].bLoadAddin= Convert.ToBoolean(e.NewValue);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Chief Technology Officer KTS INFOTECH PVT LTD
India India
->9+ Years of Experience in IT Field.
->Basically a C++ Programmer migrating to .NET
->Have Masters degree in Physics and Computer Scince.
-> Doing his Ph.D(Part Time) in Optical Networking)
->Interests: Software product development,Networking, Robotics,Sports Physics, Learning musical instruments, Cricket.

->Resides in kerala ,the gods own country, with his mother and wife.

Home page


Comments and Discussions