Exemplo n.º 1
0
        private void DrawingForm_MounseUP(object sender, MouseEventArgs e)      //鼠标抬起事件
        {
            Graphics graphics = DrawingForm.CreateGraphics();

            if (isDrawing)
            {
                switch (drawTool)
                {
                case toolBox.line:        //画直线
                    graphics.DrawLine(new Pen(color, size), startPoint, oldPoint);
                    break;

                case toolBox.rectangle:        //画矩形
                    graphics.DrawRectangle(new Pen(color, size), startPoint.X, startPoint.Y, oldPoint.X - startPoint.X, oldPoint.Y - startPoint.Y);
                    break;

                case toolBox.ellipese:        //画圆
                    graphics.DrawEllipse(new Pen(color, size), startPoint.X, startPoint.Y, oldPoint.X - startPoint.X, oldPoint.Y - startPoint.Y);
                    break;

                case toolBox.triangle:
                    graphics.DrawLine(new Pen(color, size), startPoint, oldPoint);
                    graphics.DrawLine(new Pen(color, size), startPoint.X, startPoint.Y, (startPoint.X + startPoint.X - oldPoint.X), oldPoint.Y);
                    graphics.DrawLine(new Pen(color, size), (startPoint.X + startPoint.X - oldPoint.X), oldPoint.Y, oldPoint.X, oldPoint.Y);
                    graphics.DrawLine(new Pen(color, size), startPoint, startPoint);
                    graphics.DrawLine(new Pen(color, size), oldPoint, oldPoint);
                    graphics.DrawLine(new Pen(color, size), (startPoint.X + startPoint.X - oldPoint.X), oldPoint.Y, (startPoint.X + startPoint.X - oldPoint.X), oldPoint.Y);
                    break;
                }
            }
            isDrawing = false;
        }
Exemplo n.º 2
0
        private void Form1_MouseMove(object sender, MouseEventArgs e)    //鼠标移动事件
        {
            //MessageBox.Show("Yes");
            if (isDrawing == true)
            {
                //MessageBox.Show("Yes again!");
                Graphics graphics = DrawingForm.CreateGraphics();
                switch (drawTool)
                {
                case toolBox.pen:
                    graphics.DrawLine(new Pen(color, size), oldPoint, new Point(e.X, e.Y)); //使用画笔画直线
                    oldPoint.X = e.X;                                                       //更新画图直线的初始坐标
                    oldPoint.Y = e.Y;
                    break;

                case toolBox.eraser:
                    graphics.DrawLine(new Pen(Color.White, size), oldPoint, new Point(e.X, e.Y));        //使用白笔画图,覆盖原来画的图
                    oldPoint.X = e.X;
                    oldPoint.Y = e.Y;
                    break;

                default:
                    oldPoint.X = e.X;
                    oldPoint.Y = e.Y;
                    break;
                }
            }
        }
Exemplo n.º 3
0
        private void 新建ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Graphics graphics = DrawingForm.CreateGraphics();

            if (isSave == true)
            {
                graphics.Clear(Color.White);     //重置画图板
            }
            else
            {
                string       name   = this.Text;
                DialogResult result = MessageBox.Show("                  是否将更改保存到" + name, "狐仙魔法书", MessageBoxButtons.YesNoCancel);
                switch (result)
                {
                case DialogResult.Yes:             //执行保存操作
                    保存ToolStripMenuItem_Click(sender, e);
                    break;

                case DialogResult.No:                      //重置画板
                    graphics.Clear(Color.White);
                    isSave = true;
                    break;

                case DialogResult.Cancel:                   //取消什么都不做
                    break;
                }
            }
        }
Exemplo n.º 4
0
 private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     //MessageBox.Show(isSave.ToString());
     if (isSave == true)
     {
         OpenFileDialog openFileDialog = new OpenFileDialog();
         openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);  //默认桌面作为打开文件路径
         openFileDialog.Filter           = "PNG(*.png)|*.png | GIF(*.gif)|*.gif | ICO(*.ico)|*.ico | JPEG(*.jpg,*.jpeg,*.jpe,*.jfif)|*.jpg;*jpeg;*jpe;*jfif | 所有图片文件|*.png;*.gif;*.bmp;*.wmf;*.ico;*.cur;*.jpg;*.jpeg;*.jpe*,jfif  | 所有文件(.)|*.*";
         openFileDialog.FilterIndex      = 5;
         if (openFileDialog.ShowDialog() == DialogResult.OK)
         {
             Graphics graphic = DrawingForm.CreateGraphics();
             Image    image   = Bitmap.FromFile(openFileDialog.FileName);
             graphic.DrawImage(image, this.ClientRectangle);
             this.Text = openFileDialog.FileName.Substring(openFileDialog.FileName.IndexOf("//") + 1);
             filePath  = openFileDialog.FileName;
         }
     }
 }