开发者

WinForms: Looking for an easy way to pop up a 'Processing..' panel

开发者 https://www.devze.com 2023-03-27 07:36 出处:网络
I have a WinForms application that, at some point, will do some calculations that take a couple of seconds. Dur开发者_如何学Pythoning this time, I disable the controls. Additionally I want to display

I have a WinForms application that, at some point, will do some calculations that take a couple of seconds. Dur开发者_如何学Pythoning this time, I disable the controls. Additionally I want to display a popup that kind of 'blocks' the application more visibly.

I tried placing a Panel on top of the Form in order to do so, but there I'm somehow not able to add any text to it. I.e. the Labels and ImageBoxes I put there are somehow not displayed or behind the Panel.

Any suggestions how I could achieve this in a quick and easy way? .. I mean, without redesigning the whole Form.


Your problem with the things not showing up in your additional panel is that everything is happening in the same thread, but your calculations are blocking everything from appearing because they are hogging up the thread. You should look into using a backgroundWorker, which is one of the tools in WinForms. You should throw the function call that performs the calculations into the DoWork method of the backgroundWorker, then the form itself can continue to function during the calculations.

See http://msdn.microsoft.com/en-us/library/cc221403%28v=vs.95%29.aspx for examples


Create a Dialog Box (windows form) to popup during the processing, then you can have the Dialog Box close once your processing is completed.

By using a Dialog Box not a Message Box, you can still have control over closing the window when your processing is done.


You could create a simple UserControl with just a Label and an ImageBox, maybe with public setter for their values. You can add it to your form setting its Visible property to false. Then you can make it visible during your calculations and go back top invisible in the end.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号