Re: Imprimir En Gambas3 - Alguien Tiene Un Fragmento De Código Que Funcione?
hola man, te comento yo estoy haciendo un proyecto (CLText) y nesesitava la opcion de imprimir, aca te dejo el codigo de como lo logre:
primero que nada yo en mi caso utilizo un TextEdit y El "Elemento" Printer, una vez destacado esto, lo primero que aremos sera crear un Sub el cual sera:
(Recuerda Remplazar TextEdit1 por el nombre de tu TextEdit)
luego en el boton de imprimir pegaremso el siguiente codigo:
(Recuerda Remplazar prtText por el nombre de tu elemento Print)
ahora crearemos un nuevo sub el cual sera:
Public Sub prtText_Begin()
Dim PRINT_MARGIN As Float = Paint.Width / prtText.PaperWidth * 10
Dim hExtents As PaintExtents
hExtents = Paint.RichTextExtents(GetText(), Paint.Width - PRINT_MARGIN * 2)
prtText.Count = Ceil(hExtents.Height / (Paint.Height - PRINT_MARGIN * 2))
End
y otro sub mas el cual sera:
Public Sub prtText_Draw()
Dim PRINT_MARGIN As Float = Paint.Width / prtText.PaperWidth * 10
Debug "Printing page";; prtText.Page
Paint.Rectangle(PRINT_MARGIN / 2, PRINT_MARGIN / 2, Paint.Width - PRINT_MARGIN, Paint.Height - PRINT_MARGIN)
Paint.LineWidth = Paint.Width / prtText.PaperWidth * 0.5
Paint.Stroke
Paint.Rectangle(PRINT_MARGIN, PRINT_MARGIN, Paint.Width - PRINT_MARGIN * 2, Paint.Height - PRINT_MARGIN * 2)
Paint.Clip
Paint.DrawRichText(GetText(), PRINT_MARGIN, PRINT_MARGIN - (prtText.Page - 1) * (Paint.Height - PRINT_MARGIN * 2), Paint.Width - PRINT_MARGIN * 2, Paint.Height * prtText.Count, Align.TopNormal)
Paint.ResetClip
End
y listo solo te queda editar un poco los Paint para agregarle fuente y color y eso. espero que te sirva