Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/HeuristicLab.Netron-3.0.2672.12446/NetronVisualization.cs @ 2782

Last change on this file since 2782 was 2782, checked in by mkommend, 14 years ago

added test application for netron (ticket #867)

File size: 2.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9
10using Netron.Diagramming.Core;
11
12namespace HeuristicLab.Netron {
13  [ToolboxItem(true)]
14  public partial class NetronVisualization : DiagramControlBase {
15    private static Size INVALID_SIZE = new Size(-1,-1);
16    private Size oldSize;
17    public NetronVisualization()
18      : base() {
19      InitializeComponent();
20      this.oldSize = INVALID_SIZE;
21
22      SetStyle(ControlStyles.AllPaintingInWmPaint, true);
23      SetStyle(ControlStyles.DoubleBuffer, true);
24      SetStyle(ControlStyles.UserPaint, true);
25      SetStyle(ControlStyles.ResizeRedraw, true);
26
27      if (!DesignMode) {
28        this.Controller = new Controller(this);
29        this.View = new View(this);
30
31        this.Document = new Document();
32        this.AttachToDocument(Document);
33        this.Controller.View = View;
34        TextEditor.Init(this);
35
36        View.OnCursorChange += new EventHandler<CursorEventArgs>(mView_OnCursorChange);
37        View.OnBackColorChange += new EventHandler<ColorEventArgs>(View_OnBackColorChange);
38
39        this.SizeChanged += new EventHandler(NetronVisualization_SizeChanged);
40        this.AllowDrop = true;
41      }
42    }
43
44    private void NetronVisualization_SizeChanged(object sender, EventArgs e) {
45      if (this.oldSize == INVALID_SIZE) {
46        this.View.PageSize = new Size((int)(this.Size.Width * this.Magnification.Width), (int)(this.Size.Height * this.Magnification.Height));
47        oldSize = this.Size;
48        return;
49      }
50
51      SizeF magnificationChanges = new SizeF();
52      magnificationChanges.Width = ((float)this.Size.Width) / oldSize.Width;
53      magnificationChanges.Height = ((float)this.Size.Height) / oldSize.Height;
54
55      SizeF newMagnification = new SizeF();
56      newMagnification.Width = this.View.Magnification.Width * magnificationChanges.Width;
57      newMagnification.Height = this.View.Magnification.Height * magnificationChanges.Height;
58
59      this.Magnification = newMagnification;
60      this.oldSize = this.Size;
61    }
62
63    protected override void OnScroll(ScrollEventArgs se) {
64      //base.OnScroll(se);
65      if (se.ScrollOrientation == ScrollOrientation.HorizontalScroll) {
66        Origin = new Point(se.NewValue, Origin.Y);
67        //System.Diagnostics.Trace.WriteLine(se.NewValue);
68      } else {
69        Origin = new Point(Origin.X, se.NewValue);
70        //System.Diagnostics.Trace.WriteLine(se.NewValue);
71      }
72    }
73
74    private void mView_OnCursorChange(object sender, CursorEventArgs e) {
75      this.Cursor = e.Cursor;
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.