質問するログイン新規登録

質問編集履歴

5

pictureboxをひとつに変更した最新コードへ更新

2019/06/06 07:39

投稿

dendenmushi
dendenmushi

スコア98

title CHANGED
File without changes
body CHANGED
@@ -10,14 +10,63 @@
10
10
  画像をローカルからD&Dでアプリ側で表示し、その上でD&Dをした際に四角形は出現して枠組みまではできますが、その際に下の表示されている画像が消えてしまいます。
11
11
 
12
12
 
13
+ ###コード
14
+ わかりづらくなってしまうので当初のpicturebox2つ使おうとしていたコードは削除しました。
13
15
 
14
- Form1.cs
16
+ ### 試したこと
17
+
18
+ paintイベントの中にgraphics含め描画のメソッドを入れていくことも行いましたが、paintの外側にあるマウスダウンイベントなどの中でメソッド呼び込みをどうしたらよいかわからず、そもそもpaintイベントの中にマウスイベントじたいも入れ込まなければいけないのかいろいろなサイトや書籍(C#)を見てますが、解決できませんでした。
19
+ 参考サイト:
20
+ [PictureBoxに線が描けません。](https://teratail.com/questions/28653)
21
+ [ラバーランドでのドラッグ範囲の切り抜き](https://teratail.com/questions/14079)
22
+ [基本描画画像が消える](http://www110.kir.jp/csharp/chip0231.html)
23
+ [イメージプロパティによくある勘違い](https://dobon.net/vb/dotnet/graphics/pictureboximageanddrawimage.html)
24
+
25
+ pictureboxを2つ重ねて上側を透過trancerateをbackcolorを選択しても四角形描画が始まるとはじめの画像表示は消えてしまいました。
26
+ あと試していない(できなかった)のはpictureboxを2つ作り、親子の関係にして上のを透過させる方法です。
27
+ 最終的には四角形で切り抜き保存までを行いたいだけです。
28
+ かなり苦戦しております。どなたかご教授頂けないでしょうか。
29
+
30
+
31
+ ###その後試したこと
32
+ 親子関係を作りpicturebox2の方を透過で四角を描けるようにしました。
15
33
  ```C#
34
+ public Form1()
35
+ {
36
+ InitializeComponent();
37
+ //プロパティの設定変更
38
+ pictureBox1.AllowDrop = true;
39
+ //描画先とするImageオブジェクトを作成する
40
+ bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
41
+
42
+ pictureBox2.BackColor = Color.Transparent;
43
+ pictureBox2.Parent = pictureBox1;
44
+ pictureBox2.Location = new Point(0, 0);
45
+
46
+ }
47
+ ```
48
+
49
+ それでも画像の方は四角指定の際のD&Dで消えてしまいました。
50
+
51
+ ###現状(令和元年6月6日)
52
+ デザイン…picture1の上にあえてpicture2をずらして上に置いています。テストのため。
53
+ ![イメージ説明](8b4ac5cabe0e8222cd161612132d5dfd.jpeg)
54
+ ドラッグ中…はじめに置いた画像picture1がpicture2が出てきたことで上半分欠ける(子の透過ができていない)
55
+ ![イメージ説明](2f221ae301b56fd6f1b947ae2e59e3a3.png)
56
+ ドロップ後…四角形は最終的に目当てと違う場所に残ったが意図しない場所(picuture2だが座標がおかしい)
57
+ ![イメージ説明](9fdc46f8e7710fa4f224f02f315ac27f.png)
58
+
59
+
60
+ ###6月6日16時の時点での現状
61
+ ・なんとか元画像の上に四角枠を表示することができました。ありがとうございます。
62
+ ・残りの課題は、四角の表示される位置が非常にずれています。
63
+ ```C#
16
64
  using System;
17
65
  using System.Collections.Generic;
18
66
  using System.ComponentModel;
19
67
  using System.Data;
20
68
  using System.Drawing;
69
+ using System.Drawing.Imaging;
21
70
  using System.IO;
22
71
  using System.Linq;
23
72
  using System.Text;
@@ -29,16 +78,11 @@
29
78
  {
30
79
  public partial class Form1 : Form
31
80
  {
32
-
33
- private string editFilePath = "";
34
- private bool dirtyFlag = false;
35
- private bool readOnlyFlag = false;
36
-
37
- //Form2から
38
81
  Point MD = new Point();
39
82
  Point MU = new Point();
40
83
  Bitmap bmp;
41
- Bitmap bitmap;//20190605
84
+ Bitmap backgroundBitmap;//20190605
85
+ Bitmap offscreenBitmap;
42
86
  bool view = false;
43
87
 
44
88
 
@@ -49,102 +93,25 @@
49
93
  pictureBox1.AllowDrop = true;
50
94
  //描画先とするImageオブジェクトを作成する
51
95
  bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
52
-
53
- pictureBox2.BackColor = Color.Transparent;
54
- pictureBox2.Parent = pictureBox1;
55
- pictureBox2.Location = new Point(0, 0);
56
-
57
96
  }
58
- /*
59
- private void textBox1_DragDrop(object sender, DragEventArgs e)
60
- {
61
- string[] dlagFilePathArray = (string[])e.Data.GetData(DataFormats.FileDrop, false);
62
-
63
- //複数のファイルがドラックされた場合、パスが配列として取得されるが、
64
- //今回のアプリケーションは TextBox が 1 つしかないため、先頭の
65
- //ファイルのみを扱う
66
- string filePath = dlagFilePathArray[0];
67
-
68
- //ファイルがテキスト形式でオープン可能なものかどうか確認
69
- if (CheckFileType(filePath))
70
- {
71
- //ファイルの内容を TextBox にロード
72
- textBox1.Text = File.ReadAllText(filePath, Encoding.Default);
73
-
74
- //フォームのタイトル部分にファイル名を表示
75
- this.Text = GetFileNameString(filePath, '\');
76
- editFilePath = filePath;
77
- setDirty(false);
78
-
79
- }
80
-
81
-
82
- }*/
83
- /*
84
- private void setDirty(bool flag)
85
- {
86
- dirtyFlag = flag;
87
- //読み取り専用でファイルがオープンされている場合、
88
- //[上書き(&S)] メニューアイテムは常に無効
89
- //menuSave.Enabled = (readOnlyFlag) ? false : flag;
90
- }
91
-
92
- //ドロップファイルがオープン可能なものであるかどうかをチェックする関数
93
- private bool CheckFileType(string filePath)
94
- {
95
- //読み込みを許可するファイルの拡張子を指定 (app.config に定義した方が本当は便利)
96
- string[] extnArray = { "txt", "cs", "vb", "htm", "html", "xml", "csv", "js", "vbs", "wsh" };
97
- foreach (string extn in extnArray)
98
- {
99
- int dotLen = extn.Length;
100
- if (extn == filePath.Substring(filePath.Length - dotLen, dotLen))
101
- {
102
- return true;
103
- }
104
- }
105
- return false;
106
- }
107
-
108
- private void textBox1_DragEnter(object sender, DragEventArgs e)
109
- {
110
- //ドラッグされたのがファイルであるか確認
111
- if (e.Data.GetDataPresent(DataFormats.FileDrop))
112
- //ドラッグされたデータを受け取る
113
- e.Effect = DragDropEffects.All;
114
- else
115
- //ドラッグされたデータを受け取らない
116
- e.Effect = DragDropEffects.None;
117
- }
118
-
119
- //フルパスからファイル名のみを取り出す関数
120
- private string GetFileNameString(string filePath, char separateChar)
121
- {
122
- try
123
- {
124
- string[] strArray = filePath.Split(separateChar);
125
- return strArray[strArray.Length - 1];
126
- }
127
- catch
128
- { return ""; }
129
- }
130
- */
131
97
  private void pictureBox1_DragDrop(object sender, DragEventArgs e)
132
98
  {
133
99
  string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, false);
134
100
  for (int i = 0; i < files.Length; i++)
135
101
  {
136
102
  string fileName = files[i];
137
- //textBox1.Text += fileName + "\r\n";
138
103
 
139
104
  string filename = ((string[])e.Data.GetData(DataFormats.FileDrop))[0];
140
- //Bitmap bitmap = null;
141
- bitmap = new Bitmap(filename);
105
+ backgroundBitmap = new Bitmap(filename);
106
+ offscreenBitmap = new Bitmap(backgroundBitmap);//tuika15
142
107
 
108
+
109
+ Console.WriteLine("offscreenBitmap:" + offscreenBitmap);
110
+
143
111
  //表示方法をzoomにする
144
112
  pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
145
113
 
146
- pictureBox1.Image = bitmap;
114
+ pictureBox1.Image = offscreenBitmap;
147
-
148
115
  }
149
116
  }
150
117
 
@@ -154,8 +121,6 @@
154
121
  e.Effect = DragDropEffects.Copy;
155
122
  }
156
123
 
157
-
158
- //以下はForm2から
159
124
  private void GetRegion(Point p1, Point p2, ref Point start, ref Point end)
160
125
  {
161
126
  start.X = Math.Min(p1.X, p2.X);
@@ -174,41 +139,37 @@
174
139
  {
175
140
  Pen blackPen = new Pen(Color.Black);
176
141
  Console.WriteLine(bmp);
177
- Console.WriteLine(bitmap);
142
+ Console.WriteLine(offscreenBitmap);
178
- if (bitmap != null)
179
- {
180
- Graphics g = Graphics.FromImage(bitmap);
181
143
 
144
+ Graphics g = Graphics.FromImage(offscreenBitmap);
145
+
182
146
  // 描画する線を点線に設定
183
147
  blackPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
184
148
 
185
149
  // 画面を消去
186
150
  g.Clear(SystemColors.Control);
187
151
 
188
- // 領域を描画
189
152
  g.DrawRectangle(blackPen, start.X, start.Y, GetLength(start.X, end.X), GetLength(start.Y, end.Y));
190
-
153
+
191
154
  g.Dispose();
192
- }
193
155
  }
194
156
 
195
- private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
157
+ private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
196
158
  {
197
159
  // 描画フラグON
198
160
  view = true;
199
- //pictureBox2.BackColor = Color.Transparent;
200
161
 
201
162
  // Mouseを押した座標を記録
202
163
  MD.X = e.X;
203
164
  MD.Y = e.Y;
204
165
  }
205
166
 
206
- private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
167
+ private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
207
168
  {
169
+
208
170
  Point p = new Point();
209
171
  Point start = new Point();
210
172
  Point end = new Point();
211
- //BackColor = Color.Transparent;
212
173
 
213
174
  // 描画フラグcheck
214
175
  if (view == false)
@@ -223,26 +184,31 @@
223
184
  // 座標から(X,Y)座標を計算
224
185
  GetRegion(MD, p, ref start, ref end);
225
186
 
226
- //System.Diagnostics.Debug.WriteLine("Move ({0},{1})", e.X, e.Y);
227
-
228
187
  // 領域を描画
229
188
  DrawRegion(start, end);
230
189
 
190
+ //backの画像表示方法指定
191
+ pictureBox1.BackgroundImageLayout = ImageLayout.Zoom;
192
+ //初めにとっておいた背景bitmapを表示
193
+ pictureBox1.BackgroundImage = backgroundBitmap;
194
+ //bitmapの透過
195
+ offscreenBitmap.MakeTransparent();
196
+
231
- //PictureBox1に表示する
197
+ //Imageを表示
232
- pictureBox2.Image = bitmap;
198
+ pictureBox1.Image = offscreenBitmap;
233
199
  }
234
200
 
235
- private void pictureBox2_MouseUp(object sender, MouseEventArgs e)
201
+ private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
236
202
  {
203
+
237
204
  Point start = new Point();
238
205
  Point end = new Point();
239
206
 
207
+
240
- // Mouseを離した座標を記録
208
+ // Mouseを離し た座標を記録
241
209
  MU.X = e.X;
242
210
  MU.Y = e.Y;
243
211
 
244
- //System.Diagnostics.Debug.WriteLine("MouseUp({0},{1})->({2},{3})", MD.X, MD.Y, MU.X, MU.Y);
245
-
246
212
  // 座標から(X,Y)座標を計算
247
213
  GetRegion(MD, MU, ref start, ref end);
248
214
 
@@ -250,7 +216,6 @@
250
216
  DrawRegion(start, end);
251
217
 
252
218
  //PictureBox1に表示する
253
- pictureBox2.Image = bmp;
254
219
 
255
220
  // 描画フラグOFF
256
221
  view = false;
@@ -258,51 +223,4 @@
258
223
  }
259
224
  }
260
225
  ```
261
-
262
-
263
-
264
-
265
-
266
-
267
- ### 試したこと
268
-
269
- paintイベントの中にgraphics含め描画のメソッドを入れていくことも行いましたが、paintの外側にあるマウスダウンイベントなどの中でメソッド呼び込みをどうしたらよいかわからず、そもそもpaintイベントの中にマウスイベントじたいも入れ込まなければいけないのかいろいろなサイトや書籍(C#)を見てますが、解決できませんでした。
270
- 参考サイト:
271
- [PictureBoxに線が描けません。](https://teratail.com/questions/28653)
272
- [ラバーランドでのドラッグ範囲の切り抜き](https://teratail.com/questions/14079)
273
- [基本描画画像が消える](http://www110.kir.jp/csharp/chip0231.html)
274
- [イメージプロパティによくある勘違い](https://dobon.net/vb/dotnet/graphics/pictureboximageanddrawimage.html)
275
-
276
- pictureboxを2つ重ねて上側を透過trancerateをbackcolorを選択しても四角形描画が始まるとはじめの画像表示は消えてしまいました。
277
- あと試していない(できなかった)のはpictureboxを2つ作り、親子の関係にして上のを透過させる方法です。
278
- 最終的には四角形で切り抜き保存までを行いたいだけです。
279
- かなり苦戦しております。どなたかご教授頂けないでしょうか。
280
-
281
-
282
- ###その後試したこと
283
- 親子関係を作りpicturebox2の方を透過で四角を描けるようにしました。
284
- ```C#
285
- public Form1()
286
- {
287
- InitializeComponent();
288
- //プロパティの設定変更
289
- pictureBox1.AllowDrop = true;
290
- //描画先とするImageオブジェクトを作成する
291
- bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
292
-
293
- pictureBox2.BackColor = Color.Transparent;
294
- pictureBox2.Parent = pictureBox1;
295
- pictureBox2.Location = new Point(0, 0);
296
-
297
- }
298
- ```
299
-
300
- それでも画像の方は四角指定の際のD&Dで消えてしまいました。
301
-
302
- ###現状(令和元年6月6日)
303
- デザイン…picture1の上にあえてpicture2をずらして上に置いています。テストのため。
304
- ![イメージ説明](8b4ac5cabe0e8222cd161612132d5dfd.jpeg)
305
- ドラッグ中…はじめに置いた画像picture1がpicture2が出てきたことで上半分欠ける(子の透過ができていない)
306
- ![イメージ説明](2f221ae301b56fd6f1b947ae2e59e3a3.png)
226
+ ![イメージ説明](61ceb0c937c6b928bcf8a8b047a8c585.png)
307
- ドロップ後…四角形は最終的に目当てと違う場所に残ったが意図しない場所(picuture2だが座標がおかしい)
308
- ![イメージ説明](9fdc46f8e7710fa4f224f02f315ac27f.png)

4

現状報告のデザイン追記

2019/06/06 07:39

投稿

dendenmushi
dendenmushi

スコア98

title CHANGED
File without changes
body CHANGED
@@ -300,6 +300,8 @@
300
300
  それでも画像の方は四角指定の際のD&Dで消えてしまいました。
301
301
 
302
302
  ###現状(令和元年6月6日)
303
+ デザイン…picture1の上にあえてpicture2をずらして上に置いています。テストのため。
304
+ ![イメージ説明](8b4ac5cabe0e8222cd161612132d5dfd.jpeg)
303
305
  ドラッグ中…はじめに置いた画像picture1がpicture2が出てきたことで上半分欠ける(子の透過ができていない)
304
306
  ![イメージ説明](2f221ae301b56fd6f1b947ae2e59e3a3.png)
305
307
  ドロップ後…四角形は最終的に目当てと違う場所に残ったが意図しない場所(picuture2だが座標がおかしい)

3

現状画像追加(元コード間違えあったのでpicture指定修正)

2019/06/05 21:38

投稿

dendenmushi
dendenmushi

スコア98

title CHANGED
File without changes
body CHANGED
@@ -49,7 +49,85 @@
49
49
  pictureBox1.AllowDrop = true;
50
50
  //描画先とするImageオブジェクトを作成する
51
51
  bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
52
+
53
+ pictureBox2.BackColor = Color.Transparent;
54
+ pictureBox2.Parent = pictureBox1;
55
+ pictureBox2.Location = new Point(0, 0);
56
+
52
57
  }
58
+ /*
59
+ private void textBox1_DragDrop(object sender, DragEventArgs e)
60
+ {
61
+ string[] dlagFilePathArray = (string[])e.Data.GetData(DataFormats.FileDrop, false);
62
+
63
+ //複数のファイルがドラックされた場合、パスが配列として取得されるが、
64
+ //今回のアプリケーションは TextBox が 1 つしかないため、先頭の
65
+ //ファイルのみを扱う
66
+ string filePath = dlagFilePathArray[0];
67
+
68
+ //ファイルがテキスト形式でオープン可能なものかどうか確認
69
+ if (CheckFileType(filePath))
70
+ {
71
+ //ファイルの内容を TextBox にロード
72
+ textBox1.Text = File.ReadAllText(filePath, Encoding.Default);
73
+
74
+ //フォームのタイトル部分にファイル名を表示
75
+ this.Text = GetFileNameString(filePath, '\');
76
+ editFilePath = filePath;
77
+ setDirty(false);
78
+
79
+ }
80
+
81
+
82
+ }*/
83
+ /*
84
+ private void setDirty(bool flag)
85
+ {
86
+ dirtyFlag = flag;
87
+ //読み取り専用でファイルがオープンされている場合、
88
+ //[上書き(&S)] メニューアイテムは常に無効
89
+ //menuSave.Enabled = (readOnlyFlag) ? false : flag;
90
+ }
91
+
92
+ //ドロップファイルがオープン可能なものであるかどうかをチェックする関数
93
+ private bool CheckFileType(string filePath)
94
+ {
95
+ //読み込みを許可するファイルの拡張子を指定 (app.config に定義した方が本当は便利)
96
+ string[] extnArray = { "txt", "cs", "vb", "htm", "html", "xml", "csv", "js", "vbs", "wsh" };
97
+ foreach (string extn in extnArray)
98
+ {
99
+ int dotLen = extn.Length;
100
+ if (extn == filePath.Substring(filePath.Length - dotLen, dotLen))
101
+ {
102
+ return true;
103
+ }
104
+ }
105
+ return false;
106
+ }
107
+
108
+ private void textBox1_DragEnter(object sender, DragEventArgs e)
109
+ {
110
+ //ドラッグされたのがファイルであるか確認
111
+ if (e.Data.GetDataPresent(DataFormats.FileDrop))
112
+ //ドラッグされたデータを受け取る
113
+ e.Effect = DragDropEffects.All;
114
+ else
115
+ //ドラッグされたデータを受け取らない
116
+ e.Effect = DragDropEffects.None;
117
+ }
118
+
119
+ //フルパスからファイル名のみを取り出す関数
120
+ private string GetFileNameString(string filePath, char separateChar)
121
+ {
122
+ try
123
+ {
124
+ string[] strArray = filePath.Split(separateChar);
125
+ return strArray[strArray.Length - 1];
126
+ }
127
+ catch
128
+ { return ""; }
129
+ }
130
+ */
53
131
  private void pictureBox1_DragDrop(object sender, DragEventArgs e)
54
132
  {
55
133
  string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, false);
@@ -118,6 +196,7 @@
118
196
  {
119
197
  // 描画フラグON
120
198
  view = true;
199
+ //pictureBox2.BackColor = Color.Transparent;
121
200
 
122
201
  // Mouseを押した座標を記録
123
202
  MD.X = e.X;
@@ -150,7 +229,7 @@
150
229
  DrawRegion(start, end);
151
230
 
152
231
  //PictureBox1に表示する
153
- pictureBox1.Image = bmp;
232
+ pictureBox2.Image = bitmap;
154
233
  }
155
234
 
156
235
  private void pictureBox2_MouseUp(object sender, MouseEventArgs e)
@@ -171,7 +250,7 @@
171
250
  DrawRegion(start, end);
172
251
 
173
252
  //PictureBox1に表示する
174
- pictureBox1.Image = bmp;
253
+ pictureBox2.Image = bmp;
175
254
 
176
255
  // 描画フラグOFF
177
256
  view = false;
@@ -218,4 +297,10 @@
218
297
  }
219
298
  ```
220
299
 
221
- それでも画像の方は四角指定の際のD&Dで消えてしまいました。
300
+ それでも画像の方は四角指定の際のD&Dで消えてしまいました。
301
+
302
+ ###現状(令和元年6月6日)
303
+ ドラッグ中…はじめに置いた画像picture1がpicture2が出てきたことで上半分欠ける(子の透過ができていない)
304
+ ![イメージ説明](2f221ae301b56fd6f1b947ae2e59e3a3.png)
305
+ ドロップ後…四角形は最終的に目当てと違う場所に残ったが意図しない場所(picuture2だが座標がおかしい)
306
+ ![イメージ説明](9fdc46f8e7710fa4f224f02f315ac27f.png)

2

現状ソースコードの修正と追加挑戦内容の追記

2019/06/05 21:36

投稿

dendenmushi
dendenmushi

スコア98

title CHANGED
File without changes
body CHANGED
@@ -29,6 +29,7 @@
29
29
  {
30
30
  public partial class Form1 : Form
31
31
  {
32
+
32
33
  private string editFilePath = "";
33
34
  private bool dirtyFlag = false;
34
35
  private bool readOnlyFlag = false;
@@ -48,9 +49,7 @@
48
49
  pictureBox1.AllowDrop = true;
49
50
  //描画先とするImageオブジェクトを作成する
50
51
  bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
51
-
52
52
  }
53
-
54
53
  private void pictureBox1_DragDrop(object sender, DragEventArgs e)
55
54
  {
56
55
  string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, false);
@@ -77,6 +76,8 @@
77
76
  e.Effect = DragDropEffects.Copy;
78
77
  }
79
78
 
79
+
80
+ //以下はForm2から
80
81
  private void GetRegion(Point p1, Point p2, ref Point start, ref Point end)
81
82
  {
82
83
  start.X = Math.Min(p1.X, p2.X);
@@ -110,13 +111,10 @@
110
111
  g.DrawRectangle(blackPen, start.X, start.Y, GetLength(start.X, end.X), GetLength(start.Y, end.Y));
111
112
 
112
113
  g.Dispose();
113
-
114
- //最後表示
115
- pictureBox1.Image = bitmap;
116
114
  }
117
115
  }
118
116
 
119
- private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
117
+ private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
120
118
  {
121
119
  // 描画フラグON
122
120
  view = true;
@@ -126,7 +124,7 @@
126
124
  MD.Y = e.Y;
127
125
  }
128
126
 
129
- private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
127
+ private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
130
128
  {
131
129
  Point p = new Point();
132
130
  Point start = new Point();
@@ -155,7 +153,7 @@
155
153
  pictureBox1.Image = bmp;
156
154
  }
157
155
 
158
- private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
156
+ private void pictureBox2_MouseUp(object sender, MouseEventArgs e)
159
157
  {
160
158
  Point start = new Point();
161
159
  Point end = new Point();
@@ -178,14 +176,8 @@
178
176
  // 描画フラグOFF
179
177
  view = false;
180
178
  }
181
-
182
- private void pictureBox1_Paint(object sender, PaintEventArgs e)
183
- {
184
-
185
- }
186
179
  }
187
180
  }
188
-
189
181
  ```
190
182
 
191
183
 
@@ -205,4 +197,25 @@
205
197
  pictureboxを2つ重ねて上側を透過trancerateをbackcolorを選択しても四角形描画が始まるとはじめの画像表示は消えてしまいました。
206
198
  あと試していない(できなかった)のはpictureboxを2つ作り、親子の関係にして上のを透過させる方法です。
207
199
  最終的には四角形で切り抜き保存までを行いたいだけです。
208
- かなり苦戦しております。どなたかご教授頂けないでしょうか。
200
+ かなり苦戦しております。どなたかご教授頂けないでしょうか。
201
+
202
+
203
+ ###その後試したこと
204
+ 親子関係を作りpicturebox2の方を透過で四角を描けるようにしました。
205
+ ```C#
206
+ public Form1()
207
+ {
208
+ InitializeComponent();
209
+ //プロパティの設定変更
210
+ pictureBox1.AllowDrop = true;
211
+ //描画先とするImageオブジェクトを作成する
212
+ bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
213
+
214
+ pictureBox2.BackColor = Color.Transparent;
215
+ pictureBox2.Parent = pictureBox1;
216
+ pictureBox2.Location = new Point(0, 0);
217
+
218
+ }
219
+ ```
220
+
221
+ それでも画像の方は四角指定の際のD&Dで消えてしまいました。

1

試そうとしてできなかったこと追記

2019/06/05 14:12

投稿

dendenmushi
dendenmushi

スコア98

title CHANGED
File without changes
body CHANGED
@@ -203,5 +203,6 @@
203
203
  [イメージプロパティによくある勘違い](https://dobon.net/vb/dotnet/graphics/pictureboximageanddrawimage.html)
204
204
 
205
205
  pictureboxを2つ重ねて上側を透過trancerateをbackcolorを選択しても四角形描画が始まるとはじめの画像表示は消えてしまいました。
206
+ あと試していない(できなかった)のはpictureboxを2つ作り、親子の関係にして上のを透過させる方法です。
206
207
  最終的には四角形で切り抜き保存までを行いたいだけです。
207
208
  かなり苦戦しております。どなたかご教授頂けないでしょうか。