タイトル : PictureBoxのサイズをドラッグで変更 投稿日 : 2008/03/08(Sat) 08:14 投稿者 : ゆうき
ゆうきです。おはようございます。 マウスのドラッグで、ペイントのようにPictureBoxのサイズを変更したいのですが、 http://hanatyan.sakura.ne.jp/samplepic/vb8_239.htm を参考に、幅を変更するのは実装できました。 しかし、たてを別のラベルで同じようにやろうとすると、ラベルをドラッグしたときに、 PictureBoxがどこかへ行ってしまいます。 サンプルは Dim posx As Long Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown If e.Button = System.Windows.Forms.MouseButtons.Left Then posx = e.X End If End Sub Private Sub Label1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove If e.Button = System.Windows.Forms.MouseButtons.Left Then Dim X1 As Long = posx - e.X Label1.Left -= X1 PictureBox1.Width -= X1 End If End Sub となっていたので、たてをやるとき、 Dim posy As Long Private Sub Label2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label2.MouseDown If e.Button = System.Windows.Forms.MouseButtons.Left Then posy = e.Y End If End Sub Private Sub Label2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label2.MouseMove If e.Button = System.Windows.Forms.MouseButtons.Left Then Dim Y1 As Long = posy - e.Y Label1.Top -= Y1 PictureBox1.Height -= Y1 End If End Sub こうしました。 YをXに変えただけですが、何が悪いかわかりません。 よろしくお願いします。 |