プログラムを書き換え、再度投稿させて頂きました。
線を描くプログラムを例に質問させて頂きます。
1.Form1のpicturebox1に「Draw.drawline」メソッドから線を描きます。
2.button1を押すと、Form2が表示される。
3.Form2のpicturebox2にForm1内の「Draw.draw_sen」メソッドを利用し線を描きたい
※(フォームが増えても同じことができるようにしたい)。
フォーム間で引数を受け渡したいのですが、どのようにするのが一般的でしょうか?
また、今回引数が4つと少ないですが、これが、10~20と増えてきた時に何かいい方法はありますでしょうか?
ご指導ご鞭撻の程、よろしくお願い致します。
・Form1
public partial class Form1 : Form { int x1 = 20; int y1 = 20; int x2 = 100; int y2 = 100; Form2 fm2 = new Form2(); public Form1() { InitializeComponent(); } public void pictureBox1_Paint(object sender, PaintEventArgs e) { Draw.drawline(sender, e, x1, y1, x2, y2); } public void button1_Click(object sender, EventArgs e) { if (fm2.ShowDialog() == DialogResult.OK) { } } } // Drawクラスのメンバとし、Drawを静的インスタンス(static)をつける? public class Draw { public int _x1; public int _y1; public int _x2; public int _y2; public static void drawline(object sender, PaintEventArgs e, int x1, int y1, int x2, int y2) { Draw d = new Draw(); e.Graphics.DrawLine(Pens.Black, x1, y2, x2, y2); d._x1 = x1; d._y1 = y1; d._x2 = x2; d._y2 = y2; } }
・Form2
public partial class Form2 : Form { public Form2() { InitializeComponent(); } public void pictureBox1_Paint(object sender, PaintEventArgs e) { // どのようにして、x1, y1 , x2, y2 のデータを受け取り、Draw.drawlineメソッドにアクセスするかがわかりません。 // Draw.drawline(sender, e, x1, y1 , x2, y2); } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/10/22 04:13