Bonjour à tous,
Savez-vous si l'on peut reproduire dans un controle (Panel ou autre) les propriétés ScaleTop, ScaleLeft, ScaleWidth et ScaleHeight qui existaient en VB6 ?
D'avance merci
Bonjour à tous,
Savez-vous si l'on peut reproduire dans un controle (Panel ou autre) les propriétés ScaleTop, ScaleLeft, ScaleWidth et ScaleHeight qui existaient en VB6 ?
D'avance merci
Bonjour,
Oui la classe Control possède une propriété ClientRectangle => https://msdn.microsoft.com/fr-fr/lib...vs.110%29.aspx
De là tu retrouves la classe Rectangle => https://msdn.microsoft.com/fr-fr/lib...vs.110%29.aspx (Top/Left/Height/Width)
bonjour
Il n'existe rien de semblable en vb.net pour la mise à l'echelle et les unites user....
1/tout est specifie en pixel
- dimensions de ton control(limites) avec Control.ClientRectangle ou variante (Control.Left , Control.Top et Control.ClientSize)
- deplacement du pointeur souris (e.Location)
2/si tu dessine le class Graphics est ton ami,il permet de specifier
- les unites de dessin : gr.PageUnit = GraphicsUnit.Millimeter
- l'echelle courante : g.PageScale = 0.5
- pour les deplacements de pointeur souris,il faut convertir (cf exemple en mm) avec gr.TransformPoints(CoordinateSpace.Page, CoordinateSpace.Device, pts),ou pts est un tableau de pointf
pts se ,reduit à un point dans le cas de l'argument e.Location....
voici un exemple code de dessin dans l'event Paint du Panel :
- de plusieurs rectangles en dur specifie dans l'event Paint
- un ellipse interactif avec souris
bon code...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
95
96
97
98
99
100
101
102
103
104 Imports System.Drawing.Drawing2D Public Class Form2 Private EchelleCourante1 As Single = 0.5 Private EchelleCourante2 As Single = 1.5 Private UniteMillimetre As GraphicsUnit = GraphicsUnit.Millimeter Public Sub New() ' Cet appel est requis par le concepteur. InitializeComponent() ' Ajoutez une initialisation quelconque après l'appel InitializeComponent(). Me.Panel1.Location = New Point(50, 50) Me.Panel1.Size = New Size(400, 400) End Sub Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint Dim g As Graphics = e.Graphics g.Clear(Color.White) ' Set page units and scale g.PageUnit = UniteMillimetre g.PageScale = EchelleCourante1 ' 1 unit => 0.5 millimetre Dim blackPen As Pen = New Pen(Color.Black, 0) ' Specify units in Millimtres Dim rect1 As RectangleF = New RectangleF(10, 10, 50.0, 30.0) ' Draw in Millimtre g.DrawRectangle(blackPen, rect1.X, _ rect1.Y, rect1.Width, rect1.Height) g.PageScale = EchelleCourante2 ' 1 unit => 1.5 Millimetre ' Draw in Millimetre g.DrawRectangle(blackPen, rect1.X, _ rect1.Y, rect1.Width, rect1.Height) g.PageScale = EchelleCourante1 Dim points() As PointF = New PointF() { New PointF(Me.ClientSize.Width, Me.ClientSize.Height)} ' Convert client size to Millimetres from pixels g.TransformPoints(CoordinateSpace.Page, CoordinateSpace.Device, points) Dim clientRect As RectangleF = New RectangleF(0, 0, points(0).X, points(0).Y) g.DrawRectangle(Pens.Red, Rectangle.Ceiling(clientRect)) If IsDrawing Then g.DrawEllipse(Pens.Blue, Rectangle.Ceiling(ellip)) End If End Sub Private Sub Panel1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Panel1.Resize Me.Panel1.Refresh() End Sub Private IsDrawing As Boolean = False Private ellip As RectangleF Private StartPoint As PointF Private EndPoint As PointF Private Sub Panel1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown IsDrawing = True StartPoint = PixelToMillimetre(e.Location) EndPoint = StartPoint ellip = New RectangleF(StartPoint.X, StartPoint.Y, Math.Abs(StartPoint.X - EndPoint.X), Math.Abs(StartPoint.Y - EndPoint.Y)) Me.Panel1.Refresh() End Sub Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove If Not IsDrawing Then Return EndPoint = PixelToMillimetre(e.Location) ellip = New RectangleF(StartPoint.X, StartPoint.Y, Math.Abs(StartPoint.X - EndPoint.X), Math.Abs(StartPoint.Y - EndPoint.Y)) Me.Panel1.Refresh() End Sub Private Sub Panel1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp If Not IsDrawing Then Return EndPoint = PixelToMillimetre(e.Location) ellip = New RectangleF(StartPoint.X, StartPoint.Y, Math.Abs(StartPoint.X - EndPoint.X), Math.Abs(StartPoint.Y - EndPoint.Y)) Me.Panel1.Refresh() IsDrawing = False End Sub Private Function PixelToMillimetre(ByVal pt As Point) As PointF Dim pts() As PointF = {pt} Dim g As Graphics = Me.Panel1.CreateGraphics g.PageUnit = UniteMillimetre g.PageScale = EchelleCourante1 g.TransformPoints(CoordinateSpace.Page, CoordinateSpace.Device, pts) g.Dispose() Return pts(0) End Function End Class
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager