[571] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Drawing;
|
---|
| 26 | using System.Drawing.Drawing2D;
|
---|
| 27 | using System.Data;
|
---|
| 28 | using System.Text;
|
---|
| 29 | using System.Windows.Forms;
|
---|
| 30 | using HeuristicLab.Charting;
|
---|
| 31 |
|
---|
| 32 | namespace HeuristicLab.CEDMA.Charting {
|
---|
| 33 | public partial class HistogramControl : UserControl {
|
---|
| 34 | private Bitmap bitmap;
|
---|
| 35 | private bool renderingRequired;
|
---|
| 36 |
|
---|
| 37 | private Histogram myChart;
|
---|
| 38 | public Histogram Chart {
|
---|
| 39 | get { return myChart; }
|
---|
| 40 | set {
|
---|
| 41 | if(myChart != null) myChart.Update -= new EventHandler(myChart_Update);
|
---|
| 42 | myChart = value;
|
---|
| 43 | if(myChart != null) {
|
---|
| 44 | myChart.Update += new EventHandler(myChart_Update);
|
---|
| 45 | }
|
---|
| 46 | GenerateImage();
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | public HistogramControl() {
|
---|
| 51 | InitializeComponent();
|
---|
| 52 | GenerateImage();
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | private void myChart_Update(object sender, EventArgs e) {
|
---|
| 56 | GenerateImage();
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | private void pictureBox_SizeChanged(object sender, EventArgs e) {
|
---|
| 60 | GenerateImage();
|
---|
| 61 | }
|
---|
| 62 | private void pictureBox_VisibleChanged(object sender, EventArgs e) {
|
---|
| 63 | if(pictureBox.Visible && renderingRequired) {
|
---|
| 64 | GenerateImage();
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | private void pictureBox_MouseMove(object sender, MouseEventArgs e) {
|
---|
| 69 | toolTip.SetToolTip(pictureBox, Chart.GetToolTipText(e.Location));
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | private void GenerateImage() {
|
---|
| 73 | if(!Visible) {
|
---|
| 74 | renderingRequired = true;
|
---|
| 75 | } else {
|
---|
| 76 | if((pictureBox.Width == 0) || (pictureBox.Height == 0)) {
|
---|
| 77 | bitmap = null;
|
---|
| 78 | } else {
|
---|
| 79 | bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
|
---|
| 80 | if(Chart != null) {
|
---|
| 81 | Graphics graphics = Graphics.FromImage(bitmap);
|
---|
| 82 | graphics.SetClip(new System.Drawing.Rectangle(0, 0, pictureBox.Width, pictureBox.Height));
|
---|
| 83 | Chart.Render(graphics, pictureBox.Width, pictureBox.Height);
|
---|
| 84 | graphics.Dispose();
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 | pictureBox.Image = bitmap;
|
---|
| 88 | renderingRequired = false;
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | private void pictureBox_MouseClick(object sender, MouseEventArgs e) {
|
---|
| 93 | Chart.MouseClick(e.Location, e.Button);
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 | }
|
---|