From b1f17e02a11a07627e5d0b4da920ee434db8aba1 Mon Sep 17 00:00:00 2001 From: kimw <1@kimwong.me> Date: Fri, 21 Aug 2015 16:47:56 +0800 Subject: [PATCH] 1. limit the windows' minimized size 2. store window's size & position in config file. 3. fix: scroll bar sometimes disappear while sizing the window. --- shadowsocks-csharp/Model/LogViewerConfig.cs | 9 +++++++++ shadowsocks-csharp/View/LogForm.Designer.cs | 9 +++++---- shadowsocks-csharp/View/LogForm.cs | 9 +++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/shadowsocks-csharp/Model/LogViewerConfig.cs b/shadowsocks-csharp/Model/LogViewerConfig.cs index 28471084..80bb220d 100644 --- a/shadowsocks-csharp/Model/LogViewerConfig.cs +++ b/shadowsocks-csharp/Model/LogViewerConfig.cs @@ -1,5 +1,6 @@ using System; using System.Drawing; +using System.Windows.Forms; namespace Shadowsocks.Model { @@ -13,6 +14,10 @@ namespace Shadowsocks.Model public bool topMost; public bool wrapText; public bool toolbarShown; + public int width; + public int height; + public int top; + public int left; public LogViewerConfig() { @@ -23,6 +28,10 @@ namespace Shadowsocks.Model this.topMost = false; this.wrapText = false; this.toolbarShown = false; + this.width = 600; + this.height = 400; + this.top = (Screen.PrimaryScreen.WorkingArea.Height - height) / 2; + this.left = (Screen.PrimaryScreen.WorkingArea.Width - width) / 2; } public Color GetBackgroundColor() diff --git a/shadowsocks-csharp/View/LogForm.Designer.cs b/shadowsocks-csharp/View/LogForm.Designer.cs index 187ab948..ba090850 100644 --- a/shadowsocks-csharp/View/LogForm.Designer.cs +++ b/shadowsocks-csharp/View/LogForm.Designer.cs @@ -63,7 +63,7 @@ this.LogMessageTextBox.Name = "LogMessageTextBox"; this.LogMessageTextBox.ReadOnly = true; this.LogMessageTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.LogMessageTextBox.Size = new System.Drawing.Size(584, 377); + this.LogMessageTextBox.Size = new System.Drawing.Size(378, 99); this.LogMessageTextBox.TabIndex = 0; // // MainMenu @@ -199,7 +199,7 @@ this.tableLayoutPanel1.RowCount = 2; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanel1.Size = new System.Drawing.Size(590, 418); + this.tableLayoutPanel1.Size = new System.Drawing.Size(384, 140); this.tableLayoutPanel1.TabIndex = 2; // // ToolbarFlowLayoutPanel @@ -212,16 +212,17 @@ this.ToolbarFlowLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; this.ToolbarFlowLayoutPanel.Location = new System.Drawing.Point(3, 3); this.ToolbarFlowLayoutPanel.Name = "ToolbarFlowLayoutPanel"; - this.ToolbarFlowLayoutPanel.Size = new System.Drawing.Size(584, 29); + this.ToolbarFlowLayoutPanel.Size = new System.Drawing.Size(378, 29); this.ToolbarFlowLayoutPanel.TabIndex = 2; // // LogForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(590, 418); + this.ClientSize = new System.Drawing.Size(384, 140); this.Controls.Add(this.tableLayoutPanel1); this.Menu = this.MainMenu; + this.MinimumSize = new System.Drawing.Size(400, 200); this.Name = "LogForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Log Viewer"; diff --git a/shadowsocks-csharp/View/LogForm.cs b/shadowsocks-csharp/View/LogForm.cs index 91eb69bb..a80965fd 100644 --- a/shadowsocks-csharp/View/LogForm.cs +++ b/shadowsocks-csharp/View/LogForm.cs @@ -120,6 +120,11 @@ namespace Shadowsocks.View timer.Tick += Timer_Tick; timer.Start(); + this.Top = config.logViewer.top; + this.Left = config.logViewer.left; + this.Height = config.logViewer.height; + this.Width = config.logViewer.width; + topMostTriggerLock = true; this.TopMost = TopMostMenuItem.Checked = TopMostCheckBox.Checked = topMostTrigger; topMostTriggerLock = false; @@ -141,6 +146,10 @@ namespace Shadowsocks.View config.logViewer.fontSize = LogMessageTextBox.Font.Size; config.logViewer.SetBackgroundColor(LogMessageTextBox.BackColor); config.logViewer.SetTextColor(LogMessageTextBox.ForeColor); + config.logViewer.top = this.Top; + config.logViewer.left = this.Left; + config.logViewer.height = this.Height; + config.logViewer.width = this.Width; Model.Configuration.Save(config); }