PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/WorldView/FormProgressDialog.cs

#
C# | 90 lines | 68 code | 18 blank | 4 comment | 4 complexity | 629bf06c9059c665a3da970af1623bf2 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace MoreTerra
  10. {
  11. public partial class FormProgressDialog : Form
  12. {
  13. private Boolean cancel;
  14. private String name;
  15. private BackgroundWorker bw;
  16. private Boolean success;
  17. public FormProgressDialog(String titleName, Boolean allowsCancel, BackgroundWorker worker)
  18. {
  19. bw = worker;
  20. cancel = allowsCancel;
  21. name = titleName;
  22. this.ShowInTaskbar = false;
  23. InitializeComponent();
  24. this.Icon = Properties.Resources.Cannon;
  25. }
  26. private void FormProgressDialog_Load(object sender, EventArgs e)
  27. {
  28. Point pt;
  29. Size size;
  30. Text = name;
  31. buttonCancel.Enabled = cancel;
  32. textBoxOutput.Text = "";
  33. // Set the box to the center of the window.
  34. pt = this.Owner.Location;
  35. size = this.Owner.Size;
  36. pt.X = pt.X + (size.Width / 2) - (this.Size.Width / 2);
  37. pt.Y = pt.Y + (size.Height / 2) - (this.Size.Height / 2);
  38. this.Location = pt;
  39. }
  40. private void buttonCancel_Click(object sender, EventArgs e)
  41. {
  42. // ?
  43. // Somehow I need to pass back that we need to cancel.
  44. // Although we could handle it ourselves.
  45. }
  46. public void worker_Completed(object sender, RunWorkerCompletedEventArgs e)
  47. {
  48. if (e.Cancelled)
  49. success = false;
  50. success = true;
  51. this.Close();
  52. }
  53. public void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
  54. {
  55. if (e.ProgressPercentage > progressBarTotal.Value)
  56. progressBarTotal.Value = e.ProgressPercentage;
  57. if (e.UserState != null)
  58. {
  59. textBoxOutput.Text += ((String)e.UserState + Environment.NewLine);
  60. textBoxOutput.Select(textBoxOutput.TextLength, 0);
  61. textBoxOutput.ScrollToCaret();
  62. }
  63. }
  64. public Boolean Success
  65. {
  66. get
  67. {
  68. return success;
  69. }
  70. }
  71. }
  72. }