Domanda: come faccio a collegare l'oggetto Printer ad una specifica DrawingArea? Ce ne potrebbero essere più di una, per esempio.
Io avrei scritto questo codice un po' rozzo... (ipotizziamo di avere due "DrawingArea"):
Public Sub DrawingArea1_Draw()
With Paint
.Brush = Paint.Color(Color.Red)
.MoveTo(100, 100)
.RelLineTo(0, 100)
.Stroke
.DrawText("DrawingArea1", 10, 10, 20, 20)
.End
End With
End
Public Sub DrawingArea2_Draw()
With Paint
.Brush = Paint.Color(Color.Red)
.MoveTo(200, 200)
.RelLineTo(0, 200)
.Stroke
.DrawText("DrawingArea2", 200, 200, 20, 20)
.End
End With
End
Public Sub Button1_Click()
With Printer1
.Configure
.Orientation = 0
.Paper = 2
.Resolution = Desktop.Resolution
.GrayScale = False
' Creiamo e stampiamo su un file .pdf:
.OutputFile = "/tmp/file.pdf"
.Print
End With
End
Public Sub Printer1_Draw()
Dim n As Byte
n = Val(InputBox("Quale DrawingArea vuoi stampare ?"))
' Richiamiamo ai fini della stampa le impostazioni presenti nella sub-procedura":
Stampa(n)
End
Private Procedure Stampa(d As Byte)
Dim mx, my, rY, dx, dy As Integer
Dim dS As String
If d = 1 Then
mx = 100
my = 100
rY = 100
dX = 10
dY = 10
dS = "1"
Else
mx = 200
my = 200
rY = 200
dX = 200
dY = 200
dS = "2"
Endif
With Paint
.Begin(Printer1)
.Brush = Paint.Color(Color.Red)
.MoveTo(mx, my)
.RelLineTo(0, rY)
.Stroke
.DrawText("DrawingArea" & dS, dX, dY, 20, 20)
.End
End With
End
Pensavo, non potrebbe essere sufficiente dare il Setfocus alla DrawingArea per poterla stampare su file?
Scusa il ritardo della risposta ma mi ero concentrato sul problema sopra esposto. :)
Penso proprio di si e questo è un semplicissimo parto della mia mente:
Cambiando leggermente l'esempio di vuott
' Gambas class file
Private byDove As Byte = 1 ' Default stampa draw 1
...
...
...
Public Sub DrawingArea1_GotFocus()
byDove = 1
DrawingArea1.Background = Color.Green
End
Public Sub DrawingArea1_LostFocus()
DrawingArea1.Background = Color.Default
End
Public Sub DrawingArea2_GotFocus()
byDove = 2
DrawingArea2.Background = Color.Green
End
Public Sub DrawingArea2_LostFocus()
DrawingArea2.Background = Color.Default
End
Public Sub Printer1_Draw()
' Dim n As Byte
' n = Val(InputBox("Quale DrawingArea vuoi stampare ?"))
' Print n
' Richiamiamo ai fini della stampa le impostazioni presenti nella sub-procedura":
Stampa(byDove)
End
:ciao:
ps. magari cambiando il green ;D
ps2. devi portare a true il focus delle drawing