Last change
on this file since 1240 was
1240,
checked in by mstoeger, 15 years ago
|
Transformations on shapes are possible outside of the Draw method. (#424)
|
File size:
1.4 KB
|
Rev | Line | |
---|
[724] | 1 | using System;
|
---|
| 2 | using System.Diagnostics;
|
---|
| 3 | using System.Drawing;
|
---|
[635] | 4 | using System.Windows.Forms;
|
---|
| 5 |
|
---|
| 6 | namespace HeuristicLab.Visualization {
|
---|
| 7 | public partial class CanvasUI : Control {
|
---|
[1240] | 8 | private readonly Canvas canvas = new Canvas();
|
---|
[1045] | 9 | private IMouseEventListener mouseEventListener;
|
---|
[635] | 10 |
|
---|
| 11 | public CanvasUI() {
|
---|
| 12 | InitializeComponent();
|
---|
[958] | 13 |
|
---|
| 14 | DoubleBuffered = true;
|
---|
[635] | 15 | }
|
---|
| 16 |
|
---|
[1240] | 17 | public Canvas Canvas {
|
---|
| 18 | get { return canvas; }
|
---|
[635] | 19 | }
|
---|
| 20 |
|
---|
[1045] | 21 | public IMouseEventListener MouseEventListener {
|
---|
[724] | 22 | get { return mouseEventListener; }
|
---|
| 23 | set { mouseEventListener = value; }
|
---|
| 24 | }
|
---|
| 25 |
|
---|
[635] | 26 | protected override void OnPaint(PaintEventArgs pe) {
|
---|
[724] | 27 | try {
|
---|
| 28 | Graphics g = pe.Graphics;
|
---|
[635] | 29 |
|
---|
[1240] | 30 | canvas.Viewport = ClientRectangle;
|
---|
| 31 | canvas.Draw(g);
|
---|
[869] | 32 |
|
---|
[724] | 33 | base.OnPaint(pe);
|
---|
| 34 | } catch (Exception e) {
|
---|
[1038] | 35 | Trace.WriteLine(e);
|
---|
[724] | 36 | }
|
---|
[635] | 37 | }
|
---|
[724] | 38 |
|
---|
[869] | 39 | protected override void OnResize(EventArgs e) {
|
---|
| 40 | Invalidate();
|
---|
| 41 |
|
---|
[1240] | 42 | canvas.Viewport = ClientRectangle;
|
---|
| 43 |
|
---|
[869] | 44 | base.OnResize(e);
|
---|
| 45 | }
|
---|
| 46 |
|
---|
[724] | 47 | private void CanvasUI_MouseMove(object sender, MouseEventArgs e) {
|
---|
[725] | 48 | if (mouseEventListener != null) {
|
---|
[1045] | 49 | mouseEventListener.MouseMove(sender, e);
|
---|
[725] | 50 | }
|
---|
[724] | 51 | }
|
---|
| 52 |
|
---|
| 53 | private void CanvasUI_MouseUp(object sender, MouseEventArgs e) {
|
---|
[725] | 54 | if (mouseEventListener != null) {
|
---|
[1045] | 55 | mouseEventListener.MouseUp(sender, e);
|
---|
[725] | 56 | }
|
---|
[724] | 57 | }
|
---|
[635] | 58 | }
|
---|
[724] | 59 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.