Reputation: 281
I've created a printing tools with the print preview. The print preview is made by form. I would like to let user to click the print button to print the doc while the preview form is not closing.
How can I return the DialogResult.OK
to the printing tool preventing the form from disappearing?
Upvotes: 1
Views: 1089
Reputation: 63772
You can't.
DialogResult
is used with modal windows. Modal windows basically hijack the underlying UI message loop, which makes them synchronous with respect to the caller.
If you need the print preview to initiate the printing while keeping the dialog modal, just give it a way to initiate the printing, rather than having the caller react to a returned DialogResult
. Probably the easiest way to do this would be to simply pass an Action
delegate to the dialog - when OK is pressed, you invoke the delegate.
Upvotes: 1
Reputation: 1600
There is no such functionlity as i now in C#. However, you can create a custom dialog box to do this instead.
public static class MyDialog
{
public static int ShowDialog(string text, string caption)
{
Form prompt = new Form();
prompt.Width = 500;
prompt.Height = 100;
prompt.Text = caption;
Label textLabel = new Label() { Left = 50, Top=20, Text=text };
NumericUpDown inputBox = new NumericUpDown () { Left = 50, Top=50, Width=400 };
Button confirmation = new Button() { Text = "Ok", Left=350, Width=100, Top=70 };
confirmation.Click += (sender, e) => { //YOUR FUNCTIONALITY };
prompt.Controls.Add(confirmation);
prompt.Controls.Add(textLabel);
prompt.Controls.Add(inputBox);
prompt.ShowDialog();
return (int)inputBox.Value;
}
}
Then call it using:
int MyDialogValue = MyDialog.ShowDialog("Test", "123");
Upvotes: 0