IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Forms Discussion :

ScaleTop, ScaleLeft, ScaleWidth et ScaleHeight


Sujet :

Windows Forms

  1. #1
    Membre régulier
    Profil pro
    Ingénieur de développement
    Inscrit en
    Avril 2005
    Messages
    169
    Détails du profil
    Informations personnelles :
    Localisation : France, Vaucluse (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur de développement

    Informations forums :
    Inscription : Avril 2005
    Messages : 169
    Points : 96
    Points
    96
    Par défaut ScaleTop, ScaleLeft, ScaleWidth et ScaleHeight
    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

  2. #2
    Membre habitué
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2013
    Messages
    93
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2013
    Messages : 93
    Points : 127
    Points
    127
    Par défaut
    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)

  3. #3
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    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

    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
    bon code...

Discussions similaires

  1. [A devenir FOU!] Scaleheight & Scalewidth
    Par El Effe dans le forum VBA PowerPoint
    Réponses: 1
    Dernier message: 17/07/2012, 00h58
  2. problème avec scaleheight et scalewith
    Par djelloharmel dans le forum VB.NET
    Réponses: 0
    Dernier message: 27/06/2012, 18h46
  3. ScaleWidth et ScaleLeft de VB6
    Par Nico28 dans le forum Windows Forms
    Réponses: 4
    Dernier message: 18/01/2008, 15h46

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo