472,982 Members | 2,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,982 software developers and data experts.

Q: GIF image on a form

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
May 19 '06 #1
7 1748
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.as...rol&lang=en%3E

"G .Net" <no********@email.com> wrote in message
news:Jf********************@pipex.net...
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

May 19 '06 #2
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" <do******@spammuch.com> wrote in message
news:e4*******************@news.demon.co.uk...
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.as...rol&lang=en%3E

"G .Net" <no********@email.com> wrote in message
news:Jf********************@pipex.net...
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


May 19 '06 #3
(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.SupportsTransparentBackC olor, 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" <no********@email.com> wrote in message
news:jZ******************************@pipex.net...
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" <do******@spammuch.com> wrote in message
news:e4*******************@news.demon.co.uk...
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.as...rol&lang=en%3E

"G .Net" <no********@email.com> wrote in message
news:Jf********************@pipex.net...
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



May 19 '06 #4
gs
that looks more like VB than c#
I think you will have to fresh out the last stub for OnPaintBackground
with painting you GB image
Imports System
Imports System.Windows.Forms

Public Class TransparentControl
Inherits Control

Private Const WS_EX_TRANSPARENT As Int32 = &H20

Public Sub New()
Me.SetStyle(ControlStyles.SupportsTransparentBackC olor, True)
Me.UpdateStyles()
Me.BackColor = Color.Transparent
End Sub

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

Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
' fresh out this partto pain the gb image
End Sub
a primitive example is from the vb help
Private Sub pictureBox1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs)
' Create a local version of the graphics object for the PictureBox.
Dim g As Graphics = e.Graphics

' Draw a string on the PictureBox.
g.DrawString("This is a diagonal line drawn on the control", _
New Font("Arial", 10), Brushes.Red, New PointF(30.0F, 30.0F))
' Draw a line in the PictureBox.
g.DrawLine(System.Drawing.Pens.Red, pictureBox1.Left, _
pictureBox1.Top, pictureBox1.Right, pictureBox1.Bottom)
End Sub 'pictureBox1_Paint

but then if you already the GB image in some format (tif, bmp,) you may be
better off looking for some picture control to take care of that for you.
Hey, I am newbie to vb too. so I can help very much beyon what I can find by
goole or built help.

you may also want to look at the game snippets or starter kit/template. I
am sure there are plenty of examples for handling graphics

"G .Net" <no********@email.com> wrote in message
news:jZ******************************@pipex.net...
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" <do******@spammuch.com> wrote in message
news:e4*******************@news.demon.co.uk...
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.as...rol&lang=en%3E

"G .Net" <no********@email.com> wrote in message
news:Jf********************@pipex.net...
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



May 19 '06 #5
Many thanks Fred for your comprehensive help.

G

"Fred Hedges" <do******@spammuch.com> wrote in message
news:e4******************@news.demon.co.uk...
(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.SupportsTransparentBackC olor, 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" <no********@email.com> wrote in message
news:jZ******************************@pipex.net...
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" <do******@spammuch.com> wrote in message
news:e4*******************@news.demon.co.uk...
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.as...rol&lang=en%3E

"G .Net" <no********@email.com> wrote in message
news:Jf********************@pipex.net...
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



May 20 '06 #6
Thanks gs.

G

"gs" <gs@nomail.nil> wrote in message
news:ej**************@TK2MSFTNGP05.phx.gbl...
that looks more like VB than c#
I think you will have to fresh out the last stub for OnPaintBackground
with painting you GB image
Imports System
Imports System.Windows.Forms

Public Class TransparentControl
Inherits Control

Private Const WS_EX_TRANSPARENT As Int32 = &H20

Public Sub New()
Me.SetStyle(ControlStyles.SupportsTransparentBackC olor, True)
Me.UpdateStyles()
Me.BackColor = Color.Transparent
End Sub

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

Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
' fresh out this partto pain the gb image
End Sub
a primitive example is from the vb help
Private Sub pictureBox1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs)
' Create a local version of the graphics object for the PictureBox.
Dim g As Graphics = e.Graphics

' Draw a string on the PictureBox.
g.DrawString("This is a diagonal line drawn on the control", _
New Font("Arial", 10), Brushes.Red, New PointF(30.0F, 30.0F))
' Draw a line in the PictureBox.
g.DrawLine(System.Drawing.Pens.Red, pictureBox1.Left, _
pictureBox1.Top, pictureBox1.Right, pictureBox1.Bottom)
End Sub 'pictureBox1_Paint

