using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using HeuristicLab.MainForm; using HeuristicLab.Core.Views; using HeuristicLab.Data; using System.Threading; namespace HeuristicLab.Problems.NK { [View("BoolMatrixBitmapView")] [Content(typeof(BoolMatrix), IsDefaultView = false)] public sealed partial class BoolMatrixView : ItemView { public new BoolMatrix Content { get { return (BoolMatrix)base.Content; } set { base.Content = value; } } public BoolMatrixView() { InitializeComponent(); } protected override void DeregisterContentEvents() { Content.ToStringChanged -= new EventHandler(Content_ToStringChanged); base.DeregisterContentEvents(); } protected override void RegisterContentEvents() { base.RegisterContentEvents(); Content.ToStringChanged += new EventHandler(Content_ToStringChanged); } #region Event Handlers (Content) void Content_ToStringChanged(object sender, EventArgs e) { Rebuild(); } #endregion private BackgroundWorker worker; private void Rebuild() { if (worker != null) worker.CancelAsync(); worker = new BackgroundWorker(); worker.WorkerSupportsCancellation = true; Thread.Sleep(1); var bitmap = new Bitmap(Content.Rows*4, Content.Columns*4); worker.DoWork += (s, a) => { using (Graphics g = Graphics.FromImage(bitmap)) { for (int i = 0; i { if (!a.Cancelled) pictureBox.Image = bitmap; if (!worker.CancellationPending) worker = null; }; worker.RunWorkerAsync(); } protected override void OnContentChanged() { base.OnContentChanged(); if (Content == null) { pictureBox.Image = new Bitmap(1, 1); } else { Rebuild(); } } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); } #region Event Handlers (child controls) #endregion } }