We help IT Professionals succeed at work.

Setting background image.

Kinger247
Kinger247 used Ask the Experts™
on
Hi all,

Via the onPaint event I’m trying to draw some boxes/text on a control over the selected background image.
But I need to clear the control before each paint event to stop blurring of text, but this stops me showing the background image.

How can I get around this or should I say “do it correctly” ?

I want to be able to use the controls BackgroundImage / BackgroundImageLayout properties.

My code below ...

Thanks in advance
K.


  Public Overrides Property BackgroundImage() As Image
    Get
      Return _BackgroundImage
    End Get
    Set(ByVal value As Image)
      _BackgroundImage = value
      MyBase.BackgroundImage = value
      Me.Invalidate()
    End Set
  End Property

  Private _BackgroundImage As Image = Nothing

  Private Sub ucGraph_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

    BackBuffer = New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)
    Using gr As Graphics = Graphics.FromImage(BackBuffer)
      gr.SmoothingMode = SmoothingMode.HighQuality
      gr.InterpolationMode = InterpolationMode.High
      gr.Clear(Color.White)

      MyBase.BackgroundImage = _BackgroundImage

      'Draw everything else here .......

    End Using

    e.Graphics.DrawImageUnscaled(BackBuffer, 0, 0)
  End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
Can you give more details?

I can't get my text to blur in a simple example.  Furthermore, I didn't need to draw the BackgroundImage manually...just set it using the default built-in property and then use the Paint() event like this:


    Imports System.Drawing.Drawing2D
    Public Class ucGraph

        Private Sub ucGraph_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
            Dim G As Graphics = e.Graphics
            G.SmoothingMode = SmoothingMode.HighQuality
            G.InterpolationMode = InterpolationMode.High

            ' ...draw the text with "G"...

        End Sub

    End Class

The text properly appeared over the already drawn backgroundimage and properly redrew itself in response to usercontrol size changes and even when a new backgroundimage was set.

Author

Commented:
I'll give you the points for your time :)