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.
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.
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.
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?
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 !!!
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.