C# .NET はまだ新しいため、単純な (説明付き) が優先されます。:) いくつかのテキスト ボックスを含む Windows フォームがあります。これらのテキストボックスの内容を別のファイルで読み込めるようにしたい。 同様の問題をカバーする記事(ここでもstackoverflow)を見たことがありますが、私の場合は機能しません。必要なデータは、Form1 のテキスト ボックスにあります。このデータの移動先は -> myOtherCS で、メソッド (Savedoc) で使用されます。
Form1.cs には次のものがあります。
private myOtherCS allOtherMethods;
public static string myText= "";
public static string mytitle = "";
public Form1()
{
InitializeComponent();
allOtherMethods = new myOtherCS();
}
/* I would like the myText to be filled with the contents of Textbox1
* and mytitle to be filled with contents of Textbox2. Ideally when the
* Textboxes have been changed. */
private void TextBox1_TextChanged(object sender, EventArgs e)
{
myText = Textbox1.Text;
}
private void TextBox2_TextChanged(object sender, EventArgs e)
{
myTitle = Textbox2.Text;
}
myOtherCS ファイルでは、これらの値を別のメソッド内で使用できるようにしたいと考えています。したがって、最初におそらく「取得」および「設定」します。私は多くのことを試しましたが、ここに..アイデアを得るために..両方のファイルで変更を加える必要があることは知っていますが、これはアイデアを得るためのものです.
public class GetTextBoxes
{
private string title;
private string text;
public string Title
{
get { return title; }
set { title = value; }
}
public string Text
{
get { return text; }
set { text = value; }
}
}
public void SaveDoc()
{
GetTextBoxes.title;
GetTextBoxes.text;
}
これは、私がやりたいことを示すための PSEUDOcode です。私は多くのことを試しましたが、誰かがこれを行う方法を知っていれば、とても感謝しています! 前もって感謝します