Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ViewBase.cs @ 2591

Last change on this file since 2591 was 2548, checked in by mkommend, 15 years ago

added ViewShown, ViewHidden and ViewClosed events in MainForm (ticket #771)

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Text;
28using System.Xml;
29using System.Windows.Forms;
30
31namespace HeuristicLab.MainForm.WindowsForms {
32  public partial class ViewBase : UserControl, IView {
33    private bool initialized;
34    public ViewBase() {
35      InitializeComponent();
36      this.initialized = false;
37      this.closeReason = CloseReason.None;
38    }
39
40    private string myCaption;
41    public string Caption {
42      get { return myCaption; }
43      set {
44        if (InvokeRequired) {
45          Action<string> action = delegate(string s) { this.Caption = s; };
46          Invoke(action, value);
47        } else {
48          if (value != myCaption) {
49            myCaption = value;
50            OnCaptionChanged();
51          }
52        }
53      }
54    }
55
56    public event EventHandler CaptionChanged;
57    protected virtual void OnCaptionChanged() {
58      if (CaptionChanged != null)
59        CaptionChanged(this, new EventArgs());
60    }
61
62    public event EventHandler Changed;
63    protected virtual void OnChanged() {
64      if (InvokeRequired)
65        Invoke((MethodInvoker)OnChanged);
66      else if (Changed != null)
67        Changed(this, new EventArgs());
68    }
69
70    public virtual void OnClosing(object sender, CancelEventArgs e) {
71    }
72
73    internal CloseReason closeReason;
74    internal void OnClosingHelper(object sender, FormClosingEventArgs e) {
75      if (this.closeReason != CloseReason.None)
76        this.OnClosing(sender, new FormClosingEventArgs(this.closeReason, e.Cancel));
77      else
78        this.OnClosing(sender, e);
79
80      this.closeReason = CloseReason.None;
81    }
82
83    public virtual void OnClosing(object sender, FormClosingEventArgs e) {
84    }
85
86    public virtual void OnClosed(object sender, EventArgs e) {
87    }
88
89    public event EventHandler Initialized;
90
91    private void ViewBase_Load(object sender, EventArgs e) {
92      if (!this.initialized && !this.DesignMode) {
93        if (this.Initialized != null)
94          this.Initialized(this, new EventArgs());
95        this.initialized = true;
96      }
97    }
98  }
99}
Note: See TracBrowser for help on using the repository browser.