code_junkie

Windows Forms: A modal form that gets opened/closed by the application rather than the user?

Nov 11th, 2011
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. partial class MySustainedDialog : Form {
  2. public MySustainedDialog(string msg) {
  3. InitializeComponent();
  4. lbMessage.Text = msg;
  5. }
  6. public new void Show() {
  7. base.ShowDialog();
  8. }
  9.  
  10. public new void Hide() {
  11. this.Close();
  12. }
  13.  
  14. }
  15.  
  16. public class MyNoConnectionDialog : INoConnectionDialog {
  17. private FakeSustainedDialog _dialog;
  18. public void Show() {
  19. var w = new BackgroundWorker();
  20. w.DoWork += delegate {
  21. _dialog = new MySustainedDialog("Connection Lost");
  22. _dialog.Show();
  23. };
  24. w.RunWorkerAsync();
  25. }
  26.  
  27. public void Hide() {
  28. _dialog.Close();
  29. }
  30. }
  31.  
  32. public new void Hide()
  33. {
  34. if (this.InvokeRequired)
  35. {
  36. this.BeginInvoke((MethodInvoker)delegate { this.Hide(); });
  37. return;
  38. }
  39.  
  40. this.Close();
  41. }
Add Comment
Please, Sign In to add comment