| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 493 人关注过本帖
标题:新手求教几个用 C# 制作画板遇到的 bug
取消只看楼主 加入收藏
zhiweidabaon
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-5-13
结帖率:0
收藏
已结贴  问题点数:5 回复次数:0 
新手求教几个用 C# 制作画板遇到的 bug
我想问一下,1:为什么我做的画板最小化后画的图就没有了
2:当第二点的X或Y坐标大于第一点时,矩形无法绘制
3:我的左右键都响应绘图,我想改为只左键响应
一点分数聊表谢意啊

这是我的代码:
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;



namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        Pen MyPen = new System.Drawing.Pen(System.Drawing.Color.Red, 1);
        PointF pStart;
        PointF pEnd;
        PointF pWork;
        Boolean working;
        Boolean brushmode;
        String dmode = "line";
        void DrawShape(Graphics e,PointF startp,PointF endp,Boolean brushmode,Pen penmode,String domde)
        {
            Rectangle rect1 = new Rectangle((int)startp.X,(int)startp.Y,
                (int)(endp.X- startp.X),(int)(endp.Y - startp.Y));
            switch(dmode)
            {
                case"line":
                    e.DrawLine(penmode, startp.X,startp.Y,endp.X,endp.Y);
                    break;
                case"rect":
                    if(brushmode== true)   e.FillRectangle(penmode.Brush,rect1);
                else e.DrawRectangle(penmode,rect1);
                    break;
                case"circle":
                    if(brushmode== true)   e.FillEllipse(penmode.Brush,rect1);
                else e.DrawEllipse(penmode, rect1);
                    break;
                default:break;
            }
        }






        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            System.Drawing.Drawing2D.HatchBrush brush2 = new
            System.Drawing.Drawing2D.HatchBrush(
            System.Drawing.Drawing2D.HatchStyle.DarkDownwardDiagonal,
            Color.Brown);



        }

        private void BtnSetColor_Click(object sender, System.EventArgs e)
        {
            ColorDialog1.ShowDialog();
            //将窗体的背景颜色设置为选定的颜色
            BtnSetColor.BackColor = ColorDialog1.Color;



        }

        private void PictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            working = true;
            pStart.X = e.X;
            pStart.Y = e.Y;
            toolStripStatusLabel1.Text = "[" + e.X +  "," +  e.Y + "]";


        }

        private void PictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if(working== true)
            {
                pWork.X = e.X;
                pWork.Y = e.Y;
                toolStripStatusLabel1.Text = "[" + e.X + "," + e.Y + "]";
            }
        }

        private void PictureBox1_MouseUp(object sender,System.Windows.Forms.MouseEventArgs e)

        {
            if(working ==  true)
            {
                pEnd.X= e.X;
                pEnd.Y= e.Y;
                MyPen.Color= BtnSetColor.BackColor;
                MyPen.Width = (int)NumericUpDown1.Value;
                brushmode = CheckBox1.Checked;
                if(RadioButton1.Checked == true)
        MyPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                if(RadioButton2.Checked ==true)
        MyPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
                if(RadioButton3.Checked ==true)
        MyPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                if(RadioButton4.Checked ==true)
        MyPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
                if(RadioButton5.Checked ==true)
        MyPen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;
                if(RadioButton6.Checked ==true)
        MyPen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
                if(RadioButton7.Checked ==true)
                  dmode = "line";
                if(RadioButton8.Checked ==true)
                  dmode = "circle";
                if(RadioButton9.Checked ==true)
                  dmode = "rect";
                if(RadioButton10.Checked ==true)
        MyPen.Brush = new
        System.Drawing.Drawing2D.HatchBrush(
        System.Drawing.Drawing2D.HatchStyle.DarkDownwardDiagonal,
        MyPen.Color);
                if(RadioButton11.Checked ==true)
                MyPen.Brush = new
        System.Drawing.Drawing2D.HatchBrush(
        System.Drawing.Drawing2D.HatchStyle.Cross,MyPen.Color);
                if(RadioButton12.Checked == true)
                MyPen.Brush = new SolidBrush(MyPen.Color);
    DrawShape(PictureBox1.CreateGraphics(),
        pStart,pEnd,brushmode,MyPen,dmode);
                working = false;
            }

                  
        }

        private void BtnClear_Click(object sender,System. EventArgs e)
        {
            PictureBox1.CreateGraphics().Clear(BtnSetColor.BackColor);
        }

        private void PictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void ToolStripStatusLabel1_Click(object sender, EventArgs e)
        {

        }

      
        
        }

    }
搜索更多相关主题的帖子: public 制作 左右 
2014-05-13 19:53
快速回复:新手求教几个用 C# 制作画板遇到的 bug
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.047122 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved