Пример #1
0
        public FormsPlot()
        {
            Backend = new Control.ControlBackEnd(1, 1, "FormsPlot");
            Backend.Resize(Width, Height, useDelayedRendering: false);
            Backend.BitmapChanged        += new EventHandler(OnBitmapChanged);
            Backend.BitmapUpdated        += new EventHandler(OnBitmapUpdated);
            Backend.CursorChanged        += new EventHandler(OnCursorChanged);
            Backend.RightClicked         += new EventHandler(OnRightClicked);
            Backend.LeftClicked          += new EventHandler(OnLeftClicked);
            Backend.LeftClickedPlottable += new EventHandler(OnLeftClickedPlottable);
            Backend.AxesChanged          += new EventHandler(OnAxesChanged);
            Backend.PlottableDragged     += new EventHandler(OnPlottableDragged);
            Backend.PlottableDropped     += new EventHandler(OnPlottableDropped);
            Configuration = Backend.Configuration;

            if (IsDesignerMode)
            {
                try
                {
                    Configuration.WarnIfRenderNotCalledManually = false;
                    Plot.Title($"ScottPlot {Plot.Version}");
                    Plot.Render();
                }
                catch (Exception e)
                {
                    InitializeComponent();
                    pictureBox1.Visible     = false;
                    rtbErrorMessage.Visible = true;
                    rtbErrorMessage.Dock    = DockStyle.Fill;
                    rtbErrorMessage.Text    = "ERROR: ScottPlot failed to render in design mode.\n\n" +
                                              "This may be due to incompatible System.Drawing.Common versions or a 32-bit/64-bit mismatch.\n\n" +
                                              "Although rendering failed at design time, it may still function normally at runtime.\n\n" +
                                              $"Exception details:\n{e}";
                    return;
                }
            }

            Cursors = new Dictionary <Cursor, System.Windows.Forms.Cursor>()
            {
                [ScottPlot.Cursor.Arrow]     = System.Windows.Forms.Cursors.Arrow,
                [ScottPlot.Cursor.WE]        = System.Windows.Forms.Cursors.SizeWE,
                [ScottPlot.Cursor.NS]        = System.Windows.Forms.Cursors.SizeNS,
                [ScottPlot.Cursor.All]       = System.Windows.Forms.Cursors.SizeAll,
                [ScottPlot.Cursor.Crosshair] = System.Windows.Forms.Cursors.Cross,
                [ScottPlot.Cursor.Hand]      = System.Windows.Forms.Cursors.Hand,
                [ScottPlot.Cursor.Question]  = System.Windows.Forms.Cursors.Help,
            };

            InitializeComponent();

            rtbErrorMessage.Visible = false;
            pictureBox1.BackColor   = System.Drawing.Color.Transparent;
            Plot.Style(figureBackground: System.Drawing.Color.Transparent);
            pictureBox1.MouseWheel += PictureBox1_MouseWheel;
            RightClicked           += DefaultRightClickEvent;

            Backend.StartProcessingEvents();
        }
Пример #2
0
        public WpfPlot()
        {
            Backend = new Control.ControlBackEnd(1, 1, GetType().Name);
            Backend.Resize((float)ActualWidth, (float)ActualHeight, useDelayedRendering: false);
            Backend.BitmapChanged              += new EventHandler(OnBitmapChanged);
            Backend.BitmapUpdated              += new EventHandler(OnBitmapUpdated);
            Backend.CursorChanged              += new EventHandler(OnCursorChanged);
            Backend.RightClicked               += new EventHandler(OnRightClicked);
            Backend.LeftClicked                += new EventHandler(OnLeftClicked);
            Backend.LeftClickedPlottable       += new EventHandler(OnLeftClickedPlottable);
            Backend.AxesChanged                += new EventHandler(OnAxesChanged);
            Backend.PlottableDragged           += new EventHandler(OnPlottableDragged);
            Backend.PlottableDropped           += new EventHandler(OnPlottableDropped);
            Backend.Configuration.ScaleChanged += new EventHandler(OnScaleChanged);
            Configuration = Backend.Configuration;

            if (DesignerProperties.GetIsInDesignMode(this))
            {
                try
                {
                    Configuration.WarnIfRenderNotCalledManually = false;
                    Plot.Title($"ScottPlot {Plot.Version}");
                    Plot.Render();
                }
                catch (Exception e)
                {
                    InitializeComponent();
                    PlotImage.Visibility = System.Windows.Visibility.Hidden;
                    ErrorLabel.Text      = "ERROR: ScottPlot failed to render in design mode.\n\n" +
                                           "This may be due to incompatible System.Drawing.Common versions or a 32-bit/64-bit mismatch.\n\n" +
                                           "Although rendering failed at design time, it may still function normally at runtime.\n\n" +
                                           $"Exception details:\n{e}";
                    return;
                }
            }

            Cursors = new Dictionary <Cursor, System.Windows.Input.Cursor>()
            {
                [ScottPlot.Cursor.Arrow]     = System.Windows.Input.Cursors.Arrow,
                [ScottPlot.Cursor.WE]        = System.Windows.Input.Cursors.SizeWE,
                [ScottPlot.Cursor.NS]        = System.Windows.Input.Cursors.SizeNS,
                [ScottPlot.Cursor.All]       = System.Windows.Input.Cursors.SizeAll,
                [ScottPlot.Cursor.Crosshair] = System.Windows.Input.Cursors.Cross,
                [ScottPlot.Cursor.Hand]      = System.Windows.Input.Cursors.Hand,
                [ScottPlot.Cursor.Question]  = System.Windows.Input.Cursors.Help,
            };

            RightClicked += DefaultRightClickEvent;

            InitializeComponent();

            ErrorLabel.Visibility = System.Windows.Visibility.Hidden;

            Backend.StartProcessingEvents();
        }