English 中文(简体)
另一类[复制]的出入标签
原标题:Access label on one form from another class [duplicate]
This question already has answers here:
Closed 11 years ago.

Possible Duplicate:
Best way to access a control on another form in WinForms?

我知道这是一个盲目明显的问题,但我是一个新奇,认为它没有什么混淆,因此,任何帮助都将受到高度赞赏。

我有主文和第二稿,请将其称为2。 表格2中有一些标签。 我愿控制这些标签的案文。 不管我试图做什么,我看不到他们。 我已经将其中一些内容公开了,我仍然可以“见”这些内容。

主要表现是 w(与项目一样)。 形式2是一种固定的双赢形式。

如果有人要帮助我,我将永远感激。

感谢

问题回答

由于你的标签是私人的,只能从所有权人手中获取。 不要试图将其改变为公众,而是采取错误的做法(公共成员是邪恶)。

添加一种公开的方法,更新你的标签,以便从您的第二种形式中获取。

:

public void SetTextForLabel(string myText)
{
    this.myLabel.Text = myText;
}

主要形式:

myForm2Instance.SetTextForLabel("my text");




相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签