-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathrichEx.cs
117 lines (99 loc) · 3.28 KB
/
richEx.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace SPA
{
public partial class richEx : RichTextBox
{
private readonly object mustHideCaretLocker = new object();
private bool mustHideCaret;
[DefaultValue(false)]
public bool MustHideCaret
{
get
{
lock (this.mustHideCaretLocker)
return this.mustHideCaret;
}
set
{
TabStop = false;
if (value)
SetHideCaret();
else
SetShowCaret();
}
}
[DllImport("user32.dll")]
private static extern int HideCaret(IntPtr hwnd);
[DllImport("user32.dll", EntryPoint = "ShowCaret")]
private static extern long ShowCaret(IntPtr hwnd);
public richEx()
{
//VScroll += HandleRichTextBoxAdjustScroll;
//TextChanged += HandleRichTextBoxAdjustScroll;
}
private void SetHideCaret()
{
//VScroll += richEx_VScroll;
MouseDown += new MouseEventHandler(ReadOnlyRichTextBox_Mouse);
MouseUp += new MouseEventHandler(ReadOnlyRichTextBox_Mouse);
Resize += new EventHandler(ReadOnlyRichTextBox_Resize);
HideCaret(Handle);
lock (this.mustHideCaretLocker)
this.mustHideCaret = true;
}
//void richEx_VScroll(object sender, EventArgs e)
//{
// throw new NotImplementedException();
//}
private void SetShowCaret()
{
try
{
MouseDown -= new MouseEventHandler(ReadOnlyRichTextBox_Mouse);
MouseUp -= new MouseEventHandler(ReadOnlyRichTextBox_Mouse);
Resize -= new EventHandler(ReadOnlyRichTextBox_Resize);
}
catch
{
}
ShowCaret(Handle);
lock (this.mustHideCaretLocker)
this.mustHideCaret = false;
}
protected override void OnGotFocus(EventArgs e)
{
if (MustHideCaret)
{
HideCaret(Handle);
this.Parent.Focus();//here we select parent control in my case it is panel
}
}
protected override void OnEnter(EventArgs e)
{
if (MustHideCaret)
HideCaret(Handle);
}
private void ReadOnlyRichTextBox_Mouse(object sender, System.Windows.Forms.MouseEventArgs e)
{
HideCaret(Handle);
}
private void ReadOnlyRichTextBox_Resize(object sender, System.EventArgs e)
{
HideCaret(Handle);
}
//private const UInt32 SB_TOP = 0x6;
//private const UInt32 WM_VSCROLL = 0x115;
//[return: MarshalAs(UnmanagedType.Bool)]
//[DllImport("user32.dll", SetLastError = true)]
//private static extern bool PostMessage(IntPtr hWnd, UInt32 Msg,
// IntPtr wParam, IntPtr lParam);
//private void HandleRichTextBoxAdjustScroll(Object sender,
// EventArgs e)
//{
// PostMessage(Handle, WM_VSCROLL, (IntPtr)SB_TOP, IntPtr.Zero);
//}
}
}