none
vb.net Bitmap 宽高问题 RRS feed

  • 问题

  • 1.我想问一下vb.net里面Bitmap的宽高的最大值是多少?超过最大值好像报错。。。。。

    2.现在有两个Picturebox两个是紧挨着的。按住鼠标左键在picturebox1上面开始画图,不过鼠标左键不放,离开Picturebox1,进Picturebox2的时候Picturebox2上面什么都不显示。两个picturebox离开一个进入另外一个继续画怎么实现。。。。


    muradil
    2011年8月30日 3:15

答案

  • 试试这个代码:

        Dim flag As Boolean = True
        Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
            If e.Button = Windows.Forms.MouseButtons.Left Then
                If e.X > Me.PictureBox1.Width + (Me.PictureBox2.Left - Me.PictureBox1.Right) Then
                    If flag = True Then
                        oldx = e.X - PictureBox1.Width - (Me.PictureBox2.Left - Me.PictureBox1.Right)
                        oldy = e.Y
                    End If
                    flag = False
                    Dim ee As New MouseEventArgs(e.Button, e.Clicks, e.X - PictureBox1.Width - (Me.PictureBox2.Left - Me.PictureBox1.Right), e.Y, e.Delta)
                    PictureBox2_MouseMove(Nothing, ee)
                Else
                    If flag = False Then
                        oldx = e.X + PictureBox1.Width + (Me.PictureBox2.Left - Me.PictureBox1.Right)
                    End If
                    flag = True
                    Dim g As Graphics = Me.PictureBox1.CreateGraphics
                    g.DrawLine(Pens.Black, oldx, oldy, e.X, e.Y)
                    oldx = e.X
                    oldy = e.Y
                End If
            End If
        End Sub
    
        Private Sub PictureBox2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseMove
            If e.Button = Windows.Forms.MouseButtons.Left Then
                Dim g As Graphics = Me.PictureBox2.CreateGraphics
                g.DrawLine(Pens.Black, oldx, oldy, e.X, e.Y)
                oldx = e.X
                oldy = e.Y
            End If
        End Sub

    以上代码实现了从picturebox1到2的连续画,你可以仿造着写从picturebox2到1的连续画

    Best regards,


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    2011年9月11日 10:18
    版主

全部回复

  • 在两个picturebox的mousemove事件里判断是不是有鼠标左键被按下的情况,有就画图,没有就不画。


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年8月31日 10:33
    版主
  • 情况不是左键被按下那么简单,因为你在一个picturebox里开始左键画的时候离开第一个picturebox的时候不会在第二个picturebox上面画。。。。
    muradil
    2011年9月2日 11:30
  • 那麻烦你再详细说明下你的情况有多么复杂.

    >因为你在一个picturebox里开始左键画的时候离开第一个picturebox的时候不会在第二个picturebox上面画。。。。

    你说的这句话到底是原因还是结果, 是你尝试后结果是没有在另一个picturebox上画,还是其他的?

    又或许你是按右键开始画,而不是左键?

    如果你尝试过我的建议, 那么可以贴出来你的代码吗?

    另外我还想问, 你有实现picturebox2的图形该怎么画吗? 如果没有,请按你的picturebox1里的方法在picturebox2里画图。


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年9月5日 4:46
    版主
  • Public Class Form1
    
        Private oldx, oldy As Integer
    
        Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
            If e.Button = Windows.Forms.MouseButtons.Left Then
                oldx = e.X
                oldy = e.Y
            End If
        End Sub
    
    
        Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
            If e.Button = Windows.Forms.MouseButtons.Left Then
                If e.X > Me.PictureBox1.Width Then
                    oldx = 0
                    oldy = e.Y
                    PictureBox2_MouseMove(sender, e)
                Else
                    Dim g As Graphics = Me.PictureBox1.CreateGraphics
                    g.DrawLine(Pens.Black, oldx, oldy, e.X, e.Y)
                    oldx = e.X
                    oldy = e.Y
                End If
            End If
        End Sub
    
        Private Sub PictureBox2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseMove
            If e.Button = Windows.Forms.MouseButtons.Left Then
                Dim g As Graphics = Me.PictureBox2.CreateGraphics
                g.DrawLine(Pens.Black, oldx, oldy, e.X, e.Y)
                oldx = e.X
                oldy = e.Y
            End If
    
        End Sub
    End Class

    两个picturebox是紧挨着的(左右),你试一下我这个代码,我觉得你不太明白我的意思。。。超过picturebox1的右边界限的时候在picturebox2上面开始画,当然没有放鼠标左键。。。。。看一下我这个代码。。。。。麻烦你了
    muradil
    2011年9月10日 9:38
  • 试试这个代码:

        Dim flag As Boolean = True
        Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
            If e.Button = Windows.Forms.MouseButtons.Left Then
                If e.X > Me.PictureBox1.Width + (Me.PictureBox2.Left - Me.PictureBox1.Right) Then
                    If flag = True Then
                        oldx = e.X - PictureBox1.Width - (Me.PictureBox2.Left - Me.PictureBox1.Right)
                        oldy = e.Y
                    End If
                    flag = False
                    Dim ee As New MouseEventArgs(e.Button, e.Clicks, e.X - PictureBox1.Width - (Me.PictureBox2.Left - Me.PictureBox1.Right), e.Y, e.Delta)
                    PictureBox2_MouseMove(Nothing, ee)
                Else
                    If flag = False Then
                        oldx = e.X + PictureBox1.Width + (Me.PictureBox2.Left - Me.PictureBox1.Right)
                    End If
                    flag = True
                    Dim g As Graphics = Me.PictureBox1.CreateGraphics
                    g.DrawLine(Pens.Black, oldx, oldy, e.X, e.Y)
                    oldx = e.X
                    oldy = e.Y
                End If
            End If
        End Sub
    
        Private Sub PictureBox2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseMove
            If e.Button = Windows.Forms.MouseButtons.Left Then
                Dim g As Graphics = Me.PictureBox2.CreateGraphics
                g.DrawLine(Pens.Black, oldx, oldy, e.X, e.Y)
                oldx = e.X
                oldy = e.Y
            End If
        End Sub

    以上代码实现了从picturebox1到2的连续画,你可以仿造着写从picturebox2到1的连续画

    Best regards,


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    2011年9月11日 10:18
    版主
  • 特别说明下, 测试的时候请把1放在左边,2放在右边,并且他们在同一个水平高度.


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年9月11日 10:31
    版主