From 3cc53625c26a089a93af9014886bae0e57b0ff21 Mon Sep 17 00:00:00 2001 From: xponen Date: Mon, 23 Jun 2014 07:53:36 +0800 Subject: [PATCH] SendBox.cs & NavigationControl.cs: implement triple click to select all text in textbox. --- ZeroKLobby/MicroLobby/SendBox.cs | 14 +++++++++++++ ZeroKLobby/NavigationControl.Designer.cs | 3 +-- ZeroKLobby/NavigationControl.cs | 26 +++++++++++++----------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/ZeroKLobby/MicroLobby/SendBox.cs b/ZeroKLobby/MicroLobby/SendBox.cs index 2338f616a5..853781254d 100644 --- a/ZeroKLobby/MicroLobby/SendBox.cs +++ b/ZeroKLobby/MicroLobby/SendBox.cs @@ -32,6 +32,7 @@ public SendBox() this.BackColor = Program.Conf.BgColor; this.ForeColor = Program.Conf.TextColor; this.KeyDown += SendBox_KeyDown; + this.MouseDown += SendBox_MouseDown; } protected override void OnKeyPress(KeyPressEventArgs e) @@ -259,5 +260,18 @@ private void SendBox_KeyDown(object sender, KeyEventArgs e) else if (e.Control & e.KeyCode == Keys.B) InsertColorCharacter("02", "12");//blue on light cyan } + + private int clickCount = 0; + private long lastClick = 0; + private int systemDoubleClickTime = SystemInformation.DoubleClickTime * 10000; + private void SendBox_MouseDown(object sender, EventArgs e) + { //reference: http://stackoverflow.com/questions/5014825/triple-mouse-click-in-c + //10,000 ticks is a milisecond, therefore 2,000,000 ticks is 200milisecond . http://msdn.microsoft.com/en-us/library/system.datetime.ticks.aspx + //double click time: http://msdn.microsoft.com/en-us/library/system.windows.forms.systeminformation.doubleclicktime(v=vs.110).aspx + if (DateTime.Now.Ticks - lastClick <= systemDoubleClickTime) clickCount = clickCount + 1; + else clickCount = 1; + if (clickCount%3 == 0) SelectAll(); //select all text when triple click + lastClick = DateTime.Now.Ticks; + } } } \ No newline at end of file diff --git a/ZeroKLobby/NavigationControl.Designer.cs b/ZeroKLobby/NavigationControl.Designer.cs index b8535f1b25..5b8a4977e8 100644 --- a/ZeroKLobby/NavigationControl.Designer.cs +++ b/ZeroKLobby/NavigationControl.Designer.cs @@ -46,9 +46,8 @@ private void InitializeComponent() this.urlBox.Name = "urlBox"; this.urlBox.Size = new System.Drawing.Size(190, 20); this.urlBox.TabIndex = 2; - this.urlBox.Enter += new System.EventHandler(this.urlBox_Enter); this.urlBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.urlBox_KeyDown); - this.urlBox.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.urlBox_MouseDoubleClick); + this.urlBox.MouseDown += new System.Windows.Forms.MouseEventHandler(this.urlBox_MouseDown); // // flowLayoutPanel1 // diff --git a/ZeroKLobby/NavigationControl.cs b/ZeroKLobby/NavigationControl.cs index a1b1c0afce..7156c37adc 100644 --- a/ZeroKLobby/NavigationControl.cs +++ b/ZeroKLobby/NavigationControl.cs @@ -42,7 +42,6 @@ public partial class NavigationControl: UserControl readonly Dictionary lastTabPaths = new Dictionary(); public ChatTab ChatTab { get { return chatTab; } } public static NavigationControl Instance { get; private set; } - bool selectURLtextboxAll = false; public string Path { get { return CurrentPage != null ? CurrentPage.ToString() : string.Empty; } @@ -330,17 +329,6 @@ public void AddToHistoryStack(String finalURL, String firstURL, Object obj) } } - private void urlBox_MouseDoubleClick(object sender, MouseEventArgs e) - { - if (!selectURLtextboxAll) { urlBox.SelectAll(); } - selectURLtextboxAll = !selectURLtextboxAll; - } - - private void urlBox_Enter(object sender, EventArgs e) - { - selectURLtextboxAll = false; - } - private void logoutButton_Click(object sender, EventArgs e) { Program.TasClient.Disconnect(); @@ -352,5 +340,19 @@ private void isBusyTimer_Tick(object sender, EventArgs e) { isBusyIcon.Visible = CurrentNavigatable.IsBusy; } + + private int clickCount = 0; + private long lastClick = 0; + private int systemDoubleClickTime = SystemInformation.DoubleClickTime * 10000; + private void urlBox_MouseDown(object sender, MouseEventArgs e) + { + //reference: http://stackoverflow.com/questions/5014825/triple-mouse-click-in-c + //10,000 ticks is a milisecond, therefore 2,000,000 ticks is 200milisecond . http://msdn.microsoft.com/en-us/library/system.datetime.ticks.aspx + //double click time: http://msdn.microsoft.com/en-us/library/system.windows.forms.systeminformation.doubleclicktime(v=vs.110).aspx + if (DateTime.Now.Ticks - lastClick <= systemDoubleClickTime) clickCount = clickCount + 1; + else clickCount = 1; + if (clickCount % 3 == 0) urlBox.SelectAll(); //select all text when triple click + lastClick = DateTime.Now.Ticks; + } } } \ No newline at end of file