I draw an vector graphics in a picture box and I want to zoom window in that picture box by mouse. How to write a code to zoom window in that picture

  • Thread starter Thread starter Hany Metry
  • Start date Start date
H

Hany Metry

Guest
Hi,

I draw an vector graphics in a picture box and I want to zoom window in that picture box by mouse. How to write a code to zoom window in that picture box and how to back the drawing to its original state.

The below code is only suggest and maybe need some additional code or some improvement.

The below code provide Xini = 0 and Yini = 0, That the zoom window start from point (0,0).

I don't know my mistake but maybe mouse left button double click does not read e.X and e.y?

Is it possible to make left button click instead of left button double click?

Can we store the the value of Xcorner and Ycorner at the start mouse down, to make it equal to Xini and Yini?

I need also to improve that code.

Dim Xini As Integer
Dim Yini As Integer
Dim Xcorner As Integer
Dim Ycorner As Integer
Dim MouseStatus As Integer
Dim Mimi As Integer
Private Sub PictureBox2_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox2.Paint
Dim mpen4 As Pen = New Pen(Color.LightGray, 2.0F)
mpen4.DashStyle = Drawing2D.DashStyle.Dash
If MouseStatus = 1 And CheckBox1.Checked = True Then
e.Graphics.DrawRectangle(mpen4, Xini, Yini, Xcorner - Xini, Ycorner - Yini)
End If
Private Sub PictureBox2_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox2.MouseDown
If CheckBox1.Checked = True Then
MouseStatus = 1
Xcorner = e.X
Ycorner = e.Y
End If
End Sub
Private Sub PictureBox2_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox2.MouseMove
If CheckBox1.Checked = True And MouseStatus = 1 Then
Xcorner = e.X
Ycorner = e.Y
PictureBox2.Invalidate()
End If
End Sub
Private Sub PictureBox2_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox2.MouseUp
If CheckBox1.Checked = True And MouseStatus = 1 Then
Xcorner = e.X
Ycorner = e.Y
If e.Button = MouseButtons.Right = True Then
Mimi = 4
Else
Mimi = 1
End If
End If
End Sub
Private Sub PictureBox2_MousedoubleClick(sender As Object, e As MouseEventArgs) Handles PictureBox2.MouseDoubleClick
If e.Button = MouseButtons.Left = True Then
If CheckBox1.Checked = True Then
Xini = e.X
Yini = e.Y
Else
End If
End If
End Sub




Kind Regards,


Hany Metry

Continue reading...
 
Back
Top