Make it transparent

tesseract

Member
Joined
Jul 3, 2008
Messages
13
Programming Experience
3-5
I thought the transpency key would make anything that color transparent but i have tryed picture boxes changing the background image and even creating the graphics and manualy drawing the image but the effect i want is a ball for a forum.

this is an image of the code and forum (the transpency key is magenta)

76755207hq2.gif
 
The magenta-like color in the image you posted is not magenta (it has RGB 252,4,252), but that could be caused by the tainted gif encoding... otherwise it should have worked. A few comments still; Set the TransparencyKey in Load event, not a million times in Paint event. Do realize this will make that part of form fully see-through transparent, if you only want to rid that part of the image but retain the form backcolor use the MakeTransparent method of Bitmap class. Do use the correct graphics instance when you draw in Paint event, e.Graphics is provided for this purpose. If you ever need to use CreateGraphics again remember to Dispose it when you're done. Also the bitmap must be disposed in your code, but there is also no need to load that in Paint event a million times, just load it to a private variable from form Load event.
 
i dont know why but i changed it to this and it works, and you were kind of right, the lower left section was close to maganta but i fixed that


VB.NET:
Public Class Ball
    Dim G As Graphics

    Private Sub Ball_Load() Handles Me.Load
        Me.TransparencyKey = Color.Magenta()
    End Sub

    Private Sub Ball_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim bmp As New Bitmap("C:\Documents and Settings\Steven Bayer\My Documents\Visual Studio 2008\ball.bmp")
        e.Graphics.DrawImage(bmp, 0, 0, 100, 100)
    End Sub

    Private Sub Ball_Shown() Handles Me.Shown
        Me.Height = 100
        Me.Width = 100
    End Sub

End Class
 
You still have a major memory leak in your code with the bitmap you're loading a million times without disposing. Move the "Dim bmp..." line to class level and it's fixed, alternative is to add bmp.Dispose() after DrawImage.
 
Back
Top