Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Performance / October 2004

Tip: Looking for answers? Try searching our database.

background images slow

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andreas van de Sand - 15 Oct 2004 07:23 GMT
Hi all,

I'm working on an application and want to use background images for forms
and controls. Using the images itself is not a problem, but when I run my
application it becomes really slow and my CPU usage goes up to 100% for a
time...
Is there a better way of setting background images?
It's just 3 images I think, all pretty small, and I already created the
objects for the images and set them to the controls at runtime so that it
uses only 3 objects and not new instances for every control.
But still...
It can't be that hard just to show a couple of images...?

Many thanks for your help...
Andreas
Lloyd Dupont - 18 Oct 2004 04:16 GMT
> It can't be that hard just to show a couple of images...?
I think it is....
GDI is pretty prehistoric in some ways....
It's why background image are so uncommon, prefer tghe background color
property...
or wait for longhorn ;-)

> Many thanks for your help...
> Andreas
Andreas van de Sand - 18 Oct 2004 06:04 GMT
> It's why background image are so uncommon, prefer tghe background color
> property...

Well it looks like this is my only option, because I don't want my program
to look so slow, just because of a simple background image... wanted to have
a simple multi colour bg as in office 2003... do you happen to know if
there's a way to have multiple colours with a transition as background?

Thanks,
Andreas
Cablito - 18 Oct 2004 18:41 GMT
use the gdi drawing gradient. If thats not good enough in performance, drop
.net and write MFC c++ code

> > It's why background image are so uncommon, prefer tghe background color
> > property...
[quoted text clipped - 6 lines]
> Thanks,
> Andreas
Jay B. Harlow [MVP - Outlook] - 19 Oct 2004 00:19 GMT
Andreas,
I've used the following In my Forms in both VS.NET 2002 & VS.NET 2003
without any real performance problems...

   Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
       MyBase.OnResize(e)

       If Not Me.BackgroundImage Is Nothing Then
           Me.BackgroundImage.Dispose()
           Me.BackgroundImage = Nothing
       End If
       Dim image As New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)
       Dim gr As Graphics = Graphics.FromImage(image)
       Dim rect As New Rectangle(New Point(0, 0), Me.ClientSize)

       Dim brush As New LinearGradientBrush(rect,  _
           Color.RosyBrown, ControlPaint.LightLight(Color.RosyBrown),  _
           LinearGradientMode.Vertical)
       brush.SetBlendTriangularShape(0.33)
       gr.FillRectangle(brush, rect)
       gr.Dispose()

       Me.BackgroundImage = image
   End Sub

The image is always the same size as the form, so there is no tiling going
on.

Just set the BackColor of controls that support it to Transparent, they will
then pick up the colors from the above Image.

Hope this helps
Jay

>> It's why background image are so uncommon, prefer tghe background color
>> property...
[quoted text clipped - 6 lines]
> Thanks,
> Andreas
Andreas van de Sand - 19 Oct 2004 08:01 GMT
> I've used the following In my Forms in both VS.NET 2002 & VS.NET 2003
> without any real performance problems...

Thanks Jay, tried this, and at least it's better. Still slow, but not as bad
as with an image.
Thanks very much for your help everyone!
Andreas
Jay B. Harlow [MVP - Outlook] - 19 Oct 2004 15:12 GMT
Andreas,
Only the form itself should have the background image.

All your controls should have BackColor = Transparent.

Can you define "slow", when is it "slow" specifically.

Can you post a 20-25 line program (or email me) that accurately shows that
it is slow?

As using the above routine, the only time it is even close to "slow" is when
you resize the form itself. Even then on a 866 PIII, I don't really notice
it as being slower then normal (it flickers slightly, but that's about it).

Hope this helps
Jay

>> I've used the following In my Forms in both VS.NET 2002 & VS.NET 2003
>> without any real performance problems...
[quoted text clipped - 3 lines]
> Thanks very much for your help everyone!
> Andreas
Andreas van de Sand - 20 Oct 2004 04:41 GMT
Jay,

> Only the form itself should have the background image.
>
> All your controls should have BackColor = Transparent.
yes, that's what it is.

> Can you define "slow", when is it "slow" specifically.
it's slow when I'm showing a panel which contains 3 listBox controls with
splitters in between and another (transparent) panel.
I'm setting the DockingState of the panel to Fill at runtime and change the
visibility of the panel to visible.
And that's what takes time... not the backgroundimage itself, just the
(automatic) resizing of the controls (according to their Fill state). You
see them appearing and resizing, one by one.
But it's really better now than before with an image from a file.
So again, many thanks!
Andreas

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.