GUI/MainForm.cs
changeset 214 9ddbb54998ac
parent 213 d93c927e4fd6
child 223 39f73ac8c2f4
     1.1 --- a/GUI/MainForm.cs	Tue Oct 05 19:34:59 2010 +0000
     1.2 +++ b/GUI/MainForm.cs	Wed Oct 06 11:34:54 2010 +0000
     1.3 @@ -100,26 +100,6 @@
     1.4        nodeTextBoxMax.DrawText += nodeTextBoxText_DrawText;
     1.5        nodeTextBoxText.EditorShowing += nodeTextBoxText_EditorShowing;
     1.6  
     1.7 -      Rectangle newBounds = new Rectangle {
     1.8 -        X = settings.GetValue("mainForm.Location.X", Location.X),
     1.9 -        Y = settings.GetValue("mainForm.Location.Y", Location.Y),
    1.10 -        Width = settings.GetValue("mainForm.Width", 470),
    1.11 -        Height = settings.GetValue("mainForm.Height", 640)
    1.12 -      };
    1.13 -
    1.14 -      Screen[] screens = Screen.AllScreens;
    1.15 -      Rectangle totalWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
    1.16 -        int.MinValue, int.MinValue);
    1.17 -
    1.18 -      foreach(Screen screen in screens)
    1.19 -        totalWorkingArea = Rectangle.Union(totalWorkingArea, screen.Bounds);
    1.20 -
    1.21 -      this.Bounds = newBounds;
    1.22 -
    1.23 -      if (!totalWorkingArea.Contains(newBounds) ||
    1.24 -        !settings.Contains("mainForm.Location.X"))
    1.25 -        this.StartPosition = FormStartPosition.CenterScreen;
    1.26 -
    1.27        foreach (TreeColumn column in treeView.Columns) 
    1.28          column.Width = Math.Max(20, Math.Min(400,
    1.29            settings.GetValue("treeView.Columns." + column.Header + ".Width",
    1.30 @@ -346,10 +326,10 @@
    1.31  
    1.32      private void SaveConfiguration() {
    1.33        if (WindowState != FormWindowState.Minimized) {
    1.34 -        settings.SetValue("mainForm.Location.X", Location.X);
    1.35 -        settings.SetValue("mainForm.Location.Y", Location.Y);
    1.36 -        settings.SetValue("mainForm.Width", ClientSize.Width);
    1.37 -        settings.SetValue("mainForm.Height", ClientSize.Height);
    1.38 +        settings.SetValue("mainForm.Location.X", Bounds.X);
    1.39 +        settings.SetValue("mainForm.Location.Y", Bounds.Y);
    1.40 +        settings.SetValue("mainForm.Width", Bounds.Width);
    1.41 +        settings.SetValue("mainForm.Height", Bounds.Height);
    1.42        }
    1.43  
    1.44        foreach (TreeColumn column in treeView.Columns)
    1.45 @@ -361,13 +341,41 @@
    1.46        try {
    1.47          settings.Save(fileName);
    1.48        } catch (UnauthorizedAccessException) {
    1.49 -        MessageBox.Show("Access to the path '" + fileName + "' is denied. " + 
    1.50 +        MessageBox.Show("Access to the path '" + fileName + "' is denied. " +
    1.51            "The current seetings could not be saved.", 
    1.52            "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    1.53        }
    1.54      }
    1.55  
    1.56 -   private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
    1.57 +    private void MainForm_Load(object sender, EventArgs e) {
    1.58 +      Rectangle newBounds = new Rectangle {
    1.59 +        X = settings.GetValue("mainForm.Location.X", Location.X),
    1.60 +        Y = settings.GetValue("mainForm.Location.Y", Location.Y),
    1.61 +        Width = settings.GetValue("mainForm.Width", 470),
    1.62 +        Height = settings.GetValue("mainForm.Height", 640)
    1.63 +      };
    1.64 +
    1.65 +      Rectangle totalWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
    1.66 +        int.MinValue, int.MinValue);
    1.67 +
    1.68 +      foreach (Screen screen in Screen.AllScreens)
    1.69 +        totalWorkingArea = Rectangle.Union(totalWorkingArea, screen.Bounds);
    1.70 +
    1.71 +      Rectangle intersection = Rectangle.Intersect(totalWorkingArea, newBounds);
    1.72 +      if (intersection.Width < 20 || intersection.Height < 20 ||
    1.73 +        !settings.Contains("mainForm.Location.X")
    1.74 +      ) {
    1.75 +        newBounds.X = (Screen.PrimaryScreen.WorkingArea.Width / 2) -
    1.76 +                      (newBounds.Width/2);
    1.77 +
    1.78 +        newBounds.Y = (Screen.PrimaryScreen.WorkingArea.Height / 2) -
    1.79 +                      (newBounds.Height / 2);
    1.80 +      }
    1.81 +
    1.82 +      this.Bounds = newBounds;
    1.83 +    }
    1.84 +    
    1.85 +    private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
    1.86        Visible = false;
    1.87        SaveConfiguration();
    1.88