Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/09/08 16:30:24 (16 years ago)
Author:
bspisic
Message:

#319

MouseEventListener implemented
dragDrop MouseEventListener example implemented

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization.Test/MainForm.cs

    r636 r725  
    11using System.Drawing;
    22using System.Windows.Forms;
    3 using HeuristicLab.Visualization;
    43
    54namespace HeuristicLab.Visualization.Test {
    65  public partial class MainForm : Form {
     6    private MouseEventListener dragDropListener;
     7
    78    public MainForm() {
    89      InitializeComponent();
     10
     11      CreateMouseEventListeners();
    912
    1013      canvasUI.MainCanvas.WorldShape = new WorldShape(new RectangleD(0, 0, 800, 600), new RectangleD(0, 0, 800, 600));
     
    1619
    1720      canvasUI.Invalidate();
     21    }
     22
     23    private void CreateMouseEventListeners() {
     24      dragDropListener = new MouseEventListener();
     25      dragDropListener.OnMouseMove += DragDrop_OnMouseMove;
     26      dragDropListener.OnMouseUp += DragDrop_OnMouseUp;
    1827    }
    1928
     
    3443
    3544      for (int i = 0; i < 10000; i++) {
    36         RectangleShape rect = new RectangleShape(x1, y1, x1+0.3, y1+0.3, 0, Color.Maroon);
    37         x1 += 0.4; y1 += 0.4;
     45        RectangleShape rect = new RectangleShape(x1, y1, x1 + 0.3, y1 + 0.3, 0, Color.Maroon);
     46        x1 += 0.4;
     47        y1 += 0.4;
    3848        rightWorld.AddShape(rect);
    3949      }
     
    8191      mainWorld.AddShape(leftWorld);
    8292    }
     93
     94    private void canvasUI_MouseDown(object sender, MouseEventArgs e) {
     95      mouseEventDemonstrationGraphics = canvasUI.CreateGraphics();
     96
     97      dragDropListener.StartPoint = e.Location;
     98      lastActualPoint = e.Location;
     99
     100      canvasUI.MouseEventListener = dragDropListener;
     101    }
     102
     103    private Point lastActualPoint;
     104    private Graphics mouseEventDemonstrationGraphics;
     105
     106    private void DragDrop_OnMouseUp(Point startPoint, Point actualPoint) {
     107      canvasUI.MouseEventListener = null;
     108
     109      canvasUI.Invalidate();
     110      mouseEventDemonstrationGraphics.Dispose();
     111    }
     112
     113    private void DragDrop_OnMouseMove(Point startPoint, Point actualPoint) {
     114      mouseEventDemonstrationGraphics.DrawLine(Pens.Blue, lastActualPoint, actualPoint);
     115      lastActualPoint = actualPoint;
     116    }
    83117  }
    84118}
Note: See TracChangeset for help on using the changeset viewer.