Example #1
0
        private void inkCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (drawing)
            {
                Pen pen = new Pen(System.Drawing.Color.FromArgb(255,
                                                                mainView.ResultColor.R,
                                                                mainView.ResultColor.G,
                                                                mainView.ResultColor.B
                                                                ));
                pen.Width = Convert.ToSingle(mainView.BorderWidth);

                if (!mainView.IsExperiment)
                {
                    Image img = Image.FromHbitmap(tempBitmap.GetHbitmap());
                    mainView.WorkImage = new Bitmap(img);
                }

                Graphics   g     = Graphics.FromImage(mainView.WorkImage);
                SolidBrush brush = new SolidBrush(pen.Color);
                Point      point = e.GetPosition(inkCanvas);

                if (mainView.IsRectangle)
                {
                    RectangleF rect = new RectangleF(Math.Min((int)startPoint.X, (int)point.X),
                                                     Math.Min((int)startPoint.Y, (int)point.Y),
                                                     Math.Abs((int)point.X - (int)startPoint.X),
                                                     Math.Abs((int)point.Y - (int)startPoint.Y));
                    if (mainView.IsFill)
                    {
                        g.FillRectangle(brush, rect);
                    }
                    else
                    {
                        g.DrawRectangle(pen, System.Drawing.Rectangle.Round(rect));
                    }
                }
                else if (mainView.IsEllipse)
                {
                    RectangleF rect = new RectangleF((int)startPoint.X,
                                                     (int)startPoint.Y,
                                                     (int)point.X - (int)startPoint.X,
                                                     (int)point.Y - (int)startPoint.Y);
                    if (mainView.IsFill)
                    {
                        g.FillEllipse(brush, rect);
                    }
                    else
                    {
                        g.DrawEllipse(pen, System.Drawing.Rectangle.Round(rect));
                    }
                }
                else if (mainView.IsLine)
                {
                    g.DrawLine(pen, (int)startPoint.X,
                               (int)startPoint.Y,
                               (int)point.X,
                               (int)point.Y);
                }
                else if (mainView.IsText)
                {
                    g.DrawString(mainView.ResultText, mainView.ResultFont, brush, (int)point.X,
                                 (int)point.Y);
                }
                else if (mainView.IsArc)
                {
                    RectangleF rect = new RectangleF(Math.Min((int)startPoint.X, (int)point.X),
                                                     Math.Min((int)startPoint.Y, (int)point.Y),
                                                     Math.Abs((int)point.X - (int)startPoint.X),
                                                     Math.Abs((int)point.Y - (int)startPoint.Y));
                    try
                    {
                        g.DrawArc(pen, rect, mainView.StartAngle, mainView.SweepAngle);
                    }
                    catch { };
                }
                if (mainView.IsPie)
                {
                    System.Drawing.Rectangle rect = new System.Drawing.Rectangle(Math.Min((int)startPoint.X, (int)point.X),
                                                                                 Math.Min((int)startPoint.Y, (int)point.Y),
                                                                                 Math.Abs((int)point.X - (int)startPoint.X),
                                                                                 Math.Abs((int)point.Y - (int)startPoint.Y));
                    try
                    {
                        if (mainView.IsFill)
                        {
                            g.FillPie(brush, rect, mainView.StartAngle, mainView.SweepAngle);
                        }
                        else
                        {
                            g.DrawPie(pen, rect, mainView.StartAngle, mainView.SweepAngle);
                        }
                    }
                    catch { };
                }

                mainView.WorkImage = mainView.WorkImage;
            }
        }