| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 849 人关注过本帖
标题:遇到直线拖动问题,求帮助!
只看楼主 加入收藏
zixiacherry
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2011-8-1
结帖率:66.67%
收藏
已结贴  问题点数:0 回复次数:10 
遇到直线拖动问题,求帮助!
未命名.rar (7.12 KB)


我想实现在运行后,用鼠标点击a点或b点拖动,能使对应的直线可以上下左右移动。

我是个初学者,还不懂,又着急用,请求高人给编写代码。请专家伸出援助之手,感激不尽,万分感谢!!
搜索更多相关主题的帖子: 鼠标 移动 
2011-08-01 15:43
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:10 
Option Explicit

Private Type 坐标类型
   X As Integer
   Y As Integer
End Type

Dim A As 坐标类型
Dim B As 坐标类型

Dim MD As Integer
'MD ,鼠标状态
'=0 ,无操作,1=拖动A,2=拖动B

Private Sub Form_Load()

MD = 0

A.X = 500
A.Y = 500
B.X = 2000
B.Y = 2000


End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button = 1 Then
    If Abs(X - A.X) < 75 And Abs(Y - A.Y) < 75 Then
        MD = 1
        Me.MousePointer = vbSizeAll
    ElseIf Abs(X - B.X) < 75 And Abs(Y - B.Y) < 75 Then
        MD = 2
        Me.MousePointer = vbSizeAll
     Else
        Me.MousePointer = vbDefault
    End If
Else
    Me.MousePointer = vbDefault
End If

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If MD = 1 Then
        A.X = X
        A.Y = Y
        Call Form_Paint
    ElseIf MD = 2 Then
        B.X = X
        B.Y = Y
        Call Form_Paint
   
    End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    MD = 0
    Me.MousePointer = vbDefault
   
End Sub

Private Sub Form_Paint()

With Me
    .Cls
    Me.Line (A.X, 0)-(A.X, A.Y)
    Me.Line (0, A.Y)-(A.X, A.Y)
   
    Me.Line (B.X, Me.ScaleHeight)-(B.X, B.Y)
    Me.Line (Me.ScaleWidth, B.Y)-(B.X, B.Y)

End With

End Sub

授人于鱼,不如授人于渔
早已停用QQ了
2011-08-01 17:46
msgj
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:4
帖 子:190
专家分:914
注 册:2009-10-3
收藏
得分:0 
看看是不是要这个效果:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If MD = 1 Then
        B.X = B.X + (X - A.X)
        B.Y = B.Y + (Y - A.Y)
        A.X = X
        A.Y = Y
        Call Form_Paint
    ElseIf MD = 2 Then
        A.X = A.X + (X - B.X)
        A.Y = A.Y + (Y - B.Y)
        B.X = X
        B.Y = Y
        Call Form_Paint
    End If
End Sub
Private Sub Form_Paint()
With Me
    .Cls
    Me.Line (A.X, A.Y)-(B.X, B.Y)
End With
End Sub
2011-08-02 19:09
zixiacherry
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2011-8-1
收藏
得分:0 
回复 2楼 风吹过b
首先谢谢高手,程序可以运行,但是为啥运行的图上又多出两条线,还请高手给看看,太谢谢了啊!
图片附件: 游客没有浏览图片的权限,请 登录注册


[ 本帖最后由 zixiacherry 于 2011-8-2 21:29 编辑 ]
2011-08-02 21:21
zixiacherry
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2011-8-1
收藏
得分:0 
回复 3楼 msgj
运行时出现错误  Me.Line (A.X, A.Y)-(B.X, B.Y)有问题,请高手再给看看,万分感谢!
2011-08-02 21:23
msgj
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:4
帖 子:190
专家分:914
注 册:2009-10-3
收藏
得分:0 
是不是原来的代码没删除?
全:
Option Explicit
Private Type 坐标类型
   X As Integer
   Y As Integer
End Type
Dim A As 坐标类型
Dim B As 坐标类型
Dim MD As Integer
'MD ,鼠标状态
'=0 ,无操作,1=拖动A,2=拖动B
Private Sub Form_Load()
MD = 0
A.X = 500
A.Y = 500
B.X = 2000
B.Y = 2000
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
    If Abs(X - A.X) < 75 And Abs(Y - A.Y) < 75 Then
        MD = 1
        Me.MousePointer = vbSizeAll
    ElseIf Abs(X - B.X) < 75 And Abs(Y - B.Y) < 75 Then
        MD = 2
        Me.MousePointer = vbSizeAll
     Else
        Me.MousePointer = vbDefault
    End If
Else
    Me.MousePointer = vbDefault
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If MD = 1 Then
        B.X = B.X + (X - A.X)
        B.Y = B.Y + (Y - A.Y)
        A.X = X
        A.Y = Y
        Call Form_Paint
     ElseIf MD = 2 Then
        A.X = A.X + (X - B.X)
        A.Y = A.Y + (Y - B.Y)
        B.X = X
        B.Y = Y
        Call Form_Paint
    End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    MD = 0
    Me.MousePointer = vbDefault
End Sub
Private Sub Form_Paint()
With Me
    .Cls
    Me.Line (A.X, A.Y)-(B.X, B.Y)
End With
End Sub
2011-08-02 22:11
zixiacherry
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2011-8-1
收藏
得分:0 
回复 6楼 msgj
我把代码都删了  才粘进去的,你给的这个代码和之前的那个不一样了,运行起来不能拖动了,而且还多了条斜线出来,而且斜线可以自由移动,好奇怪。
图片附件: 游客没有浏览图片的权限,请 登录注册
2011-08-02 22:49
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:0 
又出现二条直线是你原来那二根直线。

我程序里是使用画线的方式显示直线的,不影响你原来的直线。

授人于鱼,不如授人于渔
早已停用QQ了
2011-08-03 08:52
zixiacherry
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2011-8-1
收藏
得分:0 
回复 8楼 风吹过b
  嗯,明白啦! 高手 你太厉害了!!! 太感谢了!!!!!
 
就是我还有个小问题,能不能实现在直线拖动的时候,不允许交叉???
还请高手帮助一下,万分感谢!!!
2011-08-03 11:15
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:0 
怎么交叉??


这个函数中 判断 坐标关系 。
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If MD = 1 Then
        B.X = B.X + (X - A.X)
        B.Y = B.Y + (Y - A.Y)
        A.X = X
        A.Y = Y
        Call Form_Paint
     ElseIf MD = 2 Then
        A.X = A.X + (X - B.X)
        A.Y = A.Y + (Y - B.Y)
        B.X = X
        B.Y = Y
        Call Form_Paint
    End If
'坐标关系
   
End Sub

然后,不能再拖动时,置 MD =0 ,置鼠标状态 Me.MousePointer = vbDefault

授人于鱼,不如授人于渔
早已停用QQ了
2011-08-03 15:48
快速回复:遇到直线拖动问题,求帮助!
数据加载中...
 
   



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

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