Re: GIF image on a form



Many thanks Fred for your comprehensive help.

G

"Fred Hedges" <dontlike@xxxxxxxxxxxx> wrote in message
news:e4kqgh$hf$1$830fa7a5@xxxxxxxxxxxxxxxxxxx
(1) Create a new User Control

(2) Override it's CreateParms property with this:

Protected Overrides ReadOnly Property CreateParams() As CreateParams

Get

Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or WS_EX_TRANSPARENT

Return cp

End Get

End Property

(3) In Sub New(), add the following code:


Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
Me.UpdateStyles()
Me.BackColor = Color.Transparent


(4) Override the OnPaintBackground event, but don't put anything into it:

Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
'
End Sub


(5) Import the GIF into your resources (Project Properties, Resources,
Images, Add Image...).

This will basically give you a transparent surface. Now you can draw your
.GIF onto this transparent surface any way you want, eg:

(6) Override the OnPaint event and use it to draw your image:
Protected Overrides Sub OnPaint(byval e As PaintEventArgs)

' Render our image here, no stretch, modify to stretch to fill
' the control if required.
e.Graphics.DrawImage ( My.Resources.WhateverMyGIFImageIsCalled, 0,
0 )

End Sub



Hope this helps.





"G .Net" <nodamnspam@xxxxxxxxx> wrote in message
news:jZidnYXR75NfdPDZnZ2dnUVZ8qSdnZ2d@xxxxxxxxxxxx
Hi Fred

Ah, looks like exactly what I need!!!

However, bit of newbie so need help in exactly what to do. Could I
trouble you to give the steps I need?

G

"Fred Hedges" <dontlike@xxxxxxxxxxxx> wrote in message
news:e4ko8g$362$1$830fa17d@xxxxxxxxxxxxxxxxxxx
What you need to do is make a user control and then modify it's
transparent property on window construction. You then need to handle
"InvalidateEx" messages in order to force the parent to redraw your
background, rather than you. Funny you mention this because I had to do
this with a "working....." animation yesterday.

This sample is in C# but it's easy to convert. You won't be needing a
picture box. Just use DrawImage to render your GIF on the control
surface but overriding the paint event.

http://www.devnewsgroups.net/link.aspx?url=http://dotnet.mvps.org/dotnet/faqs/?id=transparentcontrol&lang=en%3E



"G .Net" <nodamnspam@xxxxxxxxx> wrote in message
news:JfqdnbvL_-z4fPDZRVnyiA@xxxxxxxxxxxx
Hi

I have a form on which I have a picture box. I have placed a GIF as the
image for this picture box. The GIF has a transparent background.

If I change the background color of the form, then the GIF appears on
the form correctly i.e. the background of the form shows through the
transparent part of the gif.

However, if I place a BackgroundImage on the form, the transparent part
of the form does not show the BackgroundImage of the form, rather is
shows the back color of the form. This obviously make the GIF not to be
"transparent".

Can anybody help?

Thanks

G









.



Relevant Pages

  • Re: GIF image on a form
    ... Protected Overrides ReadOnly Property CreateParams() As CreateParams ... Override the OnPaintBackground event, but don't put anything into it: ... Import the GIF into your resources (Project Properties, Resources, ... This will basically give you a transparent surface. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: create deactivated form
    ... > One simple way would be to immediately set focus back after the second ... > So I'm looking for a way to immediately create a window that doesn't have ... > protected override CreateParams CreateParams ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: TransperantLabel
    ... you override or not, so the "perf hit" will be minimal provided you don't ... to RGBand all non transparent bits to RGBand on ... I am able to draw transperant lables by overriding OnPaint and using ... I have a embedded resource background and I need to have labels on the ...
    (microsoft.public.pocketpc.developer)
  • Re: Why dont modal windows flash?
    ... If the CreateParams in Form1 was already overrided, ... Params.WndParent was changed to GetDesktopWindow, ... > Override CreateParams like the following: ... > For MessageBoxes use MessageBox API: ...
    (borland.public.delphi.nativeapi)
  • Re: Site feedback
    ... transparent unless you're fairly sure you've also set the ... always override either the background or the text colour but not ... so that a proper user style sheet will not cause problems with yout author style sheet. ...
    (comp.infosystems.www.authoring.stylesheets)