質問編集履歴
2
無駄な部分削除 書式再修正 文章微調整
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,156 +1,145 @@
|
|
1
1
|
###前提・実現したいこと
|
2
2
|
塗りつぶした図形に枠線をつける
|
3
|
-
エクセルの[挿入][図形]で作成される
|
3
|
+
エクセルの[挿入][図形]で作成される図形を作成したい
|
4
4
|
|
5
5
|
よろしくお願いします。
|
6
6
|
###発生している問題・エラーメッセージ
|
7
7
|
|
8
|
-
塗りつぶした図形に対して線がかすれている
|
8
|
+
塗りつぶした図形に対して線がかすれている等
|
9
9
|
三角形は、補正値を入れることで対応したが他の多角形や円も綺麗に描画できないかと
|
10
|
+
|
10
11
|
###該当のソースコード
|
11
12
|
C#
|
12
13
|
```
|
13
14
|
public Form1()
|
14
|
-
|
15
|
+
{
|
15
|
-
|
16
|
+
InitializeComponent();
|
16
17
|
|
17
|
-
|
18
|
+
// 図形描画用パネル
|
18
|
-
|
19
|
+
Panel pZukei = new panel
|
19
|
-
pZukei.BackColor = System.Drawing.Color.Lime;
|
20
|
+
pZukei.BackColor = System.Drawing.Color.Lime;
|
20
|
-
|
21
|
+
pZukei.Location = new System.Drawing.Point(39, 177);
|
21
|
-
|
22
|
+
pZukei.Name = "userControl11";
|
22
|
-
|
23
|
+
pZukei.Size = new System.Drawing.Size(18, 18);
|
23
|
-
|
24
|
+
pZukei.TabIndex = 9;
|
24
|
-
|
25
|
+
pZukei.Visible = true;
|
25
26
|
|
26
|
-
|
27
|
+
// 高さ変更用
|
27
|
-
|
28
|
+
TextBox txtH=new TextBox();
|
28
|
-
|
29
|
+
this.txtH.Location = new System.Drawing.Point(110, 12);
|
29
|
-
|
30
|
+
this.txtH.Name = "txtH";
|
30
|
-
|
31
|
+
this.txtH.Size = new System.Drawing.Size(100, 19);
|
31
|
-
|
32
|
+
this.txtH.TabIndex = 0;
|
32
|
-
|
33
|
+
this.txtH.Text = "18";
|
33
|
-
|
34
|
+
this.txtH.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
|
34
|
-
|
35
|
+
TextBox txtW=new TextBox();
|
35
|
-
|
36
|
+
txtW.Location = new System.Drawing.Point(110, 37);
|
36
|
-
|
37
|
+
txtW.Name = "txtW";
|
37
|
-
|
38
|
+
txtW.Size = new System.Drawing.Size(100, 19);
|
38
|
-
|
39
|
+
txtW.TabIndex = 1;
|
39
|
-
|
40
|
+
txtW.Text = "18";
|
40
|
-
|
41
|
+
txtW.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
|
41
|
-
|
42
|
+
Button button1 =new Button();
|
42
|
-
|
43
|
+
button1.Location = new System.Drawing.Point(234, 12);
|
43
|
-
|
44
|
+
button1.Name = "button1";
|
44
|
-
|
45
|
+
button1.Size = new System.Drawing.Size(75, 23);
|
45
|
-
|
46
|
+
button1.TabIndex = 2;
|
46
|
-
|
47
|
+
button1.Text = "button1";
|
47
|
-
|
48
|
+
button1.UseVisualStyleBackColor = true;
|
48
|
-
|
49
|
+
button1.Click += new System.EventHandler(this.button1_Click);
|
49
|
-
|
50
|
+
this.Controls.Add(this.pZukei);
|
50
|
-
|
51
|
+
this.Controls.Add(this.txtH);
|
51
|
-
|
52
|
+
this.Controls.Add(this.txtW);
|
52
|
-
|
53
|
+
this.Controls.Add(this.button1);
|
53
|
-
|
54
|
+
}
|
54
55
|
|
56
|
+
// 図形描写
|
55
|
-
|
57
|
+
private void button1_Click(object sender, EventArgs e)
|
56
|
-
|
58
|
+
{
|
57
|
-
|
59
|
+
pZukei.Size = new Size(int.Parse(txtW.Text), int.Parse(txtH.Text));
|
60
|
+
// パネルの形を図形に合わせる
|
58
|
-
|
61
|
+
pZukei.Region = new Region(Sankaku(uZukei.Size));
|
59
|
-
|
62
|
+
pZukei.Refresh();
|
60
63
|
|
61
|
-
|
64
|
+
pZukei.BackgroundImage = gpLine(pZukei.Size);
|
62
|
-
|
65
|
+
}
|
63
66
|
|
67
|
+
// 図形描写
|
64
|
-
|
68
|
+
private GraphicsPath Sankaku(Size size)
|
65
|
-
|
69
|
+
{
|
66
|
-
|
70
|
+
GraphicsPath gPath = new GraphicsPath();
|
67
71
|
|
68
|
-
|
72
|
+
float fltWidth=0;
|
69
|
-
|
73
|
+
float fltHeight = 0;
|
70
|
-
|
74
|
+
float fltWidth2 = 0;
|
71
|
-
|
75
|
+
float fltHeight2 = 0;
|
72
76
|
|
73
|
-
|
77
|
+
PointF[] pntPos=new PointF[3];// 図形の点の位置
|
74
78
|
|
75
|
-
|
79
|
+
fltWidth = size.Width;
|
76
|
-
|
80
|
+
fltHeight = size.Height;
|
77
|
-
|
81
|
+
fltWidth2 = (float)(size.Width / 2.0);
|
78
|
-
|
82
|
+
fltHeight2 = (float)(size.Height / 2.0);
|
79
83
|
|
80
|
-
|
84
|
+
pntPos[0].X = 0;
|
81
|
-
|
85
|
+
pntPos[0].Y = fltHeight;
|
82
|
-
|
86
|
+
pntPos[1].X = fltWidth2;
|
83
|
-
|
87
|
+
pntPos[1].Y = 0;
|
84
|
-
|
88
|
+
pntPos[2].X = fltWidth;
|
85
|
-
|
89
|
+
pntPos[2].Y = fltHeight;
|
86
90
|
|
87
|
-
|
91
|
+
gPath.AddPolygon(pntPos);
|
88
92
|
|
89
93
|
|
90
|
-
|
94
|
+
return gPath;
|
91
|
-
|
95
|
+
}
|
92
|
-
|
96
|
+
// 線描写
|
93
97
|
private Image gpLine(Size size)
|
94
|
-
|
98
|
+
{
|
95
|
-
|
99
|
+
//描画先とするImageオブジェクトを作成する
|
96
100
|
|
97
|
-
|
101
|
+
PointF[] ptan = null;
|
98
|
-
|
102
|
+
Bitmap canvas = new Bitmap(size.Width, size.Height);
|
99
103
|
|
100
|
-
|
104
|
+
//ImageオブジェクトのGraphicsオブジェクトを作成する
|
101
|
-
|
105
|
+
Graphics gPath = Graphics.FromImage(canvas);
|
102
106
|
|
103
|
-
|
107
|
+
float fltWidth = 0;
|
104
|
-
|
108
|
+
float fltHeight = 0;
|
105
|
-
|
109
|
+
float fltWidth2 = 0;
|
110
|
+
|
111
|
+
fltWidth = (float)size.Width - (float)1;
|
106
|
-
|
112
|
+
fltHeight = (float)size.Height - (float)0.5;
|
107
113
|
|
108
|
-
fltWidth = (float)size.Width - (float)1;
|
109
|
-
fltHeight = (float)size.Height - (float)0.5;
|
110
|
-
|
111
|
-
|
114
|
+
fltWidth2 = (float)(size.Width / 2.0);// 三角の上の横位置
|
112
|
-
|
113
115
|
|
114
|
-
|
116
|
+
ptan = new PointF[3];
|
115
117
|
|
116
|
-
|
118
|
+
//Penオブジェクトの作成(幅2黒色)
|
117
|
-
|
119
|
+
Pen p = new Pen(Color.Black, 2);
|
118
|
-
ptan[0].X = (float)0;
|
119
|
-
ptan[0].Y = (float)size.Height ;
|
120
120
|
|
121
|
-
|
121
|
+
ptan[0].X = (float)0;
|
122
|
-
|
122
|
+
ptan[0].Y = (float)size.Height ;
|
123
123
|
|
124
|
+
ptan[1].X = (float)size.Width ;
|
125
|
+
ptan[1].Y = (float)size.Height ;
|
124
126
|
|
125
|
-
|
127
|
+
ptan[2].X = (float)size.Width / (float)2;
|
126
|
-
|
128
|
+
ptan[2].Y = (float)0;
|
127
129
|
|
128
|
-
|
130
|
+
gPath.DrawPolygon(p, ptan);
|
129
|
-
//左の線
|
130
|
-
|
131
|
-
//gPath.DrawLine(p, (float)0.5, fltHeight, fltWidth2, (float)0.5);
|
132
131
|
|
133
|
-
////p = new Pen(Color.Blue , 2);
|
134
|
-
//// 右の線
|
135
|
-
//gPath.DrawLine(p, fltWidth2,(float)0.5, fltWidth, fltHeight);
|
136
|
-
|
137
|
-
////p = new Pen(Color.Red, 3);
|
138
|
-
//// 下線
|
139
|
-
//gPath.DrawLine(p, fltWidth, fltHeight, (float)0.5, fltHeight);
|
140
|
-
|
141
|
-
|
132
|
+
//リソースを解放する
|
142
|
-
|
133
|
+
gPath.Dispose();
|
143
|
-
|
134
|
+
//PictureBox1に表示する
|
144
|
-
|
135
|
+
return canvas;
|
145
|
-
|
146
|
-
|
147
|
-
|
136
|
+
}
|
148
137
|
```
|
149
138
|
###試したこと
|
150
139
|
それぞれの頂点の座標をずらすことを試したが
|
151
|
-
1図形に対して調整が
|
140
|
+
1図形に対して個々に調整が必要になります(図形の形、大きさ等)
|
152
|
-
変わってしまいます。
|
153
141
|
|
142
|
+
|
154
143
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
155
144
|
Microsoft Visual Studio 2008
|
156
145
|
C#にて作成
|
1
タグ追加 書式修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
三角形は、補正値を入れることで対応したが他の多角形や円も綺麗に描画できないかと
|
10
10
|
###該当のソースコード
|
11
11
|
C#
|
12
|
+
```
|
12
13
|
public Form1()
|
13
14
|
{
|
14
15
|
InitializeComponent();
|
@@ -144,7 +145,7 @@
|
|
144
145
|
|
145
146
|
|
146
147
|
}
|
147
|
-
|
148
|
+
```
|
148
149
|
###試したこと
|
149
150
|
それぞれの頂点の座標をずらすことを試したが
|
150
151
|
1図形に対して調整が難しい複数の図形大きさなどにより
|