473,471 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Make background of graphics object transparent.

I keep getting my string inside a black box with this code.
I would like to make the background transparent. Any help on this will
be appreciated very much.

'**** BEGIN CODE ****
Try

Dim NewFont As New Font(fg.Font.FontFamily, 10, FontStyle.Regular)

Dim g As Graphics

Dim pic As Bitmap = New Bitmap(20, 20,
imaging.PixelFormat.Format24bppRgb)

g = Graphics.FromImage(pic)

g.Clear(Color.Transparent)

g.DrawString("H", NewFont, Brushes.Blue, 0, 0)
Dim st As New System.IO.MemoryStream

pic.Save(st, System.Drawing.Imaging.ImageFormat.Bmp)
Dim img As Image = Image.FromStream(st)
pct.Image = img

Catch exc As Exception
Stop

End Try
'**** END CODE ****

Kalvin

Nov 21 '05 #1
2 8150
Hi,

Try something like this.

Try

Dim g As Graphics

Dim pic As Bitmap = New Bitmap(20, 20, Imaging.PixelFormat.Format24bppRgb)

g = Graphics.FromImage(pic)

g.Clear(Color.Yellow)

g.DrawString("H", Me.Font, Brushes.Blue, 0, 0)

pic.MakeTransparent(Color.Yellow)

'Dim st As New System.IO.MemoryStream

'pic.Save(st, System.Drawing.Imaging.ImageFormat.Bmp)

'Dim img As Image = Image.FromStream(st)

PictureBox1.Image = pic

Catch exc As Exception

Stop

End Try

Ken

---------------------------

"Kalvin" <kt***@streck.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I keep getting my string inside a black box with this code.
I would like to make the background transparent. Any help on this will
be appreciated very much.

'**** BEGIN CODE ****
Try

Dim NewFont As New Font(fg.Font.FontFamily, 10, FontStyle.Regular)

Dim g As Graphics

Dim pic As Bitmap = New Bitmap(20, 20,
imaging.PixelFormat.Format24bppRgb)

g = Graphics.FromImage(pic)

g.Clear(Color.Transparent)

g.DrawString("H", NewFont, Brushes.Blue, 0, 0)
Dim st As New System.IO.MemoryStream

pic.Save(st, System.Drawing.Imaging.ImageFormat.Bmp)
Dim img As Image = Image.FromStream(st)
pct.Image = img

Catch exc As Exception
Stop

End Try
'**** END CODE ****

Kalvin
Nov 21 '05 #2


Thank you very much for your reply. I did try that, but what I wind up
with is still a black background. When I use the
pic.clear(color.yellow) line without the
pic.MakeTransparent(Color.Yellow) line, I get a yellow background, as
soon as I add the maketransparent call execute, I get the black
background again. I did find that if I don't save it to the
memoryStream, then the background is transparent. Is there something
with the memory stream that is going to color the background?

Kalvin

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3

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

Similar topics

5
by: Paul Schnitter | last post by:
Update: My custom control is based on the article "Creating Visual Basic .NET controls from scratch" in "Adventures in .NET" on MSDN. It is designed to be a replacement for the VB6 shape...
11
by: Konrad Den Ende | last post by:
I have a function returning a string but the problem is that the color of it is blue which suits me well for some pages but not for others. Is it possible to "feel" what the color of the background...
1
by: Chris Auer | last post by:
I have been banging my head for a couple of hours now. No matter what I do the color that I make transparent is black. Here is the code I am using from MSDN. I have tried bitmaps, jpegs, gifs and...
1
by: Robert W. | last post by:
In my Winforms app I'm trying to get an image's background to appear transparent on a form that has a gradient background. So I added a PictureBox and then attempted to add a custom paint command...
8
by: Grahammer | last post by:
Is it possible to set the background of a usercontrol as transparent? I tried setting the background image of the usercontrol to a transparent GIF, but that caused MAJOR problems. I'm making...
7
by: Martin | last post by:
I'm using the code show below (in VB.Net 2003) to create an image. I want to save this image to a .PNG file such that when I subsequently display it as part of a web page, the background of the...
1
by: Eric | last post by:
I created a gradient form and want the background of the labels to take on the same color pattern as the parent form. Is this easily possible? Thanks
8
by: Brian Ward | last post by:
I am looking for a simple way to set the image transparency in a PictureBox. I have a moving PictureBox containing a graphic image .. moving by incrementing its Left property. The background...
1
by: Bryon | last post by:
My current code paints a rectangular area at the top (under the menu and tool strip) and bottom (top of the status strip) of the main form with a linear gradient. The problem is that when the form...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.