回答編集履歴
1
コード追加
test
CHANGED
@@ -11,3 +11,123 @@
|
|
11
11
|
まず、k構造体はForm1とForm2で共通化したいのですか?
|
12
12
|
|
13
13
|
であれば、Form1のメンバとしてkは保持しないようにして、Form1の各TextBoxが変更された時のセット対象はDraw静的インスタンス上のk静的プロパティにするべきです。
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
```C#
|
18
|
+
|
19
|
+
public partial class Form1 : Form
|
20
|
+
|
21
|
+
{
|
22
|
+
|
23
|
+
public Form1()
|
24
|
+
|
25
|
+
{
|
26
|
+
|
27
|
+
InitializeComponent();
|
28
|
+
|
29
|
+
}
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
private void pictureBox1_Paint(object sender, PaintEventArgs e)
|
34
|
+
|
35
|
+
{
|
36
|
+
|
37
|
+
//Draw.draw(sender, e, k);
|
38
|
+
|
39
|
+
Draw.draw(sender, e);
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
private void textBox1_TextChanged(object sender, EventArgs e)
|
46
|
+
|
47
|
+
{
|
48
|
+
|
49
|
+
//k.x1 = float.Parse(textBox1.Text);
|
50
|
+
|
51
|
+
Draw.k.x1 = float.Parse(textBox1.Text);
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
private void textBox2_TextChanged(object sender, EventArgs e)
|
58
|
+
|
59
|
+
{
|
60
|
+
|
61
|
+
//k.y1 = float.Parse(textBox2.Text);
|
62
|
+
|
63
|
+
Draw.k.y1 = float.Parse(textBox2.Text);
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
private void textBox3_TextChanged(object sender, EventArgs e)
|
70
|
+
|
71
|
+
{
|
72
|
+
|
73
|
+
//k.x2 = float.Parse(textBox3.Text);
|
74
|
+
|
75
|
+
Draw.k.x2 = float.Parse(textBox3.Text);
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
private void textBox4_TextChanged(object sender, EventArgs e)
|
82
|
+
|
83
|
+
{
|
84
|
+
|
85
|
+
//k.y2 = float.Parse(textBox4.Text);
|
86
|
+
|
87
|
+
Draw.k.y2 = float.Parse(textBox4.Text);
|
88
|
+
|
89
|
+
pictureBox1.Invalidate();
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
public class Kouzoutai
|
98
|
+
|
99
|
+
{
|
100
|
+
|
101
|
+
public float x1;
|
102
|
+
|
103
|
+
public float y1;
|
104
|
+
|
105
|
+
public float x2;
|
106
|
+
|
107
|
+
public float y2;
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
public static class Draw
|
114
|
+
|
115
|
+
{
|
116
|
+
|
117
|
+
public static Kouzoutai k; //静的インスタンスとして
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
//public static void draw(object sender, PaintEventArgs e, Kouzoutai k)
|
122
|
+
|
123
|
+
public static void draw(object sender, PaintEventArgs e)
|
124
|
+
|
125
|
+
{
|
126
|
+
|
127
|
+
e.Graphics.DrawLine(Pens.Green, k.x1, k.y1, k.x2, k.y2);
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
```
|