|
皆様大変お世話になっております。
皆様のお答え・アドバイスのおかげで何とか形にすることができました。
まだまだ至らない点もあると思いますが、一応プログラムソースを貼らせて頂きます。
●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;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Collections;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
namespace test1
{
// 共通のDrawクラスを作成
public static class Draw
{
public static void draw(object sender, PaintEventArgs e, float x1, float y1, float x2, float y2)
{
e.Graphics.DrawLine(Pens.Green, x1, y1, x2, y2);
}
}
public partial class Form1 : Form
{
// Form2の宣言
Form2 fm2 = new Form2();
public float x1;
public float y1;
public float x2;
public float y2;
public Form1()
{
InitializeComponent();
}
public void pictureBox1_Paint(object sender, PaintEventArgs e)
{
yomikomi();
Draw.draw(sender,e,x1,y1,x2,y2);
}
public void yomikomi()
{
FileStream fs = new FileStream(@"c:\data\test1.dat", FileMode.Open, FileAccess.Read); // ファイルを開く
BinaryReader br = new BinaryReader(fs); // ファイルの読み取り
x1 = br.ReadSingle(); // 4バイト浮動小数点値を読み取り、4バイト進める
y1 = br.ReadSingle(); // //
x2 = br.ReadSingle(); // //
y2 = br.ReadSingle(); // //
fs.Close(); // ファイルを閉じる
}
private void button1_Click(object sender, EventArgs e)
{
fm2.set_textbox_form2(x1,y1,x2,y2);
if (fm2.ShowDialog() == DialogResult.OK)
{
kakikomi();
pictureBox1.Invalidate();
}
}
public void kakikomi()
{
using (BinaryWriter w = new BinaryWriter(File.OpenWrite(@"c:\data\test1.dat"))) // ファイルの書き込み
{
w.Write(fm2.pro._s_x1);
w.Write(fm2.pro._s_y1);
w.Write(fm2.pro._s_x2);
w.Write(fm2.pro._s_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;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Collections;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
namespace test1
{
public class Property
{
public float send_x1;
public float send_y1;
public float send_x2;
public float send_y2;
public float _s_x1
{
set { send_x1 = value; }
get { return send_x1; }
}
public float _s_y1
{
set { send_y1 = value; }
get { return send_y1; }
}
public float _s_x2
{
set { send_x2 = value; }
get { return send_x2; }
}
public float _s_y2
{
set { send_y2 = value; }
get { return send_y2; }
}
}
public partial class Form2 : Form
{
public Property pro = new Property();
public Form2()
{
InitializeComponent();
}
public void set_textbox_form2(float _x1 , float _y1, float _x2, float _y2)
{
textBox1.Text = _x1.ToString();
textBox2.Text = _y1.ToString();
textBox3.Text = _x2.ToString();
textBox4.Text = _y2.ToString();
}
private void pictureBox2_Paint(object sender, PaintEventArgs e)
{
Draw.draw(sender, e, pro.send_x1, pro.send_y1, pro.send_x2, pro.send_y2);
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
pro.send_x1 = float.Parse(textBox1.Text);
pictureBox2.Invalidate();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
pro.send_y1 = float.Parse(textBox2.Text);
pictureBox2.Invalidate();
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
pro.send_x2 = float.Parse(textBox3.Text);
pictureBox2.Invalidate();
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
pro.send_y2 = float.Parse(textBox4.Text);
pictureBox2.Invalidate();
}
}
}
|