-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathVerifyViewerForm.cs
More file actions
181 lines (147 loc) · 4.41 KB
/
VerifyViewerForm.cs
File metadata and controls
181 lines (147 loc) · 4.41 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DigitalPlatform;
using DigitalPlatform.CommonControl;
namespace DigitalPlatform.Script
{
public partial class VerifyViewerForm : Form
{
/// <summary>
/// 停靠
/// </summary>
public event DoDockEventHandler DoDockEvent = null;
public bool Docked = false;
// public MainForm MainForm = null;
public event LocateEventHandler Locate = null;
public VerifyViewerForm()
{
InitializeComponent();
}
public string ResultString
{
get
{
return this.textBox_verifyResult.Text;
}
set
{
this.textBox_verifyResult.Text = value;
}
}
private void toolStripButton_dock_Click(object sender, EventArgs e)
{
DoDock(true);
}
public void DoDock(bool bShowFixedPanel)
{
// return; // 测试内存泄漏
/*
this.MainForm.CurrentVerifyResultControl = this.textBox_verifyResult;
if (bShowFixedPanel == true
&& this.MainForm.PanelFixedVisible == false)
this.MainForm.PanelFixedVisible = true;
this.Docked = true;
this.Visible = false;
* */
if (this.DoDockEvent != null)
{
DoDockEventArgs e = new DoDockEventArgs();
e.ShowFixedPanel = bShowFixedPanel;
this.DoDockEvent(this, e);
}
}
#region 防止控件泄露
// 不会被自动 Dispose 的 子 Control,放在这里托管,避免内存泄漏
List<Control> _freeControls = new List<Control>();
public void AddFreeControl(Control control)
{
ControlExtention.AddFreeControl(_freeControls, control);
}
public void RemoveFreeControl(Control control)
{
ControlExtention.RemoveFreeControl(_freeControls, control);
}
public void DisposeFreeControls()
{
ControlExtention.DisposeFreeControls(_freeControls);
}
#endregion
public void Clear()
{
this.TryInvoke(() =>
{
this.textBox_verifyResult.Text = "";
});
}
public TextBox ResultControl
{
get
{
return this.textBox_verifyResult;
}
}
private void textBox_verifyResult_DoubleClick(object sender, EventArgs e)
{
if (this.Locate == null)
return;
if (textBox_verifyResult.Lines.Length == 0)
return;
int x = 0;
int y = 0;
API.GetEditCurrentCaretPos(
this.textBox_verifyResult,
out x,
out y);
string strLine = "";
try
{
strLine = textBox_verifyResult.Lines[y];
}
catch
{
return;
}
// 析出"(字段名,子字段名, 字符位置)"值
int nRet = strLine.IndexOf("(");
if (nRet == -1)
return;
strLine = strLine.Substring(nRet + 1);
nRet = strLine.IndexOf(")");
if (nRet != -1)
strLine = strLine.Substring(0, nRet);
strLine = strLine.Trim();
LocateEventArgs e1 = new LocateEventArgs();
e1.Location = strLine;
this.Locate(this, e1);
}
// Dock 停靠以后,this.Visible == true,只能用 ResultControl
void TryInvoke(Action method)
{
this.ResultControl.TryInvoke(method);
}
T TryGet<T>(Func<T> func)
{
return this.ResultControl.TryGet(func);
}
}
//
public delegate void DoDockEventHandler(object sender,
DoDockEventArgs e);
public class DoDockEventArgs : EventArgs
{
public bool ShowFixedPanel = false; // [in]
}
//
public delegate void LocateEventHandler(object sender,
LocateEventArgs e);
public class LocateEventArgs : EventArgs
{
public string Location = "";
}
}