Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Preventing clicks on a form without using Enabled=false

Tags:

c#

winforms

I have a form that requires a long operation (expansion of a treeview node searches the network for additional items to create more tree nodes) - so I plan on using a BackgroundWorker for this task. During the long operation I want the cursor to be the wait cursor and I want the entire form to be unclickable except for the Cancel button. I know I could use Enabled=false but this turns the treeview grey which looks pretty lame imo.

I could just NOT use a BW but that means I have to use DoEvents to get the cursor to change and that possibly "Not Responding" would show up, which I hate.

I thought of handling all the mouse click events and keyboard events so that they are cancelled if the BW is busy... so that is my current plan. I just wondered if I am missing something, if there is another way.

Thanks.

like image 952
Dave Ludwig Avatar asked Apr 26 '26 01:04

Dave Ludwig


1 Answers

There is no easy way to do that. It is better to fix your treeview and use Enabled property. You can also show your progressbar in Modal dialog - that will block UI

like image 78
username Avatar answered Apr 28 '26 13:04

username



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!