zoukankan      html  css  js  c++  java
  • 有个问题请教一下大家

       我刚学c#,做了一个简单画板,用画笔在画板上滑了一些内容,但是一旦最小化或者内容被遮挡就会消失。请问这是怎么回事呢。附上源代码

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

    using System.Windows.Forms;

     

     

    //画板内容消失

    //三角形画不出来;

    //很多需要优化的地方

    //还想实现插入图片

    namespace WindowsHuaBu

    {

        public partial class Form1 : Form

        {

            Point start, end;

            Bitmap bmp;

           public Form1()

            {

                InitializeComponent();

     

            }   

            private void btnSave_Click(object sender, EventArgs e)

            {

                SaveFileDialog dlg = new SaveFileDialog();

                if (dlg.ShowDialog() == DialogResult.OK)

                {

                    bmp.Save(dlg.FileName);

                }

     

            }

     

       private void btnAgain_Click(object sender, EventArgs e)

            {

                Form2 frm = new Form2();

                frm.ShowDialog();         

            }

           List<Paint> paintList = new List<Paint>();

            private void Form1_MouseDown_1(object sender, MouseEventArgs e)

            {

                start = new Point(e.X, e.Y);

              

            }

          

            Shape shape = Shape.铅笔;

            Pen pen = new Pen(Color.Black, 2);

     

            private void Form1_MouseUp_1(object sender, MouseEventArgs e)

            {

                end = new Point(e.X, e.Y);

                points.Clear();

     

                end = e.Location;

                Graphics g = this.CreateGraphics();

                switch (shape)

                {

                    case Shape.线:

                        g.DrawLine(pen, start, end);

                        break;

                    case Shape.矩形:

                        g.DrawRectangle(pen, start.X, start.Y, end.X - start.X, end.Y - start.Y);

                        break;

                    case Shape.:

                        g.DrawEllipse(pen, start.X, start.Y, end.X - start.X, end.Y - start.Y);

                        break;

                    case Shape.三角形:

                        break;

                    case Shape.铅笔:

                        pen.Color = Color.Black;

                        pen.Width = 2;

                     

                        break;

                    default:

                        break;

                }

                paintList.Add(new Paint(start, end, pen, shape));

            }

     

                private void btnPen_Click(object sender, EventArgs e)

            {

                shape = Shape.铅笔;

            }

     

            private void btnLine_Click(object sender, EventArgs e)

            {

                shape = Shape.线;

            }

     

            private void btnElli_Click(object sender, EventArgs e)

            {

                shape = Shape.;

            }

     

            private void btnRect_Click(object sender, EventArgs e)

            {

                shape = Shape.矩形;

            }

         

            private void btnRect_Click_1(object sender, EventArgs e)

            {

                shape = Shape.三角形;

            }

               

     

            List<Point> points=new List<Point>();

            private void Form1_MouseMove(object sender, MouseEventArgs e)

            {

                if (shape == Shape.铅笔)

                {

     

                    if (e.Button == MouseButtons.Left)

                    {

                        if (points.Count == 0)

                        {

                            points.Add(start);

     

                        }

                        Graphics g = this.CreateGraphics();

     

                        g.DrawLine(pen, points[points.Count - 1], new Point(e.X, e.Y));

                        points.Add(new Point(e.X, e.Y));

                    }

                }

            }

           

            private void btnMore_Click(object sender, EventArgs e)

            {

                 ColorDialog MyDiolog = new ColorDialog();

                MyDiolog.AllowFullOpen = false;

                MyDiolog.ShowHelp = true;

                MyDiolog.Color = btnMore.BackColor;

     

                if (MyDiolog.ShowDialog() == DialogResult.OK)

                {

                    btnMore.BackColor = MyDiolog.Color;

                }

     

                pen.Color = btnMore.BackColor;

            }

     

            List<Paint> paintlist=new List<Paint>();

            private void Form1_Load(object sender, EventArgs e)

            {

                Graphics g = this.CreateGraphics();

                foreach (Paint p in paintList)

                {

                    g.DrawLine(p.p, p.start, p.end);

                }

            }

     

            private void btnBlack_Click(object sender, EventArgs e)

            {

                pen.Color = Color.Black;

            }

     

            private void btnYel_Click(object sender, EventArgs e)

            {

                pen.Color = Color.Yellow;

            }

          

            private void btnRed_Click(object sender, EventArgs e)

            {

                pen.Color = Color.Red;

            }

     

            private void btnBro_Click(object sender, EventArgs e)

            {

                pen.Color = Color.RosyBrown;

            }

           

            private void btnBlue_Click(object sender, EventArgs e)

            {

                pen.Color = Color.Blue;

            }

     

            private void btnFuch_Click(object sender, EventArgs e)

            {

                pen.Color = Color.Fuchsia;

            }

     

            private void btnGre_Click(object sender, EventArgs e)

            {

                pen.Color = Color.Green;

            }

     

            private void btnClear_Click(object sender, EventArgs e)

            {

                pen.Color = Color.White;

                pen.Width = 15;

            }

     

            private void btnClose_Click(object sender, EventArgs e)

            {

                this.Close();

            }

     

        }

    }

  • 相关阅读:
    Visual Studio自带的的Developer Command Prompt对话框
    利用VS(Visual Studio)自带的工具查看DLL文件的信息
    谷歌面试官反馈级别
    Inno Setup中多语言时,使用占位符填充
    SQL*Plus命令
    Oracle 所有字典
    彻底完全卸载 SQL Server 2005 的图文教程
    win7(windows 7)系统下安装SQL2005(SQL Server 2005)图文教程
    创建表空间、新增用户、给用户赋予DBA权限 、删除用户下的上有数据表
    ORA-01012: not logged on
  • 原文地址:https://www.cnblogs.com/yanpu/p/3480972.html
Copyright © 2011-2022 走看看