In my form i have button to show other form.
But i want the previously form cannot be clicked before the new form is closed , How to create that ?
Because if the previously form is clicked, and i click the button again, the form is show multiple.
this my code in button click :
MDACS_AOP_CFSTL_InputActivity addProblem = new MDACS_AOP_CFSTL_InputActivity(ParameterSesi, ParameterNamaKaryawan, ParameterTanggal);
//addProblem.Close();
addProblem.Show();
You should use
addProblem.ShowDialog(this);
This will open the dialog as child of the parent (this) dialog. You cant click the parent dialog but you can still see it.
You need to use
addProblem.ShowDialog();
instead of
addProblem.Show();
so that it will open a modal dialog.
You could use
MDACS_AOP_CFSTL_InputActivity addProblem = new MDACS_AOP_CFSTL_InputActivity(ParameterSesi, ParameterNamaKaryawan, ParameterTanggal);
this.Hide;
addProblem.ShowDialog();
this.Show();
The show(); command will not be executed until the dialog is close. So it will stay hidden
Related
I want the form which will open when the user click a button, I don't want the user to click anywhere else outside this form(preventing him from clicking any other buttons on the parent form), I want to restrict his actions inside this form until he close it (For sure this form is top most), and I want the form to make alert(flicker) to any clicks outside it so the user will understand that he have to close it first.
When opening the form instead of
Form form = new Form();
form.Show();
use
Form form = new Form();
form.ShowDialog()
Super easy fix!
I assume your code to show the form right now is
form.Show();
To create/show an instance of the form that is modal (restricts clicking to that form) all you need to change is that line to:
form.ShowDialog();
Liam
How do I focus a TextBox element on the main form after closing a second form which is opened by calling ShowDialog()?
I have tried to call MainForm.TextBox.Focus() in the closing and closed event of the second form, but this won't focus the textbox.
I am using System.Windows.Forms on the compact framework.
Thanks.
From your second form, make a button (or another control) return a DialogResult by going into Properties. When you want the second form to close (ie after you press a button) make it return a specific DialogResult. In your main form you can do this:
if(secondform.ShowDialog() == DialogResult.OK)
{
textBox.Focus();
...
}
Calling ShowDialog() will block until it is closed so you could simply do:
secondform.ShowDialog();
textbox.Focus()
However the first example is for when you only want to make the textbox have focus after you press a certain button or do an action on the second form.
ShowDialog means, it's a modal window and the focus won't go back to main form until you close second form. You can set focus back in the same code which you used to open the second form.
SecondFrm.ShowDialog();
Textbox.Focus();
ShowDialog() will only return when the second form is closed, so you can write MyTextBox.Select() right after the call.
SomeForm form1 = new SomeForm();
form1.ShowDialog();
here you're showing the new form.
When you close it, you will execute methods after that, so add
yourTextbox.Focus();
so, its:
SomeForm form1 = new SomeForm();
form1.ShowDialog(); // do what you want in your form, then close it
yourTextbox.Focus();
I have a print button in form 1, when i click that, I should be able to print another form say form 2(This form has the basic layout of the page to be printed). Can anyone please tell me as to how to make this reference to form 2 in the form 1 print button event handler? Is there any need to use printform component in both the forms?
When I tried to do this, It was throwing an exception.
so put the button in Form1..
in the button click handler:
using (Form1 dialog = new Form1) {
// Do whatever you need to do here to print.
}
I have a windows form application where I show information about products and product categories in a datagridview. I would like to create a popup window so when I right click on a product and choose add to category a popup window appears and in that I show all the categories in a dropdownbox and when I click a button the product add to the category.
I want to create a popup window with a dropdownbox and a button. How do I do that in a window form application?
You can create a regular form, and call the myPopupForm.ShowDialog() method. The ShowDialog method blocks the main form, so the user can select a category, upon which you Close() the popup window; execution will continue on the main form.
More information can be found on http://msdn.microsoft.com/en-us/library/c7ykbedk.aspx#Y800.
Form2 form = new Form2();
This method will be like the Message.Show method, but you can add Buttons, TextBoxes, etc. in the Designer tools.
form.ShowDialog();
This method will just bring up another form.
form.Show();
AddHandler Me.Click,AddressOf Me_Click
Private Sub Me_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim popupForm As PopupForm = New PopupForm()
popupForm.Show(Me)
End Sub
You may get an exception window.Click continue-popup window will come.For further clicks get as many popups as you click
Regards
kvinvisibleguy
I have a form which is displayed through: ShowDialog().
The form doesn't have CancelButton specified.
When I open a BrowseDialog from the form and then close the BrowseDialog, the form is also closed. How can I prevent this from happening?
When the "browse"-button is clicked:
browseDialog.SelectedPath = projectLocation.Text;
browseDialog.ShowDialog();
if (browseDialog.SelectedPath != "")
{
projectLocation.Text = browseDialog.SelectedPath;
}
When the "cancel"-button of the form is clicked:
Close();
I would guess that the button you use to show the BrowseDialog has its DialogResult set to something other than None.
If this is not the case, please post some code.
in your onclosing event from your browser dialog, do a check on the sender arg to see which dialog is requesting the close and if it's not the browser dlg, set e.Cancel = true
I stumbled upon this when I had a similar issue, ensure your parent form is not setting ITS dialog result, because once the event to call the modal dialog is done, the parent form will close if it's set to something other than none.