Thanks Rolf-Werner,

I tried
Private $hImage As New Image
and had the same result ! Printing white page!

What I want is to print the labels of a form or ScrollArea!!

I also tried to change the *Printing Example of Gambas 3* to make it work
for my issue. Here's what I did (3 steps):

1......I've changed Form_load as following to Grab the contents of
srcImage.ScrollArea:

Public Sub Form_Open()

  Me.Center

  txtText.Text = File.Load("molly-malone.txt")
  txtFontText.Text = Font["17"].ToString()
  Try $hImage = scrImage.Grab
 ' $hImage = New Image(scrImage.Width, scrImage.Height)

  'scrImage.ResizeContents($hImage.W, $hImage.H)
  'scrImage.Refresh

End

2.......Inside the scrImage.ScrollArea I placed some labels, ie
Label1.label, Label2.label etc.

3.......I commented out the load picture (because the main purpose is to
print the context,ie the Labels that I placed inside, of
srcImage.ScrollArea) as following:

Public Sub btnOpenImage_Click()

 ' Dialog.Title = "Select an image file"
 ' Dialog.Filter = ["*.png;*.jpg;*.jpeg;*.gif;*.xpm", "Image files"]
 ' If Dialog.OpenFile() Then Return

  Try $hImage = Image.Load(Dialog.Path)
  scrImage.ResizeContents($hImage.W, $hImage.H)
  scrImage.Refresh

End

But still got blanc page printed.
(The printing example works fine in its initial form)
Attached is the Changed Code


On Thu, Mar 20, 2014 at 7:27 PM, Rolf-Werner Eilert <
[email protected]> wrote:

> Vasilis,
>
> I've got to leave the office now, but at a quick glance:
>
> > Private $hImage As Image
>
> Shouldn't this be As New Image?
>
> >
> >
> > Public Sub Form_Open()
> >      Me.Center
> >      Try $hImage = Me.Grab.Image
> > End
> >
> > Public Sub Printer1_Draw()
> >
> >    Dim hImage As Image
>
> And maybe the same here?
>
> Regards
> Rolf
>
> >
> >    If Not $hImage Then Return
> >    hImage = $hImage
> >    Paint.DrawImage(hImage)
> >
> > End
> >
> > Public Sub PrintButton_Click()
> >
> >    If Printer1.Configure() Then Return
> >
> >    Me.Enabled = False
> >    Inc Application.Busy
> >    Printer1.Print
> >    Dec Application.Busy
> >    Me.Enabled = True
> >
> > End
> > --------------------------------------------------------------------
> >
> > Thank you!
> > Vasilis
> >
> ------------------------------------------------------------------------------
> > Learn Graph Databases - Download FREE O'Reilly Book
> > "Graph Databases" is the definitive new guide to graph databases and
> their
> > applications. Written by three acclaimed leaders in the field,
> > this first edition is now available. Download your free book today!
> > http://p.sf.net/sfu/13534_NeoTech
> > _______________________________________________
> > Gambas-user mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
>
>
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and their
> applications. Written by three acclaimed leaders in the field,
> this first edition is now available. Download your free book today!
> http://p.sf.net/sfu/13534_NeoTech
> _______________________________________________
> Gambas-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
' Gambas class file

Private $hImage As Image

Public Sub Form_Open()

  Me.Center

  txtText.Text = File.Load("molly-malone.txt")
  txtFontText.Text = Font["17"].ToString()
  Try $hImage = scrImage.Grab
 ' $hImage = New Image(scrImage.Width, scrImage.Height)

  'scrImage.ResizeContents($hImage.W, $hImage.H)
  'scrImage.Refresh


End

Private Sub GetText() As String
  
  Dim sText As String
  
  sText = txtText.Text
  If Not btnRichText.Value Then sText = Replace(Html(sText), "\n", "<br>")  
  Return sText
  
End

Private Sub RefreshText()
  
  Dim hFont As Font = Font[txtFontText.Text]
  Dim sText As String = GetText()
  
  scrText.ResizeContents(scrText.ClientW, hFont.RichTextHeight(sText, 
scrText.ClientW - 16) + 16)
  scrText.Refresh
  
End

Public Sub scrText_Draw()

  Dim sText As String = GetText()
  
  Draw.FillRect(0, 0, Draw.W, Draw.H, Color.TextBackground)
  Try Draw.Font = Font[txtFontText.Text]
  Draw.Translate(- scrText.ScrollX, - scrText.ScrollY)
  Draw.RichText(sText, 8, 8, scrText.ClientW - 16, scrText.ClientH - 16, 
Align.TopNormal)

End

Public Sub btnRichText_Click()

  RefreshText

End

Public Sub txtText_Change()

  RefreshText

End

Public Sub txtFontText_Click()

  Dialog.Title = "Select a font"
  Dialog.Font = Font[txtFontText.Text]
  If Dialog.SelectFont() Then Return
  txtFontText.Text = Dialog.Font.ToString()
  RefreshText

End

Public Sub scrText_Arrange()

  RefreshText

End

Public Sub btnOpenText_Click()

  Dialog.Title = "Select a text file"
  If Dialog.OpenFile() Then Return
  Try txtText.Text = File.Load(Dialog.Path)

End

Public Sub btnPrintText_Click()

  If prtText.Configure() Then Return

  Me.Enabled = False
  Inc Application.Busy
  prtText.Print
  Dec Application.Busy
  Me.Enabled = True

End

Public Sub prtText_Begin()
  
  Dim PRINT_MARGIN As Float = Paint.Width / prtText.PaperWidth * 10
  Dim hExtents As PaintExtents
  
  Paint.Font = Font[txtFontText.Text]
  hExtents = Paint.RichTextExtents(GetText(), Paint.Width - PRINT_MARGIN * 2)
  prtText.Count = Ceil(hExtents.Height / (Paint.Height - PRINT_MARGIN * 2))
  
End

Public Sub prtText_Draw()

  Dim PRINT_MARGIN As Float = Paint.Width / prtText.PaperWidth * 10
    
  Debug "Printing page";; prtText.Page
  
  Paint.Font = Font[txtFontText.Text]
  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

Public Sub btnOpenImage_Click()

 ' Dialog.Title = "Select an image file"
 ' Dialog.Filter = ["*.png;*.jpg;*.jpeg;*.gif;*.xpm", "Image files"]
 ' If Dialog.OpenFile() Then Return
  
  Try $hImage = Image.Load(Dialog.Path)
  scrImage.ResizeContents($hImage.W, $hImage.H)
  scrImage.Refresh

End

Public Sub scrImage_Draw()
  
  If $hImage Then Draw.Image($hImage, - scrImage.ScrollX, - scrImage.ScrollY)
  
End

Public Sub btnPrintImage_Click()

  If prtImage.Configure() Then Return

  Me.Enabled = False
  Inc Application.Busy
  prtImage.Print
  Dec Application.Busy
  Me.Enabled = True

End

Public Sub prtImage_Draw()
  
  Dim PRINT_MARGIN As Float = Paint.Width / prtText.PaperWidth * 10
  Dim hImage As Image
  Dim W, H As Float
  
  If Not $hImage Then Return
  
  hImage = $hImage
  If hImage.Width > hImage.Height Then hImage = hImage.Rotate(Pi(0.5))
  
  W = Paint.Width - PRINT_MARGIN * 2
  H = W * hImage.Height / hImage.Width
  Paint.DrawImage(hImage, PRINT_MARGIN, (Paint.Height - H) / 2, W, H)
  
End
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Gambas-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to