i have two winforms loaded simultaneously
first form with web browser and second form having just controls
second form always on top of second form, second form doesn't receive any mouse events while first form loaded, after closing first form, second form receive all mouse events.
how do i solve this issue
Please post the code you're using to show for your second form, although it should be something like this:
Form2 myForm2 = new Form2();
Form2.Show(this);
It's not very likely that your WebBrowser is causing this.
Related
I have created a windows form application in c# having two forms.
2nd form loads on click of each button on form1. I have six buttons on first form.2nd form contains textbox whose content is assigned at runtime. Now if I click on more than 3 buttons one after other the form is hanged nothing happen.Also for second click form2 takes tim to load. I am not getting the reason behind this. I have used following code for show hide.
{this.Hide();} to hide and {this.ShowDialog();}to open form2.
The dialogboxes are two types.
Model and Model less.
When you open other form through showdialog, we have to finish the work with that dialogbox then only we can able to go back.
The second form you can load by calling form2.Show()
In my windows forms application, I close one form and open another like this:
MyApp.MySecondForm frmInst = new MyApp.MySecondForm();
frmInst.Show();
this.Hide();
But before I open like this, I set label text in my first form because I want to inform the user that second form is loading.
Imagine second form's loading takes 10 seconds, when I press the button in order to open the second button, the label text doesn't get changed until the second form gets open. When I close the second form, I recall the first form and see that the text has changed.
Which way should I follow to set label text right after user clicks a button?
Thanks in advance.
You have to call the Refresh() method before frmInst.Show(). Because the graphics will not refresh until the method is finished executing, unless you do it manually.
Are you firing that 10 second process asynchronously?
If not, that's what's causing the delay. It getting the information (10 seconds), then updating the GUI thread.
Try using a BackgroundWorker:
http://www.dotnetperls.com/backgroundworker
I have a Main Form and a Other Form.
The Main Form is always open, and at some time it will launch Other Form.
I tried:
form.TopMost = true;
But this only places the form on top. The Form behind (Main Form) still can be accessible.
How can I get the same behavior like when I do OpenFileDialog, and disable the main form behind it?
(Thanks in advance)
You need to make your form modal. To do this, use ShowDialog instead of Show to display it (the same way you do with a dialog).
Also, note that forms shown with ShowDialog are not actually closed and disposed when you click their Close button, so you should dispose them manually. The usual way to handle their lifetime is to use a using construct:
using (var form = new SomeForm())
{
form.ShowDialog();
// do stuff after the dialog is closed
}
form.showdialog(); where form is the the top form to be launched.so while lauching the top form just add form.showdialog()
I have two forms; one called 'win' and the other called 'loss'. There is a button on 'win' form which displays the 'loss' form. When this button is clicked both forms are visible. When I close the 'loss' form and then click the button on the 'win' form again I get the following exception:
An unhandled exception has occured: Unable to access a disposed object ..object :form
Please could someone point me in the right direction so I can resolve this?
It is because your 'loss' form is already closed and has been disposed, so it cannot be used anymore. You need to create a new instance of the form, like so (don't know how exactly your code looks):
this.loss = new LossForm();
this.loss.Show();
You can verify IsDisposed property of form, before referencing it.
E.g. button click handler on 'win' form:
if (loss.IsDisposed)
return;
// do stuff with loss form
Update: I think it's better not to share control between forms.
You can run 'loss' form as Dialog. And read all needed properties after dialog closed.
You can subscribe to 'loss' form events and process them in 'win' form.
It's not a very good model your going for but you could hook into the formClosing event, cancel it and then hide the form instead. That means the form wont be automatically disposed and you could call show again.
Put some time aside to research MVC architecture - it looks complicated at first, but it really does help.
Is there a way to show a modal form without ShowDialog metod calling? By showing a modal form I mean that the Form overlays the current Form and prevent user input to the bacground Form. The Form that is to be shown is a MessageBox style form that is not fullscreen.
Thanks
Dominik
I would assume that you could set the "dialog" form to stay on top (TopMost property) and then disable the main form in order to prevent input.
This is only a partial solution as the main form will still be able to be focused, closed etc. You will need to handle all these cases yourself in order to prevent them.
Is there any particular reason you don't want to use ShowDialog?
You could try to do this:
MyForm frm = new MyForm(); // this would be your modeless dialog
frm->show(this); // "this" being the instance that invokes it.