-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.cs
172 lines (137 loc) · 4.83 KB
/
Main.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
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;
using System.Threading;
namespace DicomViewer
{
public partial class Main : Form
{
bool showTag =true;//tag/ 影像切换
bool zoomYes = true;//原图/适合窗口
DicomHandler handler;
public Main()
{
InitializeComponent();
UIswitch();
}
void UIswitch()
{
if (handler != null)
{
windowWidthTxt.Text = handler.windowWith.ToString();
windowCenterTxt.Text = handler.windowCenter.ToString();
}
if (showTag)
{
textBox1.Visible = true;
pictureBox1.Visible = false;
toolStripButton2.Text = "[切换到影像 ]";
}
else
{
textBox1.Visible = false;
pictureBox1.Visible = true;
toolStripButton2.Text = "[切换到标签 ]";
}
if (zoomYes)
{
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
toolStripButton3.Text = "[切换到原始尺寸 ]";
}
else
{
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
toolStripButton3.Text = "[切换到适合窗口尺寸]";
}
if (backgroundWorker1.IsBusy)
{
Bitmap loadImg = new Bitmap(200, 100);
Graphics g = Graphics.FromImage(loadImg);
g.DrawString("载入中,请稍后...", new Font(new FontFamily("Arial"), 15.0f), Brushes.Black, new PointF(0, 0));
pictureBox1.Image = loadImg;
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
}
else
{
if (handler!=null&& handler.gdiImg!=null)
pictureBox1.Image = handler.gdiImg;
if (zoomYes)
{
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
toolStripButton3.Text = "[切换到原始尺寸 ]";
}
else
{
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
toolStripButton3.Text = "[切换到适合窗口尺寸]";
}
}
}
private void toolStripLabel1_Click(object sender, EventArgs e)
{
if (backgroundWorker1.IsBusy)
{
MessageBox.Show("影像载入中,请稍后...");
return;
}
if (openFileDialog1.ShowDialog() != DialogResult.OK)
return;
string fileName = openFileDialog1.FileName;
handler = new DicomHandler(fileName);
handler.readAndShow(textBox1);
this.Text = "DicomViewer-" + openFileDialog1.FileName;
backgroundWorker1.RunWorkerAsync();
UIswitch();
//if (handler.getImg())
// pictureBox1.Image = handler.gdiImg;
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
if (backgroundWorker1.IsBusy)
{
MessageBox.Show("影像载入中,请稍后...");
return;
}
if (saveFileDialog1.ShowDialog() != DialogResult.OK || handler == null || handler.gdiImg == null)
return;
handler.saveAs(saveFileDialog1.FileName);
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
showTag = !showTag;
UIswitch();
}
private void toolStripButton3_Click(object sender, EventArgs e)
{
zoomYes = !zoomYes;
UIswitch();
}
private void toolStripButton4_Click(object sender, EventArgs e)
{
if (backgroundWorker1.IsBusy||handler==null)
{
MessageBox.Show("影像载入中,请稍后...");
return;
}
int.TryParse(windowWidthTxt.Text, out handler.windowWith);
int.TryParse(windowCenterTxt.Text, out handler.windowCenter);
backgroundWorker1.RunWorkerAsync();
UIswitch();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
if (handler.getImg())
pictureBox1.Image = handler.gdiImg;
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
UIswitch();
}
}
}