1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
' ---------Ajouter
'1/ --------- un Panel scrollable au form ------------------
'2/ -------- le PictureBox Source "au" Panel-----------
'3/ -------- le 2 PictureBox (contenant "zone clonee") au form-----------
'4/ -------- un ToolTip sur le form au loeur du Label
Imports System.Drawing.Imaging
Public Class Form3
Public tmpBMP As Bitmap = Nothing
Public cloBMP As Bitmap = Nothing
'declare le rectangle viseur au niveu form:
Private viseurRec As Rectangle = New Rectangle(0, 0, 210, 210)
Public Sub New()
' Cet appel est requis par le concepteur.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
'---------Panel scrollable
Me.Panel1.AutoScroll = True
Me.Panel1.AutoScrollMinSize = New Size(1024, 768)
'---------Definit mode de "clipping" des 2 PictureBoxs
PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
PictureBox2.SizeMode = PictureBoxSizeMode.Normal
'---------DoubleBuffering pour eviter le "scintillement" lors du dessin du viseur
'---------sur le PictureBox Source
Me.DoubleBuffered = True
End Sub
Private Sub Form3_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'---------recupere image
PictureBox1.Image = My.Resources.Nenuphars
tmpBMP = New Bitmap(PictureBox1.Image)
cloBMP = New Bitmap(210, 210)
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
Label1.Text = CStr(e.Location.X) + " - " + CStr(e.Location.Y)
Dim x As Int32 = e.X - 105
Dim y As Int32 = e.Y - 105
'----------------init viseurRec
viseurRec = New Rectangle(x, y, 210, 210)
'----------------1er test sur viseurRec
If viseurRec.X <= 0 Then viseurRec.X = 0
If viseurRec.Y <= 0 Then viseurRec.Y = 0
'------2e test sur les "diaboliques" viseurRec et bitmap source
'NB : tmpBMP.Width - 1 & tmpBMP.Height - 1
'NB : props utiles du Rectangle : Right et Bottom(eclaireurs)
'Right est mis à jour "auto" quand on modifie Rectangle.X
' Idem pour Bottom & Rect.Y
If viseurRec.Right >= (tmpBMP.Width - 1) Then
' soustraire le depassement en agissant sur rectangle.X
viseurRec.X = viseurRec.X - (viseurRec.Right - (tmpBMP.Width - 1))
End If
If viseurRec.Bottom >= (tmpBMP.Height - 1) Then
viseurRec.Y = viseurRec.Y - (viseurRec.Bottom - (tmpBMP.Height - 1))
End If
ToolTip1.SetToolTip(PictureBox1, viseurRec.Right.ToString + " - " + viseurRec.Bottom.ToString)
'Out " the boggus"
cloBMP = tmpBMP.Clone(viseurRec, tmpBMP.PixelFormat)
Dim gra As Graphics = Graphics.FromImage(cloBMP)
gra.DrawLine(Pens.Red, 0, CInt(cloBMP.Height / 2), cloBMP.Width, CInt(cloBMP.Height / 2))
gra.DrawLine(Pens.Red, CInt(cloBMP.Width / 2), 0, CInt(cloBMP.Width / 2), cloBMP.Height)
gra.Dispose()
PictureBox2.Image = cloBMP
'refresh PictureBox1 (car je dessine egalement mon viseur sur PictureBox Source)
PictureBox1.Refresh()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Dim gra As Graphics = e.Graphics
Dim bigPen As Pen = New Pen(Brushes.Yellow, 4.0)
gra.DrawRectangle(bigPen, viseurRec)
bigPen.Dispose()
End Sub
End Class |
Partager