简体   繁体   English

Windows窗体仅刷新(渲染)按钮。按下任何其他按钮时可见。[c#]

[英]Windows Form only refreshes(rerenders) button.visible when any other button is pressed.[c#]

I have a main form called "Main" which dynamically resizes itself depending on what buttons are enabled. 我有一个名为“ Main”的主窗体,该窗体根据启用的按钮动态调整自身大小。 Inside of Main I also have a function called Updater. 在Main内部,我还有一个称为Updater的函数。 Updater reloads all the information from a file into memory, does a tiny bit of processing, and then 'should' refresh the window. Updater将文件中的所有信息重新加载到内存中,进行少量处理,然后“应该”刷新窗口。 This is the refreshing part: 这是令人耳目一新的部分:

Application.DoEvents();
this.Refresh();

Then I have another form that is a configuration page. 然后,我有另一个表单是配置页。 Simply opens up the same data file, lets the user change things, and saves it back. 只需打开相同的数据文件,让用户更改内容并将其保存回去即可。 Which then closes itself and runs Updater which should simply refresh the Main form with the new information. 然后,它会自行关闭并运行Updater,该更新程序应仅使用新信息刷新Main表单。 Here is the calling code: 这是调用代码:

Main main = new Main(); 
main.UpdaterCaller();

Now understand the new information is enabling and disabling buttons and positioning them. 现在了解新信息是启用和禁用按钮并对其进行定位。 I know this all works as when I ran it, i put a snippet of console code that lets me know it has run through it. 我知道这一切都是在我运行它时起作用的,我放了一段控制台代码,让我知道它已经运行了。 But when I close the configuration window, the console displays the message that is written within Updater(), but it doesn't show the changes on Main. 但是,当我关闭配置窗口时,控制台会显示写在Updater()中的消息,但不会显示Main上的更改。 Only when I click any other message does is instantly refresh with teh new buttons. 只有当我单击任何其他消息时,才会通过新按钮立即刷新。

Sorry if I wasn't specific enough or didn't use correct termonology. 抱歉,如果我不够具体或没有使用正确的术语。 Thanks for the help! 谢谢您的帮助!

You're problem is that the configuration page is creating a new instance of Main and updating that. 您的问题是配置页面正在创建Main的新实例并对其进行更新。 This instance is actually invisible since it has never been shown. 该实例实际上是不可见的,因为它从未显示过。

I'd simply display the configuration page via ShowDialog() and then have Main update itself once it's closed: 我只需要通过ShowDialog()显示配置页面,然后在关闭时让Main更新即可:

// ... this code is running in form Main ...
frmConfiguration config = new frmConfiguration();
config.ShowDialog(); // code here STOPS until "config" is closed
this.UpdaterCaller();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 c# windows 表单中使用定时器仅在按下按钮时才上下移动电梯? - How to use timer in c# windows form to move elevator up and down only when button is pressed? 如何在ASP.NET中按下按钮以隐藏其他浏览器的按钮(button.Visible) - How to press a button to hide the other browser's button in ASP.NET (button.Visible) 使用 WinForm "button.visible" 作为方法的参数 - Using WinForm "button.visible" as parameter to method Button.Visible = true; 在功能中激活时,无法将按钮设置为可见 - Button.Visible = true; fails to set the button to visible when activated within a function 按下Close,X,按钮时,不会调用OnClosing事件。 Windows Mobile - OnClosing event is not being called when Close, X, button is pressed. Windows Mobile 按下按钮时启用计时器C# - Enabling a timer when a button is pressed C# 按下按钮时,C#是否有任何方法可以执行Javascript函数? - Does C# has any methods to execute Javascript function when button is pressed? 当按下表单“b”中的按钮时,如何更改表单“a”中的 label 文本 .net C# - How can I change the label text in form "a" when a button is pressed in form "b" .net C# 任何周期,直到按下另一个按钮C# - Any cycle, until another button is pressed C# C# - 了解是否按下了任何 winform 按钮(共 64 个按钮) - C# - Getting to know if any winform button (of 64 buttons) was pressed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM