首页 新闻 会员 周边 捐助

C#编程,矩形为什么不再mousemove中画出?代码是写在mousemove中呀?

0
悬赏园豆:80 [已关闭问题] 关闭于 2011-05-10 14:22

using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.VisualBasic.PowerPacks;
using VLK.CommonClass;
using System.Drawing.Drawing2D;

 

namespace VLK
{
    public partial class frmMain : Form
    {
        int screenhori;
        int screenver;
        int screentotal;
        long picwidthlen;
        long picheightlen;
        Point startPoint;
        Point endPoint;
        Point realStart;
        Point realEnd;

 

        //private bool mouseStatus = false;//鼠标状态,false为松开  

 

        Microsoft.VisualBasic.PowerPacks.ShapeContainer canvas = new ShapeContainer();
        Microsoft.VisualBasic.PowerPacks.RectangleShape theShape = new RectangleShape();

        public frmMain()
        {
            InitializeComponent();
          
        }

        private void frmMain_Load(object sender, EventArgs e)
        {

           

            DataCon dataconnum = new DataCon();
            DataOperate dataoperatenum = new DataOperate();
            string strSqlscreennum = "select screenhorinum,screenvernum  from tb_screenset where ID=1";
            DataSet dsscreennum = dataoperatenum.getDs(strSqlscreennum, "tb_screenset");

            screenhori = (int)dsscreennum.Tables[0].Rows[0]["screenhorinum"];
            screenver = (int)dsscreennum.Tables[0].Rows[0]["screenvernum"];
            screentotal = screenver * screenhori;

            picwidthlen = Panl_Screen.Width / screenhori;
            picheightlen = Panl_Screen.Width / screenver;
            //if (screentotal > 1)
            //{
                PictureBox[] PictureBoxArray = new PictureBox[screentotal];
                //PictureBoxArray[0] = new PictureBox();
                //PictureBoxArray[0] = Pic_Screen;

                for (int i = 0; i < screentotal-1; i++)
                {
                    PictureBoxArray[i] = new PictureBox();
                    PictureBoxArray[i].Name = "Pic_Screen" + i;
                    //PictureBoxArray[i].Parent = Panl_Screen;
                   
                    Panl_Screen.Controls.Add(PictureBoxArray[i]);
                   

                }


                Panl_Screen.Controls.Add(canvas);

                canvas.Parent = Panl_Screen;
                theShape.Parent = canvas;
                canvas.Visible = false;
                theShape.Visible = false;
                theShape.BorderColor = Color.Red;
                theShape.BorderStyle = System.Drawing.Drawing2D.DashStyle.Dot;
                canvas.SendToBack();

                Panl_Screen.Controls.Add(shapewinsy1);
                shapewinsy1.Parent = Panl_Screen;
                shapewinsy1.BackColor = Color.Transparent;
               

                for (int i = 0; i < screentotal-1; i++)
                {
                    PictureBoxArray[i].MouseDown += new System.Windows.Forms.MouseEventHandler(this.PictureBoxArray_MouseDown);
                    PictureBoxArray[i].MouseMove += new System.Windows.Forms.MouseEventHandler(this.PictureBoxArray_MouseMove);
                    PictureBoxArray[i].MouseUp += new System.Windows.Forms.MouseEventHandler(this.PictureBoxArray_MouseUp);
                   

                    PictureBoxArray[i].Location = new System.Drawing.Point((i % screenhori) * (int)picwidthlen, (i / screenhori) * (int)picheightlen);//图像的位置,以左上角定位
                    PictureBoxArray[i].Size = new System.Drawing.Size((int)picwidthlen, (int)picheightlen);//图像的大小
                    PictureBoxArray[i].Image = imageListScreen.Images[1];
                    PictureBoxArray[i].SizeMode = PictureBoxSizeMode.StretchImage;
                    PictureBoxArray[i].Tag = i;
                    PictureBoxArray[i].SendToBack();
                }         

                     
        }


      

        public void PictureBoxArray_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
           


            if (e.Button == MouseButtons.Left)
            {

                //mouseStatus = true;
                int n;
                PictureBox gtnum = (PictureBox)sender;
                n = (int)gtnum.Tag;
                startPoint.X = e.X + (n % screenhori) * (int)picwidthlen;
                startPoint.Y = e.Y + (n / screenhori) * (int)picheightlen;

 

            }
        }

        public void PictureBoxArray_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            //程序逻辑 
            //提示 ((PictureBox)sender)  可以操作触发此事件的控件对象

            if (e.Button == MouseButtons.Left)
            {

                //if (mouseStatus)
                //{
                    canvas.Visible = false;
                    theShape.Visible = false;
                    canvas.SendToBack();
                int n;
                PictureBox gtnu = (PictureBox)sender;
                n = (int)gtnu.Tag;
                endPoint.X = e.X + (n % screenhori) * (int)picwidthlen;
                endPoint.Y = e.Y + (n / screenhori) * (int)picheightlen;
                realStart.X = Math.Min(startPoint.X, endPoint.X);
                realStart.Y = Math.Min(startPoint.Y, endPoint.Y);
                realEnd.X = Math.Max(startPoint.X, endPoint.X);
                realEnd.Y = Math.Max(startPoint.Y, endPoint.Y);


                canvas.Location = realStart;
                canvas.Width = realEnd.X - realStart.X;
                canvas.Height = realEnd.Y - realStart.Y;
                theShape.Location = realStart;
                theShape.Width = realEnd.X - realStart.X;
                theShape.Height = realEnd.Y - realStart.Y;
                canvas.Visible = true;
                theShape.Visible = true;
                canvas.BringToFront();
                this.UpdateZOrder();


                //}

            }

 

        }

        public void PictureBoxArray_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            //程序逻辑 
            //提示 ((PictureBox)sender)  可以操作触发此事件的控件对象
            //mouseStatus = false;

            //theShape.Visible = false;
            //canvas.SendToBack();


        }

  

            }
        }

不好意思,分不多了,谁能帮俺解决,俺把全部的分都给他

问题补充: RectangleShape 是引用VB.Net里面的控件,是不是这个控件的问题呢?
rainwolf2010的主页 rainwolf2010 | 初学一级 | 园豆:200
提问于:2011-05-05 22:54
< >
分享
所有回答(1)
0

我看你的代码意思是不是在mousemove中记录矩形的点,再在mouseup的时候再画图啊!你这个不是GDI+吗?

小小刀 | 园豆:1991 (小虾三级) | 2011-05-06 16:04
就是通过一个控件RectangleShape来显示矩形框呀,在mousemove中画图的。就是不知道明明在mousemove中 canvas.Visible = true; theShape.Visible = true;
为什么还不显示,还等到mouseup了才显示。
是GDI+ 呀
支持(0) 反对(0) rainwolf2010 | 园豆:200 (初学一级) | 2011-05-06 19:29
你再将你的mouseup事件的代码帖出来看一看,可能是在里面才画图的。
支持(0) 反对(0) 小小刀 | 园豆:1991 (小虾三级) | 2011-05-07 09:39
代码贴出来了,怎么乱成这个样子了
支持(0) 反对(0) rainwolf2010 | 园豆:200 (初学一级) | 2011-05-07 21:14
@小小刀:有邮箱吗?我给你发邮箱可以吗?在帖子上看起来太乱
支持(0) 反对(0) rainwolf2010 | 园豆:200 (初学一级) | 2011-05-07 21:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册