| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 511 人关注过本帖
标题:GDI+画图问题
只看楼主 加入收藏
王祖品
Rank: 2
等 级:论坛游民
帖 子:31
专家分:20
注 册:2013-4-21
结帖率:27.27%
收藏
已结贴  问题点数:5 回复次数:2 
GDI+画图问题
我用GDI+画图,图已经画出来了。但是不知道该怎么选中所画的图,进行移动和拉伸。请高手帮帮忙。求具体代码!
2013-11-07 23:45
qw1161748579
Rank: 4
来 自:南充
等 级:业余侠客
威 望:1
帖 子:48
专家分:252
注 册:2013-9-23
收藏
得分:5 
你画的会不会是定了坐标的,把坐标改成变量,并且将图画花在panel之类的空间里面试试
2013-11-08 10:31
王祖品
Rank: 2
等 级:论坛游民
帖 子:31
专家分:20
注 册:2013-4-21
收藏
得分:0 
回复 2楼 qw1161748579
我是用变量画的,画在了windows窗口里面。主要代码如下:
 private void Frm_Main_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)//如果按下鼠标左键
            {
                //如果选择文字输入,则打开strInput窗体
                if (drawTool == drawTools.String)
                {
                    Frm_Text inputBox = new Frm_Text();
                    inputBox.StartPosition = FormStartPosition.CenterParent;
                    if (inputBox.ShowDialog() == DialogResult.OK)
                    {
                        Graphics g = this.CreateGraphics();
                        Font theFont = this.Font;
                        g.DrawString(inputBox.textBox1.Text, theFont, new SolidBrush(foreColor), e.X, e.Y);
                        ig.DrawString(inputBox.textBox1.Text, theFont, new SolidBrush(foreColor), e.X, e.Y);
                    }
                }
                //如果开始绘制,则开始记录鼠标位置
                else if ((isDrawing = !isDrawing) == true)
                {
                    startPoint = new Point(e.X, e.Y);
                    oldPoint = new Point(e.X, e.Y);
                }
            }
        }
 private void Frm_Main_MouseMove(object sender, MouseEventArgs e)
        {
            Graphics g;
            g = this.CreateGraphics();

            if (isDrawing)//如果开始绘图
            {
                switch (drawTool)
                {
                    case drawTools.None:
                        break;
                    case drawTools.Pen:
                        //从上一个点到当前点绘制线段
                        g.DrawLine(new Pen(foreColor, 1), oldPoint, new Point(e.X, e.Y));
                        ig.DrawLine(new Pen(foreColor, 1), oldPoint, new Point(e.X, e.Y));
                        oldPoint.X = e.X;
                        oldPoint.Y = e.Y;
                        break;
                    case drawTools.Line:
                        //首先恢复此次操作之前的图像,然后再添加Line
                        this.Frm_Main_Paint(this, new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle));
                        g.DrawLine(new Pen(foreColor, 1), startPoint, new Point(e.X, e.Y));
                        oldPoint.X = e.X;
                        oldPoint.Y = e.Y;
                        break;
                    case drawTools.Ellipse:
                        //首先恢复此次操作之前的图像,然后再添加Ellipse
                        this.Frm_Main_Paint(this, new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle));
                        g.DrawEllipse(new Pen(foreColor, 1), startPoint.X, startPoint.Y, e.X - startPoint.X, e.Y - startPoint.Y);
                        oldPoint.X = e.X;
                        oldPoint.Y = e.Y;
                        break;
                    case drawTools.Rectangle:
                        //首先恢复此次操作之前的图像,然后再添加Rectangle
                        this.Frm_Main_Paint(this, new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle));
                        g.DrawRectangle(new Pen(foreColor, 1), startPoint.X, startPoint.Y, e.X - startPoint.X, e.Y - startPoint.Y);
                        oldPoint.X = e.X;
                        oldPoint.Y = e.Y;
                        break;
                    case drawTools.String:
                        break;
                    case drawTools.Rubber:
                        //用背景色绘制宽线段
                        g.DrawLine(new Pen(backColor, 100), oldPoint, new Point(e.X, e.Y));
                        ig.DrawLine(new Pen(backColor, 100), oldPoint, new Point(e.X, e.Y));
                        oldPoint.X = e.X;
                        oldPoint.Y = e.Y;
                        break;
                    case drawTools.triangle:
                        //首先恢复此次操作之前的图像,然后再添加triangle
                        this.Frm_Main_Paint(this, new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle));
                        Pen mypen = new Pen(foreColor,1);
                        Point point1 = new Point(startPoint.X,e.Y);
                        Point point2 = new Point((startPoint.X+e.X)/2,startPoint.Y);
                        Point point3 = new Point(e.X,e.Y);
                        Point[] mypoints = {point1,point2,point3 };
                        g.DrawPolygon(mypen,mypoints);
                        oldPoint.X = e.X;
                        oldPoint.Y = e.Y;
                        break;
                }
            }
        }
private void Frm_Main_MouseUp(object sender, MouseEventArgs e)
        {
            isDrawing = false;
            switch (drawTool)
            {
                case drawTools.Line://画线
                    ig.DrawLine(new Pen(foreColor, 1), startPoint, new Point(e.X, e.Y));
                    break;
                case drawTools.Ellipse://画椭圆
                    ig.DrawEllipse(new Pen(foreColor, 1), startPoint.X, startPoint.Y, e.X - startPoint.X, e.Y - startPoint.Y);
                    break;
                case drawTools.Rectangle://画矩形
                    ig.DrawRectangle(new Pen(foreColor, 1), startPoint.X, startPoint.Y, e.X - startPoint.X, e.Y - startPoint.Y);
                    break;
                case drawTools.triangle://画三角形
                     Pen mypen = new Pen(foreColor,1);
                     Point point1 = new Point(startPoint.X,e.Y);
                     Point point2 = new Point((startPoint.X+e.X)/2,startPoint.Y);
                     Point point3 = new Point(e.X,e.Y);
                     Point[] mypoints = {point1,point2,point3 };
                     ig.DrawPolygon(mypen,mypoints);
                     break;
            }
        }
应该再写哪些代码,才能选中所画的图,并移动?
2013-11-08 16:27
快速回复:GDI+画图问题
数据加载中...
 
   



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

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