Draw text to image

shawnplr

Active member
Joined
May 17, 2007
Messages
44
Programming Experience
Beginner
I'm making a front end to dvdauthor. I have a picturebox which holds the menu background. In order to draw a textbutton on the background image I store the image in a hidden picturebox. So the text doesn't get drawn to the visible background.
Code:
VB.NET:
        Dim ctl As Control
        For Each c As Control In pbMenu1.Controls
            If c.GetType() Is GetType(TextBtn) Then
                ctl = c
                Dim imgSize As New Bitmap(720, 480)
                Dim imgGraphics As Graphics = Graphics.FromImage(bkgrndMenu1.BackgroundImage)
                Dim btnFont As New Font(ctl.Font.Name, CInt(ctl.Font.Size))
                Dim btnPoint As New PointF(CSng(ctl.Location.X.ToString), CSng(ctl.Location.Y.ToString))
                Dim btnForeColor As New SolidBrush(ctl.ForeColor)
                Dim btnBackColor As New SolidBrush(ctl.BackColor)
                imgGraphics.FillRectangle(btnBackColor, 0, 0, bkgrndMenu1.Width, bkgrndMenu1.Height)
                imgGraphics.DrawString(ctl.Text, btnFont, btnForeColor, btnPoint)
            Else
                MessageBox.Show("Your trying to burn a menu without buttons")
            End If
        Next
        bkgrndMenu1.BackgroundImage.Save(Application.StartupPath & "background.png", ImageFormat.Png)
        bkgrndMenu1.BackgroundImage = pbMenu1.BackgroundImage
This works the first time. But if I hit save again it writes the text to the background image on pbMenu1.
Confused
 
Best I could come up with is to save the background image to a temp folder. Then reload it after saving the menu Images. Which means I have to monitor weather the background is the default image or it has been changed. Not a very eloquent solution but it works. Any suggestions would be much appreciated.
 
Sorry to waste your time on dumb questions. The solution I came up with was ridiculously obvious.
VB.NET:
        bkgrndMenu1.BackgroundImage = New Bitmap(New Bitmap(pbMenu1.BackgroundImage))
Solved
 
Last edited:
Back
Top