Author Topic: Print Current Screen/Form  (Read 1525 times)

zach_a_ary

  • Newbie
  • *
  • Posts: 19
    • View Profile
Print Current Screen/Form
« on: August 02, 2023, 02:42:29 AM »
Is there anyway to print current form of AdvancedHMI I am on? One of my forms has a bunch of production data on it. I would like to add a print button beside it. I see a few options under

dmroeder

  • Administrator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Print Current Screen/Form
« Reply #1 on: August 02, 2023, 11:20:40 AM »
Is there anyway to print current form of AdvancedHMI I am on? One of my forms has a bunch of production data on it. I would like to add a print button beside it. I see a few options under

One method that comes to mind is to screenshot the form and save an image.  Haven't tried this myself:
https://stackoverflow.com/questions/37825662/how-to-save-the-whole-windows-form-as-image-vb-net

Another method might be to take all of the values from the objects on your form and save them to a CSV file:
https://stackoverflow.com/questions/32985154/creating-excel-and-csv-files-in-vb-net

zach_a_ary

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Print Current Screen/Form
« Reply #2 on: August 02, 2023, 10:44:54 PM »
Thank you for your help. With that info i was able to find what i needed. Im not real savvy with c# or vb but this is what i ended up with. It works fine for what i need

zach_a_ary

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Print Current Screen/Form
« Reply #3 on: August 02, 2023, 10:48:33 PM »
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim frm = Form.ActiveForm

    Using bmp = New Bitmap(frm.Width, frm.Height)
        frm.DrawToBitmap(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height))

        bmp.Save("c:\temp\screenshot.png")
   
 End Using
End Sub

dmroeder

  • Administrator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Print Current Screen/Form
« Reply #4 on: August 03, 2023, 09:46:57 AM »
Nice.  I don't do a lot of VB.NET these days so I have to google most things :)