-
Notifications
You must be signed in to change notification settings - Fork 1
/
BarTextBox.cs
80 lines (72 loc) · 1.51 KB
/
BarTextBox.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Windows.Forms;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Summary description for BarTextBox.
/// </summary>
internal class BarTextBox:TextBox
{
private int m_LastFocusWindow;
private string m_OriginalText;
public BarTextBox()
{
this.BorderStyle=System.Windows.Forms.BorderStyle.None;
this.AutoSize=false;
this.TabStop=false;
m_LastFocusWindow=0;
}
protected override void WndProc(ref Message m)
{
if(m.Msg==NativeFunctions.WM_SETFOCUS)
{
m_LastFocusWindow=m.WParam.ToInt32();
m_OriginalText=this.Text;
}
base.WndProc(ref m);
}
public void ReleaseFocus()
{
if(this.Focused && m_LastFocusWindow!=0)
{
int focus=m_LastFocusWindow;
m_LastFocusWindow=0;
Control ctrl=Control.FromChildHandle(new System.IntPtr(focus));
if(ctrl!=this)
{
Control p=this.Parent;
while(p!=null)
{
if(p==ctrl)
return;
p=p.Parent;
}
if(ctrl!=null)
ctrl.Focus();
else
{
NativeFunctions.SetFocus(focus);
}
}
//this.OnLostFocus(new System.EventArgs());
//this.InvokeLostFocus(this,new System.EventArgs());
}
}
protected override void OnKeyDown(KeyEventArgs e)
{
if(e.KeyCode==Keys.Enter)
ReleaseFocus();
else if(e.KeyCode==Keys.Escape)
{
this.Text=m_OriginalText;
ReleaseFocus();
}
base.OnKeyDown(e);
}
protected override void OnLostFocus(EventArgs e)
{
m_LastFocusWindow=0;
base.OnLostFocus(e);
}
}
}