积极答复者
vb.net Bitmap 宽高问题

问题
答案
-
试试这个代码:
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.
- 已编辑 Mike FengModerator 2011年9月11日 10:55
- 已标记为答案 穆拉迪力 2011年9月11日 11:10
全部回复
-
在两个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.
- 已标记为答案 Mike FengModerator 2011年9月9日 6:10
- 取消答案标记 穆拉迪力 2011年9月10日 10:00
-
那麻烦你再详细说明下你的情况有多么复杂.
>因为你在一个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.
-
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 -
试试这个代码:
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.
- 已编辑 Mike FengModerator 2011年9月11日 10:55
- 已标记为答案 穆拉迪力 2011年9月11日 11:10
-
特别说明下, 测试的时候请把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.