Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/CanvasUI.cs @ 1235

Last change on this file since 1235 was 1045, checked in by bspisic, 16 years ago

#424
Did some code refactoring (created concrete MouseEventListeners)

File size: 1.5 KB
Line 
1using System;
2using System.Diagnostics;
3using System.Drawing;
4using System.Drawing.Drawing2D;
5using System.Windows.Forms;
6
7namespace HeuristicLab.Visualization {
8  public partial class CanvasUI : Control {
9    private readonly Canvas mainCanvas = new Canvas();
10    private IMouseEventListener mouseEventListener;
11
12    public CanvasUI() {
13      InitializeComponent();
14
15      DoubleBuffered = true;
16    }
17
18    public Canvas MainCanvas {
19      get { return mainCanvas; }
20    }
21
22    public IMouseEventListener MouseEventListener {
23      get { return mouseEventListener; }
24      set { mouseEventListener = value; }
25    }
26
27    protected override void OnPaint(PaintEventArgs pe) {
28      try {
29        Graphics g = pe.Graphics;
30
31        g.SmoothingMode = SmoothingMode.AntiAlias;
32
33        g.FillRectangle(Brushes.White, ClientRectangle);
34
35        mainCanvas.Draw(g, ClientRectangle);
36
37        g.DrawRectangle(Pens.Black, 0, 0, Width - 1, Height - 1);
38
39        base.OnPaint(pe);
40      } catch (Exception e) {
41       Trace.WriteLine(e);
42      }
43    }
44
45    protected override void OnResize(EventArgs e) {
46      Invalidate();
47
48      base.OnResize(e);
49    }
50
51    private void CanvasUI_MouseMove(object sender, MouseEventArgs e) {
52      if (mouseEventListener != null) {
53        mouseEventListener.MouseMove(sender, e);
54      }
55    }
56
57    private void CanvasUI_MouseUp(object sender, MouseEventArgs e) {
58      if (mouseEventListener != null) {
59        mouseEventListener.MouseUp(sender, e);
60      }
61    }
62  }
63}
Note: See TracBrowser for help on using the repository browser.