From cdca98d23c58d1d9cffec54c2d4f43ac85a60522 Mon Sep 17 00:00:00 2001 From: Vadim Guseynov Date: Fri, 24 Jul 2020 01:54:07 +0300 Subject: [PATCH] Only one set button --- Form1.Designer.cs | 31 +++++++--------------- Form1.cs | 53 +++++++++++++++++++++++++++++++++++--- Properties/AssemblyInfo.cs | 4 +-- 3 files changed, 60 insertions(+), 28 deletions(-) diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 6e3d613..38ce746 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -33,7 +33,6 @@ private void InitializeComponent() this.listBoxProcesses = new System.Windows.Forms.ListBox(); this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonSetTop = new System.Windows.Forms.Button(); - this.buttonUnsetTop = new System.Windows.Forms.Button(); this.textBoxSearch = new System.Windows.Forms.TextBox(); this.buttonThisOnTop = new System.Windows.Forms.Button(); this.buttonAbout = new System.Windows.Forms.Button(); @@ -52,15 +51,16 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Right))); this.listBoxProcesses.Location = new System.Drawing.Point(12, 36); this.listBoxProcesses.Name = "listBoxProcesses"; - this.listBoxProcesses.Size = new System.Drawing.Size(161, 186); + this.listBoxProcesses.Size = new System.Drawing.Size(161, 147); this.listBoxProcesses.Sorted = true; this.listBoxProcesses.TabIndex = 0; + this.listBoxProcesses.Click += new System.EventHandler(this.ListBoxProcesses_Click); this.listBoxProcesses.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.ListBoxProcesses_MouseDoubleClick); // // buttonUpdate // this.buttonUpdate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUpdate.Location = new System.Drawing.Point(179, 54); + this.buttonUpdate.Location = new System.Drawing.Point(179, 44); this.buttonUpdate.Name = "buttonUpdate"; this.buttonUpdate.Size = new System.Drawing.Size(94, 23); this.buttonUpdate.TabIndex = 1; @@ -71,7 +71,7 @@ private void InitializeComponent() // buttonSetTop // this.buttonSetTop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonSetTop.Location = new System.Drawing.Point(179, 170); + this.buttonSetTop.Location = new System.Drawing.Point(179, 160); this.buttonSetTop.Name = "buttonSetTop"; this.buttonSetTop.Size = new System.Drawing.Size(94, 23); this.buttonSetTop.TabIndex = 2; @@ -79,17 +79,6 @@ private void InitializeComponent() this.buttonSetTop.UseVisualStyleBackColor = true; this.buttonSetTop.Click += new System.EventHandler(this.ButtonSetTop_Click); // - // buttonUnsetTop - // - this.buttonUnsetTop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUnsetTop.Location = new System.Drawing.Point(179, 199); - this.buttonUnsetTop.Name = "buttonUnsetTop"; - this.buttonUnsetTop.Size = new System.Drawing.Size(94, 23); - this.buttonUnsetTop.TabIndex = 3; - this.buttonUnsetTop.Text = "Unset top"; - this.buttonUnsetTop.UseVisualStyleBackColor = true; - this.buttonUnsetTop.Click += new System.EventHandler(this.ButtonUnsetTop_Click); - // // textBoxSearch // this.textBoxSearch.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -104,7 +93,7 @@ private void InitializeComponent() // buttonThisOnTop // this.buttonThisOnTop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonThisOnTop.Location = new System.Drawing.Point(179, 83); + this.buttonThisOnTop.Location = new System.Drawing.Point(179, 73); this.buttonThisOnTop.Name = "buttonThisOnTop"; this.buttonThisOnTop.Size = new System.Drawing.Size(94, 23); this.buttonThisOnTop.TabIndex = 6; @@ -149,7 +138,7 @@ private void InitializeComponent() // buttonTransparency // this.buttonTransparency.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonTransparency.Location = new System.Drawing.Point(179, 112); + this.buttonTransparency.Location = new System.Drawing.Point(179, 102); this.buttonTransparency.Name = "buttonTransparency"; this.buttonTransparency.Size = new System.Drawing.Size(94, 23); this.buttonTransparency.TabIndex = 10; @@ -160,7 +149,7 @@ private void InitializeComponent() // buttonProperties // this.buttonProperties.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonProperties.Location = new System.Drawing.Point(179, 141); + this.buttonProperties.Location = new System.Drawing.Point(179, 131); this.buttonProperties.Name = "buttonProperties"; this.buttonProperties.Size = new System.Drawing.Size(94, 23); this.buttonProperties.TabIndex = 11; @@ -184,7 +173,7 @@ private void InitializeComponent() // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(285, 230); + this.ClientSize = new System.Drawing.Size(285, 195); this.Controls.Add(this.buttonLog); this.Controls.Add(this.buttonProperties); this.Controls.Add(this.buttonTransparency); @@ -192,12 +181,11 @@ private void InitializeComponent() this.Controls.Add(this.buttonAbout); this.Controls.Add(this.buttonThisOnTop); this.Controls.Add(this.textBoxSearch); - this.Controls.Add(this.buttonUnsetTop); this.Controls.Add(this.buttonSetTop); this.Controls.Add(this.buttonUpdate); this.Controls.Add(this.listBoxProcesses); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.MinimumSize = new System.Drawing.Size(301, 269); + this.MinimumSize = new System.Drawing.Size(301, 234); this.Name = "MainForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "OnTopper"; @@ -212,7 +200,6 @@ private void InitializeComponent() private System.Windows.Forms.ListBox listBoxProcesses; private System.Windows.Forms.Button buttonUpdate; private System.Windows.Forms.Button buttonSetTop; - private System.Windows.Forms.Button buttonUnsetTop; private System.Windows.Forms.TextBox textBoxSearch; private System.Windows.Forms.Button buttonThisOnTop; private System.Windows.Forms.Button buttonAbout; diff --git a/Form1.cs b/Form1.cs index a163b53..73e17ef 100644 --- a/Form1.cs +++ b/Form1.cs @@ -17,6 +17,8 @@ public partial class MainForm : Form private bool ballonShowed = false; + private State.WINDOW_STATE newState; + public MainForm() { InitializeComponent(); @@ -187,8 +189,16 @@ private void ButtonSetTop_Click(object sender, EventArgs e) ShowSelectProcessMessageBox(); return; } - SetWindowState(State.WINDOW_STATE.TOP); - logForm.AddAction(new TopStateAction(listBoxProcesses.SelectedItem as Process, State.WINDOW_STATE.TOP)); + SetWindowState(newState); + if (newState == State.WINDOW_STATE.TOP) + { + logForm.AddAction(new TopStateAction(listBoxProcesses.SelectedItem as Process, State.WINDOW_STATE.TOP)); + } else + { + logForm.AddAction(new TopStateAction(listBoxProcesses.SelectedItem as Process, State.WINDOW_STATE.UNTOP)); + } + newState = newState == State.WINDOW_STATE.TOP ? State.WINDOW_STATE.UNTOP : State.WINDOW_STATE.TOP; + RefreshTopButton(); } private void ButtonUnsetTop_Click(object sender, EventArgs e) @@ -227,7 +237,8 @@ private void ButtonSettings_Click(object sender, EventArgs e) if (settingsForm.showWindowTitles) { listBoxProcesses.DisplayMember = "MainWindowTitle"; - } else + } + else { listBoxProcesses.DisplayMember = "ProcessName"; } @@ -329,9 +340,43 @@ private void ButtonProperties_Click(object sender, EventArgs e) private void ButtonLog_Click(object sender, EventArgs e) { - logForm.ShowDialogWithTopMostState(TopMost); + logForm.ShowDialogWithTopMostState(State.IsTopMost(Process.GetCurrentProcess())); + UpdateProcesses(); + RefreshTopButton(); + } + + + private void ListBoxProcesses_Click(object sender, EventArgs e) + { + if (listBoxProcesses.SelectedIndex == -1) + { + ShowSelectProcessMessageBox(); + return; + } + + var proc = listBoxProcesses.SelectedItem as Process; + if (!State.IsTopMost(proc)) + { + newState = State.WINDOW_STATE.TOP; + } + else + { + newState = State.WINDOW_STATE.UNTOP; + } + RefreshTopButton(); } + private void RefreshTopButton() + { + if (newState == State.WINDOW_STATE.TOP) + { + buttonSetTop.Text = "Set top"; + } + else + { + buttonSetTop.Text = "Unset top"; + } + } #endregion } diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 1282096..44724f4 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -33,7 +33,7 @@ // Можно задать все значения или принять номера сборки и редакции по умолчанию // используя "*", как показано ниже: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.6.1.4")] -[assembly: AssemblyFileVersion("1.6.1.4")] +[assembly: AssemblyVersion("1.6.2.0")] +[assembly: AssemblyFileVersion("1.6.2.0")] [assembly: NeutralResourcesLanguage("en")]