-1

このコードを子フォームで使用します

MainMenu f = new MainMenu();
f.tbUserName.Text = "MY TEXT";

tbUserName にテキストを表示したいのですが、表示されません。

** このコードで新しいウィンドウを開きたくない

MainMenu f = new MainMenu();
f.Show();
4

1 に答える 1

0

That code won't work because you're creating a new instance of the object therefore only the new instance will be affected. If you want to affect an open window, make the Label static in the form.designer.cs file, like so:

private TextBox tbUserName;

becomes

public static TextBox tbUserName;

Then you remove remove "this." in front of any mention of "tbUserName".

this.tbUserName.Size = new Size();

becomes

tbUserName.Size = new Size();

And then in order to change the Label's text value, use the below statement.

MainMenu.tbUserName.Text = "MY TEXT";
于 2015-11-24T15:42:04.417 に答える