Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/21/10 18:42:21 (14 years ago)
Author:
mkommend
Message:

updated SymbolicExpressionTreeChart (ticket #938)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.3/SymbolicExpressionTreeChart.cs

    r3442 r3470  
    3131namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
    3232  public sealed partial class SymbolicExpressionTreeChart : UserControl {
     33    private Image image;
    3334    private StringFormat stringFormat;
    3435    private Dictionary<SymbolicExpressionTreeNode, VisualSymbolicExpressionTreeNode> visualTreeNodes;
     
    3637    public SymbolicExpressionTreeChart() {
    3738      InitializeComponent();
     39      this.image = new Bitmap(Width, Height);
    3840      this.stringFormat = new StringFormat();
    39       stringFormat.Alignment = StringAlignment.Center;
    40       stringFormat.LineAlignment = StringAlignment.Center;
    41       pictureBox.Image = new Bitmap(pictureBox.Width, pictureBox.Height);
     41      this.stringFormat.Alignment = StringAlignment.Center;
     42      this.stringFormat.LineAlignment = StringAlignment.Center;
    4243      this.spacing = 5;
    4344      this.lineColor = Color.Black;
     
    101102    }
    102103
     104    protected override void OnPaint(PaintEventArgs e) {
     105      base.OnPaint(e);
     106      e.Graphics.DrawImage(image, 0, 0);
     107    }
     108    protected override void OnResize(EventArgs e) {
     109      base.OnResize(e);
     110      if (this.Width == 0 || this.Height == 0)
     111        this.image = new Bitmap(1, 1);
     112      else
     113        this.image = new Bitmap(Width, Height);
     114      this.Repaint();
     115    }
    103116
    104117    public void Repaint() {
    105       using (Graphics graphics = Graphics.FromImage(pictureBox.Image)) {
     118      this.GenerateImage();
     119      this.Refresh();
     120    }
     121
     122    private void GenerateImage() {
     123      using (Graphics graphics = Graphics.FromImage(image)) {
    106124        graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
    107125        graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
     
    111129          DrawFunctionTree(tree, graphics, 0, 0, this.Width, height);
    112130        }
    113 
    114         pictureBox.Refresh();
    115131      }
    116132    }
     
    188204
    189205    #region methods for painting the symbolic expression tree
    190     protected override void OnResize(EventArgs e) {
    191       base.OnResize(e);
    192       pictureBox.Image = new Bitmap(pictureBox.Width, pictureBox.Height);
    193       Repaint();
    194     }
    195 
    196206    private void DrawFunctionTree(SymbolicExpressionTree tree, Graphics graphics, int x, int y, int width, int height) {
    197207      DrawFunctionTree(tree.Root, graphics, x, y, width, height, Point.Empty);
     
    276286    }
    277287    #endregion
    278 
    279288  }
    280289}
Note: See TracChangeset for help on using the changeset viewer.