クラスからオブジェクトTextBox
にアクセスしようとしています。私はコンストラクタを使ってみましたが、何も起こりませんでした。パネルを追加してさらにフォームを追加するまでは機能していました。私のフォームをロードC#クラスのオブジェクトにアクセスできない
私のメインフォーム:ここ
public partial class MenuForm : Form
{
public MenuForm()
{
InitializeComponent();
}
ConfigForm Config = new ConfigForm();
GeneralForm General = new GeneralForm();
private void Menu_Load(object sender, EventArgs e)
{
//Load of Config Form
Config.MdiParent = this.MdiParent;
Config.Show();
//Load of General Form
General.Show();
General.TopLevel = false;
Config.Controls["panel1"].Controls.Add(General);
}
}
が私のconfig形式である:ここで
public partial class ConfigForm : Form
{
private ConfigFormHelper confighelper = null;
private GeneralFormHelper generalhelper = new GeneralFormHelper();
public ConfigForm()
{
InitializeComponent();
}
private void comboTemplate_SelectedIndexChanged(object sender, EventArgs e)
{
generalhelper.LoadTemplate();
}
}
は私の一般的なヘルパークラスである:
class GeneralFormHelper
{
GeneralForm generalform2 = new GeneralForm();
public void LoadConfig()
{
this.generalform2.txtDSN1.Text = "test";
}
}
エラーはありませんが、 txtDSN1
は「テスト」テキストを取得しません。
txtDSN1
は、public
修飾子にあります。
現在表示されているインスタンスとは別の、別のインスタンスのテキストボックスを設定しています。あなたは 'Config.Show();'を表示し、もう一つはGeneralFormHelper: 'GeneralForm generalform2 = new GeneralForm();' –
でこれを見て、この行をMainForm: 'GeneralForm General = new GeneralForm(); 'public GeneralForm myForm; public GeneralFormHelper(GeneralFormフォーム) { this.myForm = form; } これは間違いありませんか? – FatalError
デザインを再設計します。 @RezaAghaeiが述べたように、あなたは 'GeneralForm'に対して複数のインスタンスを持ち、' GeneralFormHelper.LoadConfig() 'はあなたが提供したコードでは使われていないようです。 –