私は窓のフォームを持って、私の下のコードを使用したい私のヘルパークラスの中に。私はrichtextboxとtabControlモディファイアをpublicにしましたが、私のrichtextboxにはアクセスできません。 richTextBox1でエラーが発生する
The name richTextBox1 doesnt exist in the current context
私が間違っていることは何ですか?
ヘルパークラス</ strong>
List<string> commentLines = richTextBox1.Lines.ToList();
回答:
回答№1は0コードサンプルはかなり不完全ですが...
コードに応じて、RichTextBoxへの参照をメソッドコンストラクタまたはクラスコンストラクタに渡す必要があります。
// HelperClass method
public static void UpdateCommentLines(RichTextBox richTextBox)
{
List<string> commentLines = richTextBox.Lines.ToList();
}
// WinForm Code
public void DoSomething()
{
HelperClass.UpdateCommentLines(this.richTextBox1);
}