From f3ecd89f4cb5e62021f07c8655cbe7b9ae0e0c01 Mon Sep 17 00:00:00 2001 From: Sigmanor Date: Fri, 3 Feb 2017 23:38:15 +0200 Subject: [PATCH] Added drag and drop support for txt and cnp files #2 --- Crypto Notepad/Form1.Designer.cs | 224 +++++++++++++++---------------- Crypto Notepad/Form1.cs | 36 ++++- 2 files changed, 145 insertions(+), 115 deletions(-) diff --git a/Crypto Notepad/Form1.Designer.cs b/Crypto Notepad/Form1.Designer.cs index 5dd1556..c5c42b9 100644 --- a/Crypto Notepad/Form1.Designer.cs +++ b/Crypto Notepad/Form1.Designer.cs @@ -81,7 +81,13 @@ public void InitializeComponent() this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); + this.searchTextBox = new System.Windows.Forms.TextBox(); + this.chkMatchCase = new System.Windows.Forms.CheckBox(); + this.chkMatchWholeWord = new System.Windows.Forms.CheckBox(); + this.panel1 = new System.Windows.Forms.Panel(); + this.panel2 = new System.Windows.Forms.Panel(); this.pictureBox12 = new System.Windows.Forms.PictureBox(); + this.pictureBox13 = new System.Windows.Forms.PictureBox(); this.pictureBox5 = new System.Windows.Forms.PictureBox(); this.pictureBox2 = new System.Windows.Forms.PictureBox(); this.pictureBox11 = new System.Windows.Forms.PictureBox(); @@ -93,16 +99,13 @@ public void InitializeComponent() this.pictureBox4 = new System.Windows.Forms.PictureBox(); this.pictureBox3 = new System.Windows.Forms.PictureBox(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); - this.pictureBox13 = new System.Windows.Forms.PictureBox(); - this.searchTextBox = new System.Windows.Forms.TextBox(); - this.chkMatchCase = new System.Windows.Forms.CheckBox(); - this.chkMatchWholeWord = new System.Windows.Forms.CheckBox(); - this.panel1 = new System.Windows.Forms.Panel(); - this.panel2 = new System.Windows.Forms.Panel(); this.customRTB = new Crypto_Notepad.CustomRichTextBox(); this.MainMenu.SuspendLayout(); this.contextMenuStrip1.SuspendLayout(); + this.panel1.SuspendLayout(); + this.panel2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox12)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox13)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox5)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox11)).BeginInit(); @@ -114,9 +117,6 @@ public void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.pictureBox4)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox13)).BeginInit(); - this.panel1.SuspendLayout(); - this.panel2.SuspendLayout(); this.SuspendLayout(); // // MainMenu @@ -525,6 +525,90 @@ public void InitializeComponent() this.button2.UseVisualStyleBackColor = true; this.button2.Visible = false; // + // searchTextBox + // + this.searchTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.searchTextBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(35))))); + this.searchTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.searchTextBox.ForeColor = System.Drawing.Color.White; + this.searchTextBox.Location = new System.Drawing.Point(196, 6); + this.searchTextBox.Name = "searchTextBox"; + this.searchTextBox.Size = new System.Drawing.Size(303, 14); + this.searchTextBox.TabIndex = 9; + this.searchTextBox.TabStop = false; + this.searchTextBox.TextChanged += new System.EventHandler(this.textBox1_TextChanged); + this.searchTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.searchTextBox_KeyDown); + // + // chkMatchCase + // + this.chkMatchCase.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.chkMatchCase.AutoSize = true; + this.chkMatchCase.ForeColor = System.Drawing.Color.Gainsboro; + this.chkMatchCase.Location = new System.Drawing.Point(95, 5); + this.chkMatchCase.Name = "chkMatchCase"; + this.chkMatchCase.Size = new System.Drawing.Size(95, 17); + this.chkMatchCase.TabIndex = 11; + this.chkMatchCase.Text = "Case sensitive"; + this.chkMatchCase.UseVisualStyleBackColor = false; + this.chkMatchCase.CheckedChanged += new System.EventHandler(this.chkMatchCase_CheckedChanged); + // + // chkMatchWholeWord + // + this.chkMatchWholeWord.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.chkMatchWholeWord.AutoSize = true; + this.chkMatchWholeWord.BackColor = System.Drawing.Color.Transparent; + this.chkMatchWholeWord.ForeColor = System.Drawing.Color.Gainsboro; + this.chkMatchWholeWord.Location = new System.Drawing.Point(6, 5); + this.chkMatchWholeWord.Name = "chkMatchWholeWord"; + this.chkMatchWholeWord.Size = new System.Drawing.Size(83, 17); + this.chkMatchWholeWord.TabIndex = 12; + this.chkMatchWholeWord.Text = "Whole word"; + this.chkMatchWholeWord.UseVisualStyleBackColor = false; + this.chkMatchWholeWord.CheckedChanged += new System.EventHandler(this.chkMatchWholeWord_CheckedChanged); + // + // panel1 + // + this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(35))))); + this.panel1.Controls.Add(this.pictureBox1); + this.panel1.Controls.Add(this.searchTextBox); + this.panel1.Controls.Add(this.chkMatchCase); + this.panel1.Controls.Add(this.chkMatchWholeWord); + this.panel1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.panel1.Location = new System.Drawing.Point(0, 272); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(535, 27); + this.panel1.TabIndex = 13; + this.panel1.Visible = false; + // + // panel2 + // + this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.panel2.Controls.Add(this.pictureBox12); + this.panel2.Controls.Add(this.pictureBox13); + this.panel2.Controls.Add(this.pictureBox5); + this.panel2.Controls.Add(this.pictureBox2); + this.panel2.Controls.Add(this.pictureBox11); + this.panel2.Controls.Add(this.pictureBox10); + this.panel2.Controls.Add(this.pictureBox9); + this.panel2.Controls.Add(this.pictureBox8); + this.panel2.Controls.Add(this.pictureBox7); + this.panel2.Controls.Add(this.pictureBox6); + this.panel2.Controls.Add(this.pictureBox4); + this.panel2.Controls.Add(this.pictureBox3); + this.panel2.Location = new System.Drawing.Point(-1, 25); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(537, 23); + this.panel2.TabIndex = 14; + // // pictureBox12 // this.pictureBox12.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); @@ -541,6 +625,19 @@ public void InitializeComponent() this.pictureBox12.MouseEnter += new System.EventHandler(this.pictureBox12_MouseEnter); this.pictureBox12.MouseLeave += new System.EventHandler(this.pictureBox12_MouseLeave); // + // pictureBox13 + // + this.pictureBox13.Cursor = System.Windows.Forms.Cursors.Hand; + this.pictureBox13.Image = global::Crypto_Notepad.Properties.Resources.lock_icon; + this.pictureBox13.Location = new System.Drawing.Point(260, 3); + this.pictureBox13.Name = "pictureBox13"; + this.pictureBox13.Size = new System.Drawing.Size(16, 16); + this.pictureBox13.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBox13.TabIndex = 15; + this.pictureBox13.TabStop = false; + this.toolTip1.SetToolTip(this.pictureBox13, "Lock"); + this.pictureBox13.Click += new System.EventHandler(this.pictureBox13_Click); + // // pictureBox5 // this.pictureBox5.Cursor = System.Windows.Forms.Cursors.Hand; @@ -687,103 +784,6 @@ public void InitializeComponent() this.pictureBox1.MouseLeave += new System.EventHandler(this.pictureBox1_MouseLeave); this.pictureBox1.MouseHover += new System.EventHandler(this.pictureBox1_MouseHover); // - // pictureBox13 - // - this.pictureBox13.Cursor = System.Windows.Forms.Cursors.Hand; - this.pictureBox13.Image = global::Crypto_Notepad.Properties.Resources.lock_icon; - this.pictureBox13.Location = new System.Drawing.Point(260, 3); - this.pictureBox13.Name = "pictureBox13"; - this.pictureBox13.Size = new System.Drawing.Size(16, 16); - this.pictureBox13.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.pictureBox13.TabIndex = 15; - this.pictureBox13.TabStop = false; - this.toolTip1.SetToolTip(this.pictureBox13, "Lock"); - this.pictureBox13.Click += new System.EventHandler(this.pictureBox13_Click); - // - // searchTextBox - // - this.searchTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.searchTextBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(35))))); - this.searchTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None; - this.searchTextBox.ForeColor = System.Drawing.Color.White; - this.searchTextBox.Location = new System.Drawing.Point(196, 6); - this.searchTextBox.Name = "searchTextBox"; - this.searchTextBox.Size = new System.Drawing.Size(303, 14); - this.searchTextBox.TabIndex = 9; - this.searchTextBox.TabStop = false; - this.searchTextBox.TextChanged += new System.EventHandler(this.textBox1_TextChanged); - this.searchTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.searchTextBox_KeyDown); - // - // chkMatchCase - // - this.chkMatchCase.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.chkMatchCase.AutoSize = true; - this.chkMatchCase.ForeColor = System.Drawing.Color.Gainsboro; - this.chkMatchCase.Location = new System.Drawing.Point(95, 5); - this.chkMatchCase.Name = "chkMatchCase"; - this.chkMatchCase.Size = new System.Drawing.Size(95, 17); - this.chkMatchCase.TabIndex = 11; - this.chkMatchCase.Text = "Case sensitive"; - this.chkMatchCase.UseVisualStyleBackColor = false; - this.chkMatchCase.CheckedChanged += new System.EventHandler(this.chkMatchCase_CheckedChanged); - // - // chkMatchWholeWord - // - this.chkMatchWholeWord.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.chkMatchWholeWord.AutoSize = true; - this.chkMatchWholeWord.BackColor = System.Drawing.Color.Transparent; - this.chkMatchWholeWord.ForeColor = System.Drawing.Color.Gainsboro; - this.chkMatchWholeWord.Location = new System.Drawing.Point(6, 5); - this.chkMatchWholeWord.Name = "chkMatchWholeWord"; - this.chkMatchWholeWord.Size = new System.Drawing.Size(83, 17); - this.chkMatchWholeWord.TabIndex = 12; - this.chkMatchWholeWord.Text = "Whole word"; - this.chkMatchWholeWord.UseVisualStyleBackColor = false; - this.chkMatchWholeWord.CheckedChanged += new System.EventHandler(this.chkMatchWholeWord_CheckedChanged); - // - // panel1 - // - this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(35))))); - this.panel1.Controls.Add(this.pictureBox1); - this.panel1.Controls.Add(this.searchTextBox); - this.panel1.Controls.Add(this.chkMatchCase); - this.panel1.Controls.Add(this.chkMatchWholeWord); - this.panel1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.panel1.Location = new System.Drawing.Point(0, 272); - this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(535, 27); - this.panel1.TabIndex = 13; - this.panel1.Visible = false; - // - // panel2 - // - this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.panel2.Controls.Add(this.pictureBox12); - this.panel2.Controls.Add(this.pictureBox13); - this.panel2.Controls.Add(this.pictureBox5); - this.panel2.Controls.Add(this.pictureBox2); - this.panel2.Controls.Add(this.pictureBox11); - this.panel2.Controls.Add(this.pictureBox10); - this.panel2.Controls.Add(this.pictureBox9); - this.panel2.Controls.Add(this.pictureBox8); - this.panel2.Controls.Add(this.pictureBox7); - this.panel2.Controls.Add(this.pictureBox6); - this.panel2.Controls.Add(this.pictureBox4); - this.panel2.Controls.Add(this.pictureBox3); - this.panel2.Location = new System.Drawing.Point(-1, 25); - this.panel2.Name = "panel2"; - this.panel2.Size = new System.Drawing.Size(537, 23); - this.panel2.TabIndex = 14; - // // customRTB // this.customRTB.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -792,7 +792,6 @@ public void InitializeComponent() this.customRTB.BackColor = System.Drawing.SystemColors.Window; this.customRTB.BorderStyle = System.Windows.Forms.BorderStyle.None; this.customRTB.ContextMenuStrip = this.contextMenuStrip1; - this.customRTB.DetectUrls = false; this.customRTB.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.customRTB.ForeColor = System.Drawing.SystemColors.WindowText; this.customRTB.Location = new System.Drawing.Point(0, 48); @@ -800,6 +799,7 @@ public void InitializeComponent() this.customRTB.Size = new System.Drawing.Size(535, 252); this.customRTB.TabIndex = 10; this.customRTB.Text = ""; + this.customRTB.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.customRTB_LinkClicked); this.customRTB.SelectionChanged += new System.EventHandler(this.customRTB_SelectionChanged_1); this.customRTB.Click += new System.EventHandler(this.customRTB_Click); this.customRTB.KeyDown += new System.Windows.Forms.KeyEventHandler(this.customRTB_KeyDown); @@ -828,7 +828,12 @@ public void InitializeComponent() this.MainMenu.ResumeLayout(false); this.MainMenu.PerformLayout(); this.contextMenuStrip1.ResumeLayout(false); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + this.panel2.ResumeLayout(false); + this.panel2.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox12)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox13)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox5)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox11)).EndInit(); @@ -840,11 +845,6 @@ public void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.pictureBox4)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox13)).EndInit(); - this.panel1.ResumeLayout(false); - this.panel1.PerformLayout(); - this.panel2.ResumeLayout(false); - this.panel2.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Crypto Notepad/Form1.cs b/Crypto Notepad/Form1.cs index b2fc949..bf57675 100644 --- a/Crypto Notepad/Form1.cs +++ b/Crypto Notepad/Form1.cs @@ -20,11 +20,12 @@ public partial class MainWindow : Form string filename = "Unnamed.cnp"; string[] args = Environment.GetCommandLineArgs(); int caretPos = 0; - string appName = Assembly.GetExecutingAssembly().GetName().Name + " – "; - + string appName = Assembly.GetExecutingAssembly().GetName().Name + " – "; public MainWindow() { InitializeComponent(); + customRTB.DragDrop += new DragEventHandler(customRTB_DragDrop); + customRTB.AllowDrop = true; } #region SaltMac @@ -162,7 +163,6 @@ private void openAsotiations() } } - private void newToolStripMenuItem_Click_1(object sender, EventArgs e) { Form2 f2 = new Form2(); @@ -1048,5 +1048,35 @@ private void customRTB_LinkClicked(object sender, LinkClickedEventArgs e) Process.Start(e.LinkText); } + void customRTB_DragDrop(object sender, DragEventArgs e) + { + string[] FileList = (string[])e.Data.GetData(DataFormats.FileDrop, false); + foreach (string file in FileList) OpenFile.FileName = file; + + object fname = e.Data.GetData("FileDrop"); + if (fname != null) + { + var list = fname as string[]; + + if (list != null && !string.IsNullOrWhiteSpace(list[0])) + { + if (!OpenFile.FileName.Contains(".cnp")) + { + customRTB.Clear(); + string opnfile = File.ReadAllText(OpenFile.FileName); + string NameWithotPath = Path.GetFileName(OpenFile.FileName); + customRTB.Text = opnfile; + this.Text = appName + NameWithotPath; + string cc2 = customRTB.Text.Length.ToString(CultureInfo.InvariantCulture); + customRTB.Select(Convert.ToInt32(cc2), 0); + return; + } + customRTB.Clear(); + DecryptAES(); + } + + } + } + } } \ No newline at end of file