Free cookie consent management tool by TermsFeed Policy Generator

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

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

#424
Did some code refactoring (created concrete MouseEventListeners)

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