Results 1 to 7 of 7

Thread: Copying a hidden form

  1. #1
    ALX
    ALX is offline VB.NET Forum Genius
    .NET Framework
    .NET 4.0
    Join Date
    Nov 2005
    Location
    Columbia, SC
    Posts
    187
    Reputation
    144

    Copying a hidden form

    I have a form class "A" that uses a different form class "B" that is hidden. From time to time, form A will take a snapshot of form B and display it, in a reduced bitmap format, within form A. This all works great except that I need to show form B initially before I can copy it's contents to a bitmap. So I show it and then hide it in consecutive statements. This creates a flicker that I'd like to avoid. I'm wondering if there is a way to prep form B for copying to a bitmap without showing it first.

  2. #2
    JuggaloBrotha's Avatar
    JuggaloBrotha is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    Lansing, MI; USA
    Posts
    4,468
    Reputation
    1015
    Quote Originally Posted by ALX View Post
    I have a form class "A" that uses a different form class "B" that is hidden. From time to time, form A will take a snapshot of form B and display it, in a reduced bitmap format, within form A. This all works great except that I need to show form B initially before I can copy it's contents to a bitmap. So I show it and then hide it in consecutive statements. This creates a flicker that I'd like to avoid. I'm wondering if there is a way to prep form B for copying to a bitmap without showing it first.
    What is it that FormB is showing that you need to a take a screenshot of?
    Currently using: VS 2010 Ultimate on Win7 Ultimate x64.

  3. #3
    ALX
    ALX is offline VB.NET Forum Genius
    .NET Framework
    .NET 4.0
    Join Date
    Nov 2005
    Location
    Columbia, SC
    Posts
    187
    Reputation
    144
    Form B is a bar graph that takes an entire form class to properly construct. It's initial purpose displays this graph as a full screen graph in a stand alone module. Form A displays a reduced version of this graph as well as a few other related graphs. 'Kind of a summary, so to speak... All of these graphs are displayed as reduced bitmaps on Form A, and each one needs to be shown and hidden prior to copy to bitmap. I tried hiding the flicker by placing everything underneath a black shade form but the flicker still shows up.

  4. #4
    JuggaloBrotha's Avatar
    JuggaloBrotha is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    Lansing, MI; USA
    Posts
    4,468
    Reputation
    1015
    Quote Originally Posted by ALX View Post
    Form B is a bar graph that takes an entire form class to properly construct. It's initial purpose displays this graph as a full screen graph in a stand alone module. Form A displays a reduced version of this graph as well as a few other related graphs. 'Kind of a summary, so to speak... All of these graphs are displayed as reduced bitmaps on Form A, and each one needs to be shown and hidden prior to copy to bitmap. I tried hiding the flicker by placing everything underneath a black shade form but the flicker still shows up.
    Since you're using the entire form to draw the graph, should I presume you're using the form's paint event to draw everything on the form?
    If so, is there a reason you couldn't draw it to a Bitmap (Image) object instead?
    Currently using: VS 2010 Ultimate on Win7 Ultimate x64.

  5. #5
    ALX
    ALX is offline VB.NET Forum Genius
    .NET Framework
    .NET 4.0
    Join Date
    Nov 2005
    Location
    Columbia, SC
    Posts
    187
    Reputation
    144
    I think I see where you're going with this. If I override Form B's Paint handler, the call to "Show" the form could be redirected to painting a bitmap rather than displaying on the monitor... Wow... Why didn't I think of that ?... I assume this will work ? I'm really only copying the meat of the graph. All Headers, title bars and controls are not included in the bitmap but I think I can work around that. 'Can't wait to try it. Thanks Brotha !!!

  6. #6
    JuggaloBrotha's Avatar
    JuggaloBrotha is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    Lansing, MI; USA
    Posts
    4,468
    Reputation
    1015
    Quote Originally Posted by ALX View Post
    I think I see where you're going with this. If I override Form B's Paint handler, the call to "Show" the form could be redirected to painting a bitmap rather than displaying on the monitor... Wow... Why didn't I think of that ?... I assume this will work ? I'm really only copying the meat of the graph. All Headers, title bars and controls are not included in the bitmap but I think I can work around that. 'Can't wait to try it. Thanks Brotha !!!
    That's the direction I was nudging you, yes.
    However I was getting at that you could add a Module (not a form) and create the functions you need for "painting stuff" and the function(s) simply return a Bitmap object.

    Then you simply call the function, pass it the args needed and spits out an image.
    You can take that image and display it on a form (PictureBox control) or save it to a file, if you have a PDF creating object like iSharp or whatever it's called you could write the graph to a pdf file for the user.

    Btw, to write to a Bitmap object you will need to create a Graphics object from the Bitmap then you can use it just like you would in the form's Paint event using e.Graphics.

    Here's an example from an app I wrote years ago, it needed an Icon size image to display in the NotifyIcon control:
    Option Explicit On
    Option Strict On
    Option Infer Off

    Imports System.Drawing.Drawing2D

    Friend Module GraphicsModule

    Friend Function ApplicationImage() As Bitmap
    Dim Output As New Bitmap(16I, 16I)

    Using g As Graphics = Graphics.FromImage(Output)
    g.SmoothingMode = SmoothingMode.AntiAlias
    g.Clear(Color.FromArgb(248I, 247I, 182I))
    Using TitleBr As New SolidBrush(Color.FromArgb(251I, 248I, 123I))
    g.FillRectangle(TitleBr, New Rectangle(0I, 0I, Output.Width, CInt(Output.Height / 4I)))
    End Using
    Using BPen As New Pen(Color.DarkGray, 1.0!)
    g.DrawLine(BPen, 1.0!, 5.0!, 9.0!, 5.0!)
    g.DrawLine(BPen, 1.0!, 9.0!, 6.0!, 9.0!)
    g.DrawLine(BPen, 1.0!, 13.0!, 11.0!, 13.0!)
    End Using
    g.Save()
    End Using

    Return Output
    End Function

    End Module
    As you can see, you call the function in the Module and it spits out an image.
    Currently using: VS 2010 Ultimate on Win7 Ultimate x64.

  7. #7
    ALX
    ALX is offline VB.NET Forum Genius
    .NET Framework
    .NET 4.0
    Join Date
    Nov 2005
    Location
    Columbia, SC
    Posts
    187
    Reputation
    144
    Good stuff !!! Thanks again.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •