|
| 1 | +using System; |
| 2 | +using System.Drawing; |
| 3 | +using System.Windows.Forms; |
| 4 | + |
| 5 | +namespace Picross |
| 6 | +{ |
| 7 | + class Main : Form |
| 8 | + { |
| 9 | + private static Size MinSize = new Size(665, 435); |
| 10 | + |
| 11 | + SeaUserControl[] userControls; |
| 12 | + |
| 13 | + public Main() { |
| 14 | + // Load and apply the settings |
| 15 | + Settings s = Settings.Get; |
| 16 | + this.StartPosition = FormStartPosition.Manual; |
| 17 | + this.Location = s.Position; |
| 18 | + this.ClientSize = new Size(s.Size); |
| 19 | + //this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); |
| 20 | + this.Icon = Properties.Resources.EyesHybrid; |
| 21 | + this.MaximizeBox = false; |
| 22 | + |
| 23 | + // Set some standard values |
| 24 | + this.Text = "Picross"; |
| 25 | + |
| 26 | + // Add the controls |
| 27 | + this.userControls = new SeaUserControl[1] { new MainControl() }; |
| 28 | + foreach (SeaUserControl u in this.userControls) { |
| 29 | + u.Size = this.ClientSize; |
| 30 | + this.Controls.Add(u); |
| 31 | + u.OnResize(); |
| 32 | + } |
| 33 | + this.userControls[0].Show(); |
| 34 | + |
| 35 | + // Locate the controls |
| 36 | + this.onResizeEnd(this, new EventArgs()); |
| 37 | + |
| 38 | + // Register events |
| 39 | + this.LocationChanged += (o, e) => { Settings.Get.Position = this.Location; }; |
| 40 | + this.ResizeEnd += onResizeEnd; |
| 41 | + } |
| 42 | + |
| 43 | + void onResizeEnd(object o, EventArgs e) { |
| 44 | + // Make sure its not too small |
| 45 | + this.ClientSize = new Size(Math.Max(this.ClientSize.Width, MinSize.Width), Math.Max(this.ClientSize.Height, MinSize.Height)); |
| 46 | + |
| 47 | + // Save the size to the settings |
| 48 | + Settings.Get.Size = new Point(this.ClientSize); |
| 49 | + |
| 50 | + // Resize the user controls |
| 51 | + foreach (SeaUserControl u in this.userControls) { |
| 52 | + u.Size = this.ClientSize; |
| 53 | + u.OnResize(); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + /// <summary> |
| 58 | + /// Show usercontrol at index i and hide all others |
| 59 | + /// </summary> |
| 60 | + /// <param name="i">The index</param> |
| 61 | + public void ShowUserControl(int i) { |
| 62 | + foreach (SeaUserControl u in this.userControls) |
| 63 | + u.Hide(); |
| 64 | + this.userControls[i].Show(); |
| 65 | + this.userControls[i].Size = this.ClientSize; |
| 66 | + this.userControls[i].OnResize(); |
| 67 | + } |
| 68 | + |
| 69 | + public void LoadPuzzleFromFile(string filename) { |
| 70 | + ((MainControl)this.userControls[0]).LoadPuzzleFromFile(filename); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + class SeaUserControl : UserControl |
| 75 | + { |
| 76 | + public SeaUserControl() { |
| 77 | + this.Hide(); |
| 78 | + } |
| 79 | + |
| 80 | + /// <summary> |
| 81 | + /// Show usercontrol at index i and hide all others |
| 82 | + /// </summary> |
| 83 | + /// <param name="i">The index</param> |
| 84 | + public void ShowUserControl(int i) { |
| 85 | + ((Main)this.Parent).ShowUserControl(i); |
| 86 | + } |
| 87 | + |
| 88 | + /// <summary> |
| 89 | + /// This method gets called after the usercontrol is resized |
| 90 | + /// </summary> |
| 91 | + public virtual void OnResize() { } |
| 92 | + } |
| 93 | +} |
0 commit comments