您的位置:程序门 -> vb -> 多媒体



如何在picturebox在画个一个矩形框,并可以移动它,类似photoshop中选择框


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如何在picturebox在画个一个矩形框,并可以移动它,类似photoshop中选择框[已结贴,结贴人:nansa2000]
发表于:2007-04-27 16:35:26 楼主
如何在picturebox在画个一个矩形框,并可以移动它,类似photoshop中选择框,让用户保存框内截取的图片
发表于:2007-04-27 16:43:571楼 得分:2
用xor笔画或直接用shape控件的矩形,至于如何截取图片,可以计算。
发表于:2007-04-27 16:48:402楼 得分:0
用xor笔画没有用过,能不能指点一下啊

移动shape控件卡的很,不流畅
发表于:2007-04-27 19:06:203楼 得分:2
模范ps的选取框,俺以实现,不过不想公开代码,其实很简单,不超过100行代码!呵呵
发表于:2007-05-03 16:46:004楼 得分:2
同志们拿砖头砸楼上,呵呵
发表于:2007-05-03 17:18:535楼 得分:2
我没做过,友情帮顶
发表于:2007-05-03 17:29:146楼 得分:2
呵呵!
发表于:2007-05-08 10:01:277楼 得分:2
的确,“人一定要靠自己”。不过可以参考一下这个:http://community.csdn.net/expert/topic/5502/5502963.xml?temp=.7847559
发表于:2007-05-08 10:23:518楼 得分:0
答辩后公布那个代码,大家鼓励我吧,我就是不想写论文啊!郁闷!!!!!
发表于:2007-05-08 10:31:319楼 得分:2
mark
发表于:2007-05-09 10:48:4910楼 得分:2
记住矩形的位置宽度和高度,画的时候,以vbxorpan方式,第一次只画一次,你用鼠标移动后,先画一次,就会清除以前画的,再画一次,就是新的
发表于:2007-05-09 11:48:3511楼 得分:34
这是我写的代码
请新建一个工程,放一个图片框控件在窗体上,不改控件名称,放入以下代码

option   explicit

'矩形结构
private   type   rect
        left             as   long
        top               as   long
        right           as   long
        bottom         as   long
end   type

'操作类型
enum   optype
        none   =   0
        draw
        drag
end   enum


dim   rc   as   rect   '所画矩形
dim   ot   as   optype   '操作类型
dim   m_x   as   long   '当拖动矩形时,鼠标位置的   x   坐标
dim   m_y   as   long   '当拖动矩形时,鼠标位置的   y   坐标

private   sub   form_load()
        ot   =   none
        with   picture1
                .scalemode   =   vbpixels
                .autoredraw   =   false
                .appearance   =   0
        end   with
end   sub

private   sub   form_resize()
        picture1.move   scalex(8,   vbpixels,   scalemode),   scaley(8,   vbpixels,   scalemode),   _
                        scalewidth   -   scalex(16,   vbpixels,   scalemode),   _
                        scaleheight   -   scaley(16,   vbpixels,   scalemode)
end   sub

private   sub   picture1_mousedown(button   as   integer,   shift   as   integer,   x   as   single,   y   as   single)
        if   vbleftbutton   =   (button   and   vbleftbutton)   then
                select   case   ot
                case   optype.none
                        with   rc
                                if   x   >   .left   and   x   <   .right   and   y   >   .top   and   y   <   .bottom   then
                                        '如果已经画好了矩形,如果点击矩形范围内任意位置,则视为拖动矩形
                                        m_x   =   x
                                        m_y   =   y
                                        ot   =   drag
                                else
                                        '反之则视为重画矩形
                                        call   drawrect
                                        .left   =   x
                                        .right   =   x
                                        .top   =   y
                                        .bottom   =   y
                                        ot   =   draw
                                end   if
                        end   with
                case   optype.draw
                case   optype.drag
                end   select
        end   if
end   sub

private   sub   picture1_mousemove(button   as   integer,   shift   as   integer,   x   as   single,   y   as   single)
        if   vbleftbutton   =   (button   and   vbleftbutton)   then
                with   rc
                        select   case   ot
                        case   optype.none
                        case   optype.draw
                                '画矩形时,先画一次清除上次画的矩形
                                call   drawrect
                                '矩形的其中一个角不变
                                .right   =   x
                                .bottom   =   y
                                '再画新的矩形,达到移动矩形的目的
                                call   drawrect
                        case   optype.drag
                                '画矩形时,先画一次清除上次画的矩形
                                call   drawrect
                                '移动整个矩形
                                .left   =   .left   -   m_x   +   x
                                .top   =   .top   -   m_y   +   y
                                .right   =   .right   -   m_x   +   x
                                .bottom   =   .bottom   -   m_y   +   y
                                m_x   =   x
                                m_y   =   y
                                '再画新的矩形,达到移动矩形的目的
                                call   drawrect
                        end   select
                end   with
        end   if
end   sub

private   sub   picture1_mouseup(button   as   integer,   shift   as   integer,   x   as   single,   y   as   single)
        if   vbleftbutton   =   (button   and   vbleftbutton)   then
                select   case   ot
                case   optype.none
                case   optype.draw
                        '为了下次拖动,将矩形调整好,左边比右边的坐标小,上边比下边坐标小
                        dim   tmp   as   long
                        with   rc
                                if   .right   <   .left   then
                                        tmp   =   .right
                                        .right   =   .left
                                        .left   =   tmp
                                end   if
                                if   .bottom   <   .top   then
                                        tmp   =   .bottom
                                        .bottom   =   .top
                                        .top   =   tmp
                                end   if
                        end   with
                case   optype.drag
                end   select
                ot   =   none
        end   if
end   sub

'画矩形
private   sub   drawrect()
        with   rc
                if   .right   =   .left   or   .bottom   =   .top   then   exit   sub
                dim   drmode   as   integer
                drmode   =   picture1.drawmode
                picture1.drawmode   =   vbnotxorpen
                picture1.line   (.left,   .top)-(.right,   .bottom),   vbred,   b
                picture1.drawmode   =   drmode
        end   with
end   sub

'控件重画时,要重画矩形
private   sub   picture1_paint()
        picture1.cls
        call   drawrect
end   sub
发表于:2007-05-09 11:59:5512楼 得分:0
把   autoredraw   =   false   改为   autoredraw   =   true,可以去掉   private   sub   picture1_paint()
发表于:2007-05-13 13:26:3613楼 得分:0
该回复于2007-12-28 17:59:10被管理员或版主删除


快速检索

最新资讯
热门点击