FrmScreenTest.cs
5.6 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.Common;
namespace TSA_V
{
public partial class FrmScreenTest : Form
{
public FrmScreenTest()
{
InitializeComponent();
}
public int ScreenIndex = 1;
private void FrmScreenTest_Load(object sender, EventArgs e)
{
this.Text = "显示测试_" + ScreenIndex;
Screen[] sc = Screen.AllScreens;
this.StartPosition = FormStartPosition.Manual;
if (sc.Count() > ScreenIndex)
{
Screen screen = sc[ScreenIndex];
this.Location = new Point(screen.Bounds.Left, screen.Bounds.Top);
this.WindowState = FormWindowState.Normal;
this.WindowState = FormWindowState.Maximized;
string text ="名称:"+ screen.DeviceName+"\r\n";
// text += "X:" + screen.Bounds.X + "\r\n";
// text += "Y:" + screen.Bounds.Y+ "\r\n";
text += "Width:" + screen.Bounds.Width+ "\r\n";
text += "Heigh:" + screen.Bounds.Height+ "\r\n";
text += "是否主显示器:"+screen.Primary.ToString() + "\r\n";
lblInfo.Text = text;
SWidth = screen.Bounds.Width;
SHeight = screen.Bounds.Height;
}
comboBox1.SelectedIndex = 0;
btnColor.Text = "颜色:" + CurrColor.Name + "";
btnColor.BackColor = CurrColor;
}
private int SWidth = 0;
private int SHeight = 0;
private void FrmScreenTest_Shown(object sender, EventArgs e)
{
}
private int index = 0;
private bool isInProcess = false;
private void button1_Click(object sender, EventArgs e)
{
if (isInProcess)
{
return;
}
isInProcess = true;
btnDraw.Enabled = false;
int jianju = FormUtil.GetIntValue(txtJianJu);
int size = FormUtil.GetIntValue(txtSize);
int xCount = SWidth / (jianju + size);
int yCount = SHeight / (jianju + size);
Graphics g = panel1.CreateGraphics();
System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Lime);//画刷
int x = index % 20 * jianju;
int y = index / 20 * jianju;
g.FillEllipse(myBrush, new Rectangle(x, y, size, size));//画实心椭圆
// g.FillEllipse(myBrush, new Rectangle(x, y, size, size));//画实心椭圆
//Font myFont = new Font("宋体", size, FontStyle.Bold);
//Brush bush = new SolidBrush(Color.Red);//填充的颜色
//g.DrawString("测试", myFont, bush, x, y);
g.Dispose();
index++;
isInProcess = false;
btnDraw.Enabled = true;
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnClear_Click(object sender, EventArgs e)
{
index = 0;
Graphics g = this.panel1.CreateGraphics();
g.Clear(Color.Black);
g.Dispose();//释放资源
// this.TransparencyKey = this.panel1.BackColor;
}
private void button1_Click_1(object sender, EventArgs e)
{
if (isInProcess)
{
return;
}
isInProcess = true;
btnDraw.Enabled = false;
btnClear_Click(null, null);
int jianju = FormUtil.GetIntValue(txtJianJu);
int size = FormUtil.GetIntValue(txtSize);
int type = comboBox1.SelectedIndex;
int xCount = SWidth / (jianju + size)+1;
int yCount = SHeight / (jianju + size)+1;
Graphics g = panel1.CreateGraphics();
int allCount = xCount * yCount;
System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(CurrColor);//画刷
Pen pen = new Pen(CurrColor, 1);
for (int i = 0; i < allCount; i++)
{
int x = i % xCount * (jianju+size);
int y =( i / xCount) * (jianju + size);
if (type.Equals(0))
{
g.FillEllipse(myBrush, new Rectangle(x, y, size, size));//画实心椭圆
}else if (type.Equals(1))
{
g.DrawRectangle(pen, x, y, size, size);
}
else if (type.Equals(2))
{
g.DrawEllipse(pen, x, y, size, size);
}else if (type.Equals(3))
{
g.DrawLine(pen, new Point(x - size, y), new Point(x + size, y));
g.DrawLine(pen, new Point(x, y - size), new Point(x, y + size));
}
}
g.Dispose();
index++;
isInProcess = false;
btnDraw.Enabled = true;
}
private Color CurrColor = Color.White;
private void btnColor_Click(object sender, EventArgs e)
{
colorDialog1.Color = CurrColor;
colorDialog1.ShowDialog();
CurrColor = colorDialog1.Color;
btnColor.Text = "颜色:" + CurrColor.Name + "";
btnColor.BackColor = CurrColor;
}
}
}