Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy picturebox to drive (not screenprint)

Status
Not open for further replies.

Brewsom4me

Programmer
Jul 27, 2011
1
0
0
US
Hi all and thanks for taking a look at this!

I have a project I'm doing that I thought was done, but I guess I never should think that way.

This was a project that I took pieces from something existing and changed to suit the users request. Basically, it takes a variety of business benchmarks and shows them graphically (I didn't see a way to attach a jpg from my local drive, but I can email a sample if needed). Initially, this was a program that a user would run when they wanted to manually. I got a request to make this where it runs every morning and users can sign up for up to 24 of these "alerts". They would be shown on a jpg (which I converted from a bmp in my program) which would be attached to an email that the user would get. As I mentioned, it looked to work spiffy and I thought I was done, but instead of running it on my local PC for testing, I put it out for live. As it turns out, there is no graphic to the jpg now. I am thinking that it must have needed an active screen to use for a screen print in the picturebox. It works great when I test locally, but no graphic output when run from a server. I have also tried to run it from my PC when my PC is locked (scheduled tasks), and it also gives me a blank picture. It seems like it wants a monitor to be on when it runs and unfortunately I can't do this that way because it will run from a server.

In a nutshell...it works great when I run it myself on my PC, but if there is no monitor showing the program running, I get no picture saved. I have been searching all over trying to find an alternative to getting the graphic to work, but so far no luck. I have the code shown below where I save the picturebox. Does anyone have any other ideas as to how I could get what I need saved to use in an email? I haven't done much with pictureboxes, so sorry if I don't sound to knowledgeable. If you need ANY other info, please ask!! Thanks for your time and any help you can offer!!!

Kurt

Code:
Public Sub SaveFormImageToFile(ByRef ContainerForm As Form, _
                               ByRef PictureBoxControl As PictureBox, _
                               ByVal ImageFileName As String)
  Dim FormInsideWidth As Long
  Dim FormInsideHeight As Long
  Dim PictureBoxLeft As Long
  Dim PictureBoxTop As Long
  Dim PictureBoxWidth As Long
  Dim PictureBoxHeight As Long
  Dim FormAutoRedrawValue As Boolean
  
  With PictureBoxControl
    'Set PictureBox properties
    .Visible = False ' was originally false
    .AutoRedraw = True
    .Appearance = 0 ' Flat
    .AutoSize = False
    .BorderStyle = 0 'No border
    
   'Store PictureBox Original Size and location Values
    PictureBoxHeight = .Height: PictureBoxWidth = .Width
    PictureBoxLeft = .Left: PictureBoxTop = .Top
    
    'Make PictureBox to size to inside of form.
    .Align = vbAlignTop: .Align = vbAlignLeft
    DoEvents
    
    FormInsideHeight = .Height: FormInsideWidth = .Width
    
    'Restore PictureBox Original Size and location Values
    .Align = vbAlignNone
    .Height = FormInsideHeight: .Width = FormInsideWidth
    .Left = PictureBoxLeft: .Top = PictureBoxTop
    
    FormAutoRedrawValue = ContainerForm.AutoRedraw
    ContainerForm.AutoRedraw = True
    
    DoEvents
    
    'Copy Form Image to Picture Box
   
    BitBlt .hdc, 0, 0, _
    FormInsideWidth / Screen.TwipsPerPixelX, _
    FormInsideHeight / Screen.TwipsPerPixelY, _
    ContainerForm.hdc, 0, 0, _
    vbSrcCopy    
       
    DoEvents
    SavePicture .Image, ImageFileName
    DoEvents
    
    ContainerForm.AutoRedraw = FormAutoRedrawValue
    DoEvents
  End With
End Sub
 
I am not at home so I can't test it fully but as far as I can see from some old code there is a SavePicture function for saving images from picture boxes.

SavePicture Picture1.Picture, "C:\filename.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top