이것이 정말 간단하다고 확신하지만 Google에 적합한 문구를 찾을 수 없습니다.
트레이 응용 프로그램 인 응용 프로그램이 있습니다.
Main () 함수는 클래스의 인스턴스를 초기화합니다 CustomApplicationContext
.
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new CustomApplicationContext());
}
이 클래스에는 다음과 같은 기능이 있습니다.
public void DoRestart()
{
if (_DoRestartDialog == null)
{
using (_DoRestartDialog = new RestartDialog())
_DoRestartDialog.ShowDialog();
_DoRestartDialog = null;
}
else
_DoRestartDialog.Activate();
}
이 클래스에는 양식을 여는 함수도 있습니다.
protected override void OnTrayIconDoubleClick(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (_InfoDialog == null)
{
using (_InfoDialog = new InfoDialog())
_InfoDialog.ShowDialog();
_InfoDialog = null;
}
else
_InfoDialog.Activate();
}
base.OnTrayIconDoubleClick(e);
}
양식 내에는 버튼이 있습니다. 버튼을 클릭하면 기본 클래스에서 DoRestart 함수를 호출하고 싶습니다. 이 함수를 어떻게 참조합니까? 양식에서 액세스 할 수없는 것 같습니다.
인스턴스를에 직접 전달하는 대신 Run()
클래스 수준에서 먼저 저장합니다.
public static CustomApplicationContext App;
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
App = new CustomApplicationContext();
Application.Run(App);
}
이제 다음을 통해 액세스 할 수 있습니다.
Program.App.DoRestart();
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다