Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i have the following problem (excuse my ignorance if it's a dumb question, i am new to GDI+): i have a PictureBox in a Windows Form and then on it i draw a graphic and some text like so:

 

Dim gStudyGuide As Graphics

 

Friend WithEvents SGBackCover_PictureBox As System.Windows.Forms.PictureBox

Me.SGBackCover_PictureBox = New System.Windows.Forms.PictureBox

 

'

'SGBackCover_PictureBox

'

Me.SGBackCover_PictureBox.Dock = System.Windows.Forms.DockStyle.Fill

Me.SGBackCover_PictureBox.Image = CType(resources.GetObject("SGBackCover_PictureBox.Image"), System.Drawing.Image)

Me.SGBackCover_PictureBox.Location = New System.Drawing.Point(0, 0)

Me.SGBackCover_PictureBox.Name = "SGBackCover_PictureBox"

Me.SGBackCover_PictureBox.Size = New System.Drawing.Size(628, 734)

Me.SGBackCover_PictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage

Me.SGBackCover_PictureBox.TabIndex = 0

Me.SGBackCover_PictureBox.TabStop = False

 

Private Sub StudyGuideBack_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Variables initialization.

gStudyGuide = Graphics.FromImage(Me.SGBackCover_PictureBox.Image)

gStudyGuide.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias

 

Call Me.DrawBarcode()

Call Me.DrawISBN()

End Sub 'End StudyGuideBack_Load

 

Private Sub DrawBarcode()

'Variables declaration and initialization.

Dim orgBmp As New Bitmap(Me.BarcodeDir & "\" & Me.ISBN & ".bmp")

Dim newBmp As New Bitmap(orgBmp, orgBmp.Width, StudyGuide.DEFAULT_BARCODE_HEIGHT)

 

'Draw barcode image over PictureBox Image.

gStudyGuide.DrawImage(newBmp, New Point(StudyGuide.BARCODE_X_COORDINATE, StudyGuide.BARCODE_Y_COORDINATE))

End Sub 'End DrawBarcode

 

Private Sub DrawISBN()

'Variables declaration and initialization.

'Font and brush variables.

Dim drawFont As New Font("Arial", 10)

Dim drawBrush As New SolidBrush(Color.Black)

'Coordinates variables.

Dim xCoordinate As Single = 1730.0F

Dim yCoordinate As Single = 2760.0F

'Initialize string format.

Dim drawFormat As New StringFormat

drawFormat.FormatFlags = StringFormatFlags.NoWrap

 

'Draw ISBN string over PictureBox Image.

gStudyGuide.DrawString(Me.ISBN, drawFont, drawBrush, xCoordinate, yCoordinate, drawFormat)

End Sub 'End DrawISBN

 

so far so good. what i want to do now is be able to change the font of the text i just drew. so to accomplish this a have a FondDialog control in my form and as soon as the user selects new font i'd like to basically replace the text drawn above with the same text but in a different font.

the problem is i don't know how to delete text from a PictureBox. any ideas?

i looked into MSDN documentaion and i found the Graphics.Clear method, but it doesn't seem to be doing what i need.

 

of course i could always redraw everything in the PictureBox, but that would be...well lame. why redraw everything in it when i only need to change the text?

 

any advice would be greatly appreciated.

thanks.

  • 2 weeks later...
  • Leaders
Posted

Yes, you don't erase graphics... you merely draw over them.

 

To draw over it, just take the same drawing line that you have there, change the brush's color and then redraw the string. :)

Or, you can get a Brush from the Brushes collection:

Brushes.Green, Brushes.Blue, etc. :)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...