C#のクラスメソッドの返り値にラムダ式を設定し、その内で、Formのテキストボックスに文字を表示させようとしましたがうまくいきません。クラスの生成時に、Formのインスタンス(this)?を渡して、thisからテキストボックスを辿っています。
また、ラムダ式内で、テキストボックスに入れるにはどうしたら良いでしょうか?
意味のないコードかもしれませんが、理由を知りたいのでお願い致します。テキストボックスは、プロパテイmodifiersをpublicにしています。
namespace action_ramda_test {
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Person xs = new Person(this);
xs.writa("fgfgfg",this); } } public class Person { public Action sa; public Form1 ft; public string st; public Person(Form1 Ft) { ft = Ft; } public Person(Form1 Ft,string St,Action Sa) { ft = Ft; st = St; sa = Sa; } public Person writa(string msg, Form1 F1) { // F1.textBox1.Text = msg; //TextBoxにfgfgfgがはいる return new Person(F1,msg,() => { F1.textBox1.Text = msg; });//TextBoxにfgfgfgがはいらない } }
}
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/17 12:36