C#GUI-使形状跟随鼠标并单击放置

问题描述

我正在开发一个基本的GUI Windows窗体应用程序。它允许用户使用滑动条更改颜色,使用滚动条更改形状的大小并单击复选框以确定是否应填充形状,如果单击清除按钮,则清除屏幕,并使用按钮在形状之间进行切换。我目前正在使用MouseMove事件来使形状跟随鼠标在面板内部移动。我也有一个MouseClick事件。当有鼠标单击时,我希望它“放置”该形状,以便图形得以保留。我已经能够将单个形状移动到用户单击的位置并使其跟随鼠标,但我只是不知道如何将两者结合在一起。

这是我到目前为止所拥有的:

        void DrawShape()
        {
            //g.Clear(Color.White);
            p.Color = Color.FromArgb(r,gr,b);
            if (IsChecked) // If checkBox is checked for fill
            {
                if (IsRect)
                {
                    g.FillRectangle(myBrush,left,top,wid,ht); // Filled Rectangle
                }
                else if (IsEllipse)
                {
                    g.FillEllipse(myBrush,ht); // Filled Ellipse
                }
            }
            else // not filled
            {
                if (IsRect) 
                {
                    g.DrawRectangle(p,ht); // empty rectangle
                }
                else if (IsEllipse)// empty ellipse
                {
                    g.DrawEllipse(p,ht);
                }
            }

        }
        private void panel1_MouseMove(object sender,MouseEventArgs e) // when mouse moves
        {
            left = e.X;
            top = e.Y;
            DrawShape();
        }
        private void panel1_MouseClick(object sender,MouseEventArgs e) //when mouse clicks
        {
            left = e.X;
            top = e.Y;
            IsClick = true;
            DrawShape();
            IsClick = false;
        }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)