VisualStdio2013 C# windowsフォームアプリケーションでプログラムを組んでいます。
C# 構造体の設定・使用方法について という内容で以前質問させて頂きました。
https://teratail.com/questions/17083
構造体を
public struct Kouzoutai
{
public float x1;
public float y1;
public float x2;
public float y2;
}
から
class Kouzoutai
{
public float x1;
public float y1;
public float x2;
public float y2;
}
に変更しました。
以下のプログラムですと、
「public static void draw(object sender, PaintEventArgs e, Kouzoutai k)」で、
アクセシビリティに一貫性がありません。パラメーターの型 'test10.Kouzoutai' のアクセシビリティはメソッド 'test10.Draw.draw(object, System.Windows.Forms.PaintEventArgs, test10.Kouzoutai)' よりも低く設定されています。
というエラーが発生してしまいます。
根本的にプログラムの組み方が悪いのでしょうか?
プログラムの完成形は、以前の質問と同じでどのフォームからでも「public static class Draw」にアクセスできるようにし、
描画するのに必要な変数はまとめて構造体(クラス)で管理し、受け渡したいと思っております。
ご指導ご鞭撻の程よろしくお願い致します。
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(); } } 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);
}
}
}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/10/02 04:52
退会済みユーザー
2015/10/02 05:07