gpt4 book ai didi

c# - Application.run(Windows) 与 Application.run()

转载 作者:可可西里 更新时间:2023-11-01 11:29:02 32 4
gpt4 key购买 nike

这三个代码有什么区别?

1.

Window a = new Window ();
a.Show (); // call show

Application b = new Application ();
b.Run (); // call without a

2.

Window a = new Window ();
// do not call show

Application b = new Application ();
b.Run (a); // with a

为什么两者都能正常工作?为什么也要这样做?3.

Window a = new Window ();
a.Show (); // call show and also call show bellow

Application b = new Application ();
b.Run (a); // with a

最佳答案

两者基本上都是为了消息循环,它是windows应用程序的核心,处理窗口消息,如绘画、鼠标/kbd事件等。

如果您使用下面的代码而不使用 Application.Run

Window a = new Window ();
a.Show ();

您会发现一个卡住的窗口,原因是没有人告诉该窗口重新绘制或处理任何事件。

因此,通过 Application.Run 调用消息循环,窗口开始按预期工作

Application b = new Application ();
b.Run (a); // with a

关于c# - Application.run(Windows) 与 Application.run(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25588726/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com