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()
Related
I'm a Student of C# and doing a Windows Form Application using in visual studio 2012. The problem that i have is.
I have a parent form with a menustrip = File, with sub item Login and on Login item Click the Child form loads so you can enter your login details.
The problem that i'm having is when i click the login click button on the Child Form i need to
Add MenuStrip name "Add", with sub items names "Edit","Copy";
Also
Add DatagridView;
To the Parent Form, can anyone give me a step in the right direction please
From my understanding you could go about this two different ways.
First is to use the DialogResult that is received back from childForum.ShowDialog(this);
Which you can set in the child form's closing event. (If you don't need data back from the child form) Very similar to how you get results back from a MessageBox.Show();
Second would be to trigger an event that your main form is listening for that sets your data when received. (If you need to pass data between the two) -
simple custom event
In my windows forms application, I have two forms, mainForm and recordForm. in main form there is some textboxes and buttons , and on a click of particular button I want to show the recordForm.
But I want when the second form is opened, then user can't perform any operation (like filling textboxes etc) until second form is closed. I tried this:
private void tsCustomer_Click(object sender, EventArgs e)
{
recordForm customers = new recordForm();
customers.Show();
}
tsCustomer is button on mainForm. How can i do this?
Change your code from:
customers.Show();
to:
customers.ShowDialog();
You have to use
customers.ShowDialog();
in order for the customer form to be modal.
How about Form.ShowDialog()?
From MSDN Site : Shows the form as a modal dialog box with no owner window.
This does not effectively relates two forms of your application. But showing the second form in modal form is what you want.
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 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.
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.