but then if you already the GB image in some format (tif, bmp,) you may be
better off looking for some picture control to take care of that for you.
Hey, I am newbie to vb too. so I can help very much beyon what I can find
by goole or built help.

you may also want to look at the game snippets or starter kit/template. I
am sure there are plenty of examples for handling graphics

"G .Net" <no********@email.com> wrote in message
news:jZ******************************@pipex.net...
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" <do******@spammuch.com> wrote in message
news:e4*******************@news.demon.co.uk...
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.as...rol&lang=en%3E

"G .Net" <no********@email.com> wrote in message
news:Jf********************@pipex.net...
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



May 20 '06 #7
Yes thats correct. I couldn't find the C# version I used the other day, so
pasted the first VB version I came across, but did not edit the message to
take account of this. Actually, it turns out that this one is better.

"gs" <gs@nomail.nil> wrote in message
news:ej**************@TK2MSFTNGP05.phx.gbl...
that looks more like VB than c#
I think you will have to fresh out the last stub for OnPaintBackground
with painting you GB image
Imports System
Imports System.Windows.Forms

Public Class TransparentControl
Inherits Control

Private Const WS_EX_TRANSPARENT As Int32 = &H20

Public Sub New()
Me.SetStyle(ControlStyles.SupportsTransparentBackC olor, True)
Me.UpdateStyles()
Me.BackColor = Color.Transparent
End Sub

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

Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
' fresh out this partto pain the gb image
End Sub
a primitive example is from the vb help
Private Sub pictureBox1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs)
' Create a local version of the graphics object for the PictureBox.
Dim g As Graphics = e.Graphics

' Draw a string on the PictureBox.
g.DrawString("This is a diagonal line drawn on the control", _
New Font("Arial", 10), Brushes.Red, New PointF(30.0F, 30.0F))
' Draw a line in the PictureBox.
g.DrawLine(System.Drawing.Pens.Red, pictureBox1.Left, _
pictureBox1.Top, pictureBox1.Right, pictureBox1.Bottom)
End Sub 'pictureBox1_Paint

but then if you already the GB image in some format (tif, bmp,) you may be
better off looking for some picture control to take care of that for you.
Hey, I am newbie to vb too. so I can help very much beyon what I can find
by goole or built help.

you may also want to look at the game snippets or starter kit/template. I
am sure there are plenty of examples for handling graphics

"G .Net" <no********@email.com> wrote in message
news:jZ******************************@pipex.net...
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" <do******@spammuch.com> wrote in message
news:e4*******************@news.demon.co.uk...
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.as...rol&lang=en%3E

"G .Net" <no********@email.com> wrote in message
news:Jf********************@pipex.net...
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



May 22 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: lawrence | last post by:
I've the form you see below, which is supposed to upload an image. I expect the image name as a var to be $uploadedFile. In the receiving function, I've this code: global $uploadedFile,...
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
4
by: Kevin Myers | last post by:
Hello, Please forgive my reposting of this note with hopefully a more relevant subject line. On an Access 2000 form under Windows 2000 I would like to use a Kodak Image Edit Control to...
2
by: Don Tucker | last post by:
Hello, I have a Windows Application that needs to load multiple image files in response to users clicking buttons. Currently, I just have these images as .jpg files on disk, but I don't want to...
3
by: Dave | last post by:
Hey all, I have a problem and I can't find anything on the net to really address it. We have a program at work that has lots of numbers on the front of the form because it is a control program...
3
by: jackiepatti | last post by:
QUESTION: I have a web page containing a form that contains an image instead of a submit button, e.g. <form name='myform' action='get' method='otherpage.asp'> <input type='image'...
16
by: browntown | last post by:
so I have this application I'm nearly finished with. The only thing the client has requested is the ability to submit the form by pressing "enter". I didn't think this would be a huge pain in the...
2
by: Poppa Pimp | last post by:
ImageResizer.php Image Resizer PLEASE HELP The URL of the page this is on in my site is http://poppa-pimps-wallpapers.com//ImageResizer.php You can click on browse and get image,but...
7
by: mishrarajesh44 | last post by:
hii all Truly telling i hav got this code from net & i am finding error while running the code below.. code:- <?php $idir = "photo/"; // Path To Images Directory $tdir =...
10
by: mishrarajesh44 | last post by:
hii all, I am facing a problem currently.. i have a script for image uploading and resizing.. the image uploading takes place properly for every size images.. but, the resizing works for...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.