OVH Cloud OVH Cloud

API Screen/Printer

1 réponse
Avatar
niedernsill
Bonjour,
Je cr=E9e un control qui affiche une grille (plein de=20
rectangle) et souhaite que cette m=EAme proc=E9dure soit=20
utilis=E9 pour l'imprimer (hdc...). (=3Dsimplicit=E9 de=20
maintenance)
J'utilise l'API pour dessinner.
Il me semble que l'API veut du PIXEL ! mais en pixel =E0=20
l'=E9cran je ne suis pas pr=E9cis ! et le TWIPS semble de=20
rigueur.
Si =E0 chaque appel de la procedure de dessin je transforme=20
les coordonn=E9es en Pixel, apr=E8s quelque rectangle, un=20
gros d=E9calage se voit =E0 l'=E9cran...
Je tourne en rond...
Quelqu'un peut me dire la meilleure chose =E0 faire ?
Merci !

1 réponse

Avatar
Zoury
> Si à chaque appel de la procedure de dessin je transforme
les coordonnées en Pixel



Comment fais-tu les conversions twips vs pixel / pixels vs twips ?

Voici quelques méthodes possibles :
-Utiliser la fonction API, aucune conversion nécessaire..
-Définir vbPixels comme étant l'unité de mesure du formulaire/picturebox
dans lequel tu dessines.
-Utiliser les propriétés Screen.TwipsPerPixelX et Screen.TwipsPerPixelY afin
de convertir d'une unité à l'autre.
-Utiliser les méthodes ScaleX() et ScaleY() du formulaire/PictureBox..

Exemple :
'***
' Form1
Option Explicit

Private Declare Function Rectangle _
Lib "gdi32" _
( _
ByVal hdc As Long, _
ByVal x1 As Long, _
ByVal y1 As Long, _
ByVal x2 As Long, _
ByVal y2 As Long _
) As Long

Private Sub Command1_Click()
Call DrawRectangleAPI(10, 10, 101, 101)
End Sub

Private Sub Command2_Click()
Call DrawRectangle( _
10 * Screen.TwipsPerPixelX, _
10 * Screen.TwipsPerPixelY, _
100 * Screen.TwipsPerPixelX, _
100 * Screen.TwipsPerPixelY)
End Sub

Private Sub Command3_Click()
Me.ScaleMode = vbPixels
Call DrawRectangle(10, 10, 100, 100)
Me.ScaleMode = vbTwips ' remet en twips
End Sub

Private Sub Command4_Click()
Call DrawRectangle( _
Me.ScaleX(10, vbPixels, vbTwips), _
Me.ScaleY(10, vbPixels, vbTwips), _
Me.ScaleX(100, vbPixels, vbTwips), _
Me.ScaleY(100, vbPixels, vbTwips))
End Sub

Private Sub Form_Load()
Call Me.Move(Me.Left, Me.Top, 3645, 2580)
Call Command1.Move(2160, 120, 1215, 375)
Call Command2.Move(2160, 600, 1215, 375)
Call Command3.Move(2160, 1080, 1215, 375)
Call Command4.Move(2160, 1560, 1215, 375)
Me.AutoRedraw = True
Command1.Caption = "API"
Command2.Caption = "TwipsPerPixelsX"
Command3.Caption = "ScaleMode"
Command4.Caption = "ScaleX()"
Me.Caption = "Convertion Twips/Pixels"
End Sub

Private Sub DrawRectangleAPI(ByRef x1 As Long, ByRef y1 As Long, ByRef x2 As
Long, ByRef y2 As Long)
Me.Cls
Call Rectangle(Me.hdc, x1, y1, x2, y2)
End Sub

Private Sub DrawRectangle(ByRef x1 As Long, ByRef y1 As Long, ByRef x2 As
Long, ByRef y2 As Long)
Me.Cls
Me.Line (x1, y1)-(x2, y2), , B
End Sub
'***


Note que le problème se trouve peut-être ailleurs, on a pas vu ton code...
;O)

--
Cordialement
Yanick Lefebvre - MVP pour Visual Basic
Le français se refait une beauté, parlons en :
http://www.orthographe-recommandee.info/