Windows Form File /DBCommander/Modals/OptionsForm.cs (C#)
using System;  
using System.Collections;  
using System.ComponentModel;  
using System.Drawing;  
using System.Windows.Forms;  
  
  
namespace YariSoft.DBCommander.Modals  
{  
    public class OptionsForm : YariSoft.Utils.ModalBaseForm  
    {  
        #region Local variables  
        private YariSoft.DBCommander.Misc.OptionsInfo options = null;  
        private System.Windows.Forms.TabControl tabControl;  
        private System.Windows.Forms.TabPage generalTabPage;  
        private System.Windows.Forms.TabPage tableTabPage;  
        private System.Windows.Forms.CheckBox identityCheckBox;  
        private System.Windows.Forms.GroupBox groupBox1;  
        private System.Windows.Forms.CheckBox funcBarCheckBox;  
        private System.Windows.Forms.CheckBox toolBarCheckBox;  
        private System.Windows.Forms.GroupBox groupBox2;  
        private System.Windows.Forms.Button agentPropertiesButton;  
        private System.Windows.Forms.CheckBox agentActiveCheckBox;  
        private System.Windows.Forms.TextBox agenFileEdit;  
        private System.Windows.Forms.Button agentDirButton;  
        private System.Windows.Forms.OpenFileDialog openFileDialog;  
        private System.Windows.Forms.Button agentEdit;  
        private System.ComponentModel.IContainer components = null;  
        #endregion  
  
        #region Constructor/Destructor  
        public OptionsForm( YariSoft.DBCommander.Misc.OptionsInfo Options )  
        {  
            InitializeComponent();  
            this.options = Options;  
            this.RefreshControls();  
        }  
  
        protected override void Dispose( bool disposing )  
        {  
            if( disposing )  
            {  
                if (components != null)  
                {  
                    components.Dispose();  
                }  
            }  
            base.Dispose( disposing );  
        }  
        #endregion  
  
        #region 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()  
        {  
            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(OptionsForm));  
            this.tabControl = new System.Windows.Forms.TabControl();  
            this.generalTabPage = new System.Windows.Forms.TabPage();  
            this.groupBox2 = new System.Windows.Forms.GroupBox();  
            this.agentDirButton = new System.Windows.Forms.Button();  
            this.agenFileEdit = new System.Windows.Forms.TextBox();  
            this.agentActiveCheckBox = new System.Windows.Forms.CheckBox();  
            this.agentPropertiesButton = new System.Windows.Forms.Button();  
            this.groupBox1 = new System.Windows.Forms.GroupBox();  
            this.funcBarCheckBox = new System.Windows.Forms.CheckBox();  
            this.toolBarCheckBox = new System.Windows.Forms.CheckBox();  
            this.tableTabPage = new System.Windows.Forms.TabPage();  
            this.identityCheckBox = new System.Windows.Forms.CheckBox();  
            this.openFileDialog = new System.Windows.Forms.OpenFileDialog();  
            this.agentEdit = new System.Windows.Forms.Button();  
            this.bottomPanel.SuspendLayout();  
            this.tabControl.SuspendLayout();  
            this.generalTabPage.SuspendLayout();  
            this.groupBox2.SuspendLayout();  
            this.groupBox1.SuspendLayout();  
            this.tableTabPage.SuspendLayout();  
            this.SuspendLayout();  
            //    
            // bottomPanel  
            //    
            this.bottomPanel.Location = new System.Drawing.Point(0, 261);  
            this.bottomPanel.Size = new System.Drawing.Size(290, 35);  
            this.bottomPanel.Visible = true;  
            //    
            // cancelButton  
            //    
            this.cancelButton.Visible = true;  
            //    
            // okButton  
            //    
            this.okButton.Visible = true;  
            //    
            // tabControl  
            //    
            this.tabControl.Controls.AddRange(new System.Windows.Forms.Control[] {  
                                                                                     this.generalTabPage,  
                                                                                     this.tableTabPage});  
            this.tabControl.Location = new System.Drawing.Point(11, 8);  
            this.tabControl.Name = "tabControl";  
            this.tabControl.SelectedIndex = 0;  
            this.tabControl.Size = new System.Drawing.Size(268, 248);  
            this.tabControl.TabIndex = 0;  
            //    
            // generalTabPage  
            //    
            this.generalTabPage.Controls.AddRange(new System.Windows.Forms.Control[] {  
                                                                                         this.groupBox2,  
                                                                                         this.groupBox1});  
            this.generalTabPage.Location = new System.Drawing.Point(4, 22);  
            this.generalTabPage.Name = "generalTabPage";  
            this.generalTabPage.Size = new System.Drawing.Size(260, 222);  
            this.generalTabPage.TabIndex = 0;  
            this.generalTabPage.Text = "General";  
            //    
            // groupBox2  
            //    
            this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {  
                                                                                    this.agentDirButton,  
                                                                                    this.agenFileEdit,  
                                                                                    this.agentActiveCheckBox,  
                                                                                    this.agentPropertiesButton,  
                                                                                    this.agentEdit});  
            this.groupBox2.Location = new System.Drawing.Point(10, 88);  
            this.groupBox2.Name = "groupBox2";  
            this.groupBox2.Size = new System.Drawing.Size(240, 80);  
            this.groupBox2.TabIndex = 1;  
            this.groupBox2.TabStop = false;  
            this.groupBox2.Text = "Agent";  
            //    
            // agentDirButton  
            //    
            this.agentDirButton.Image = ((System.Drawing.Bitmap)(resources.GetObject("agentDirButton.Image")));  
            this.agentDirButton.Location = new System.Drawing.Point(204, 45);  
            this.agentDirButton.Name = "agentDirButton";  
            this.agentDirButton.Size = new System.Drawing.Size(20, 20);  
            this.agentDirButton.TabIndex = 3;  
            this.agentDirButton.Click += new System.EventHandler(this.agentDirButton_Click);  
            //    
            // agenFileEdit  
            //    
            this.agenFileEdit.Location = new System.Drawing.Point(16, 45);  
            this.agenFileEdit.Name = "agenFileEdit";  
            this.agenFileEdit.Size = new System.Drawing.Size(168, 20);  
            this.agenFileEdit.TabIndex = 2;  
            this.agenFileEdit.Text = "";  
            //    
            // agentActiveCheckBox  
            //    
            this.agentActiveCheckBox.Location = new System.Drawing.Point(16, 13);  
            this.agentActiveCheckBox.Name = "agentActiveCheckBox";  
            this.agentActiveCheckBox.Size = new System.Drawing.Size(56, 24);  
            this.agentActiveCheckBox.TabIndex = 0;  
            this.agentActiveCheckBox.Text = "Active";  
            this.agentActiveCheckBox.Click += new System.EventHandler(this.agentActiveCheckBox_Click);  
            //    
            // agentPropertiesButton  
            //    
            this.agentPropertiesButton.Location = new System.Drawing.Point(88, 14);  
            this.agentPropertiesButton.Name = "agentPropertiesButton";  
            this.agentPropertiesButton.Size = new System.Drawing.Size(136, 23);  
            this.agentPropertiesButton.TabIndex = 1;  
            this.agentPropertiesButton.Text = "Properties";  
            this.agentPropertiesButton.Click += new System.EventHandler(this.agentPropertiesButton_Click);  
            //    
            // groupBox1  
            //    
            this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {  
                                                                                    this.funcBarCheckBox,  
                                                                                    this.toolBarCheckBox});  
            this.groupBox1.Location = new System.Drawing.Point(10, 8);  
            this.groupBox1.Name = "groupBox1";  
            this.groupBox1.Size = new System.Drawing.Size(240, 72);  
            this.groupBox1.TabIndex = 0;  
            this.groupBox1.TabStop = false;  
            this.groupBox1.Text = "Toolbars";  
            //    
            // funcBarCheckBox  
            //    
            this.funcBarCheckBox.Location = new System.Drawing.Point(16, 40);  
            this.funcBarCheckBox.Name = "funcBarCheckBox";  
            this.funcBarCheckBox.Size = new System.Drawing.Size(150, 24);  
            this.funcBarCheckBox.TabIndex = 1;  
            this.funcBarCheckBox.Text = "Show function keys";  
            //    
            // toolBarCheckBox  
            //    
            this.toolBarCheckBox.Location = new System.Drawing.Point(16, 16);  
            this.toolBarCheckBox.Name = "toolBarCheckBox";  
            this.toolBarCheckBox.Size = new System.Drawing.Size(144, 24);  
            this.toolBarCheckBox.TabIndex = 0;  
            this.toolBarCheckBox.Text = "Show toolbar";  
            //    
            // tableTabPage  
            //    
            this.tableTabPage.Controls.AddRange(new System.Windows.Forms.Control[] {  
                                                                                       this.identityCheckBox});  
            this.tableTabPage.Location = new System.Drawing.Point(4, 22);  
            this.tableTabPage.Name = "tableTabPage";  
            this.tableTabPage.Size = new System.Drawing.Size(260, 222);  
            this.tableTabPage.TabIndex = 1;  
            this.tableTabPage.Text = "Table";  
            //    
            // identityCheckBox  
            //    
            this.identityCheckBox.Location = new System.Drawing.Point(16, 20);  
            this.identityCheckBox.Name = "identityCheckBox";  
            this.identityCheckBox.Size = new System.Drawing.Size(180, 24);  
            this.identityCheckBox.TabIndex = 3;  
            this.identityCheckBox.Text = "Set identity off ( MS SQL Only )";  
            //    
            // openFileDialog  
            //    
            this.openFileDialog.Filter = "Agent config files(*.amv)|*.amv";  
            //    
            // agentEdit  
            //    
            this.agentEdit.Image = ((System.Drawing.Bitmap)(resources.GetObject("agentEdit.Image")));  
            this.agentEdit.Location = new System.Drawing.Point(184, 45);  
            this.agentEdit.Name = "agentEdit";  
            this.agentEdit.Size = new System.Drawing.Size(20, 20);  
            this.agentEdit.TabIndex = 3;  
            this.agentEdit.Click += new System.EventHandler(this.agentEdit_Click);  
            //    
            // OptionsForm  
            //    
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);  
            this.ClientSize = new System.Drawing.Size(290, 296);  
            this.Controls.AddRange(new System.Windows.Forms.Control[] {  
                                                                          this.bottomPanel,  
                                                                          this.tabControl});  
            this.Name = "OptionsForm";  
            this.Text = "Options";  
            this.Closing += new System.ComponentModel.CancelEventHandler(this.OptionsForm_Closing);  
            this.Load += new System.EventHandler(this.OptionsForm_Load);  
            this.bottomPanel.ResumeLayout(false);  
            this.tabControl.ResumeLayout(false);  
            this.generalTabPage.ResumeLayout(false);  
            this.groupBox2.ResumeLayout(false);  
            this.groupBox1.ResumeLayout(false);  
            this.tableTabPage.ResumeLayout(false);  
            this.ResumeLayout(false);  
  
        }  
        #endregion  
  
        #region Private functions  
        private void RefreshControls()  
        {  
            if( this.options != null ){  
                this.funcBarCheckBox.Checked    = this.options.ShowFuncBar;  
                this.toolBarCheckBox.Checked    = this.options.ShowToolBar;  
                this.identityCheckBox.Checked    = this.options.TableOptions.IdentityOff;  
                this.agentActiveCheckBox.Checked= this.options.AgentOptions.AgentActive;  
                this.agentPropertiesButton.Enabled  
                                                = this.agentActiveCheckBox.Checked;  
                this.agentDirButton.Enabled        = this.agentActiveCheckBox.Checked;  
                this.agenFileEdit.Enabled        = this.agentActiveCheckBox.Checked;  
                this.agenFileEdit.Text            = this.options.AgentOptions.ConfigFileName;  
            }  
        }  
  
        private void OptionsForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)  
        {  
            if( this.DialogResult == DialogResult.OK ){  
                this.options.ShowFuncBar = this.funcBarCheckBox.Checked;  
                this.options.ShowToolBar = this.toolBarCheckBox.Checked;  
                this.SaveTableOptions();  
                this.options.AgentOptions.AgentActive  
                                         = this.agentActiveCheckBox.Checked;  
                this.options.AgentOptions.ConfigFileName  
                                         = this.agenFileEdit.Text;  
                this.options.SaveToFile();  
            }  
        }  
          
        private void SaveTableOptions()  
        {  
            this.options.TableOptions.IdentityOff = this.identityCheckBox.Checked;  
        }  
          
        private void OptionsForm_Load(object sender, System.EventArgs e)  
        {  
            this.toolBarCheckBox.Select();  
        }  
  
        private void agentPropertiesButton_Click(object sender, System.EventArgs e)  
        {  
            YariSoft.Utils.AgentInfo info = new YariSoft.Utils.AgentInfo();  
            info.AgentActive    = true;  
            info.ConfigFileName = this.agenFileEdit.Text;  
  
            YariSoft.Utils.AgentManager agent = new YariSoft.Utils.AgentManager();      
            if( agent.Init( info ) ){  
                agent.ShowProperties();  
            }  
        }  
  
        private void agentActiveCheckBox_Click(object sender, System.EventArgs e)  
        {  
            this.agentPropertiesButton.Enabled    = this.agentActiveCheckBox.Checked;              
            this.agentDirButton.Enabled            = this.agentActiveCheckBox.Checked;  
            this.agenFileEdit.Enabled            = this.agentActiveCheckBox.Checked;  
        }  
  
        private void agentDirButton_Click(object sender, System.EventArgs e)  
        {  
            this.openFileDialog.FileName = this.agenFileEdit.Text;  
            if( this.openFileDialog.ShowDialog(this) == DialogResult.OK ){  
                this.agenFileEdit.Text = this.openFileDialog.FileName;  
            }  
        }  
  
        [System.Runtime.InteropServices.DllImport("shell32.dll")]  
        static extern IntPtr ShellExecute( IntPtr hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd );  
  
        private void agentEdit_Click(object sender, System.EventArgs e)  
        {  
            ShellExecute( this.Handle, "open", "AgentMovieEditor.exe", "\"" + this.agenFileEdit.Text + "\"", Application.StartupPath, 1 );       
        }  
        #endregion  
  
    }  
}