VisualStdio2013 C# windowsフォームアプリケーションでプログラムを組んでいます。
Form1のpicturebox1に始点(x1,y1)から終点(x2,y2)まで線を描画し、それをForm2のpicturebox2にも表示させるというプログラムを作成しております。
Form1 : picturebox1・textbox1~4・button1
Form2 : picturebox2
が設置されております。
Form1のpicturebox1に線を引くことができ、次にForm2のpicturebox2にForm1のDrawクラスを使い、線を引きたいのですが、線を引くために必要な構造体をどう受け取りどう利用できるのかわからず、線を引くことができません。
プログラムの完成形は、以前の質問と同じでどのフォームからでも「public static class Draw」にアクセスできるようにし、
描画するのに必要な変数はまとめて構造体(クラス)で管理し、受け渡したいと思っております。
● Form1
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;
namespace test10
{
public partial class Form1 : Form
{
Form2 fm2 = new Form2();
Kouzoutai k = new Kouzoutai(); public Form1() { InitializeComponent(); } private void pictureBox1_Paint(object sender, PaintEventArgs e) { Draw.draw(sender, e, k); } private void textBox1_TextChanged(object sender, EventArgs e) { k.x1 = float.Parse(textBox1.Text); } private void textBox2_TextChanged(object sender, EventArgs e) { k.y1 = float.Parse(textBox2.Text); } private void textBox3_TextChanged(object sender, EventArgs e) { k.x2 = float.Parse(textBox3.Text); } private void textBox4_TextChanged(object sender, EventArgs e) { k.y2 = float.Parse(textBox4.Text); pictureBox1.Invalidate(); } private void button1_Click(object sender, EventArgs e) { fm2.ShowDialog(); } } public class Kouzoutai { public float x1; public float y1; public float x2; public float y2; } public static class Draw { public static void draw(object sender, PaintEventArgs e, Kouzoutai k) { e.Graphics.DrawLine(Pens.Green, k.x1, k.y1, k.x2, k.y2); } }
}
● Form2
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;
namespace test10
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
// Kouzoutai k を引数として持たせると、Paintイベントが起こらなくなる・・・ // 引数として構造体を持たせるのは間違い? private void pictureBox2_Paint(object sender, PaintEventArgs e Kouzoutai k) { Draw.draw(sender, e, k); } }
}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/10/02 05:30 編集
2015/10/02 05:34
2015/10/02 06:02
2015/10/02 06:04
2015/10/02 06:18