Groups | Blog | Home
all groups > dotnet drawing api > february 2006 >

dotnet drawing api : GDI+ FAQ Question


JB
2/12/2006 6:38:26 PM
Hi,

I have taken the code from http://www.bobpowell.net/manipulate_graphics.htm.
This works great for creating simple shapes but I have tried to extend the
functionality.

What I want to do is add images to the screen, so that they work in the same
way as all the other shaped.

My code is below:-
Public Class Picture
Inherits Primitive

Public Sub New()
MyBase.New()
End Sub

Public Overloads Overrides Sub Draw(ByVal g As Graphics)
Dim b As SolidBrush = New SolidBrush(Me.Color)

g.FillRectangle(b, New Rectangle(Me.Location, Me.Size))
b.Dispose()

If Highlight Then
Dim p As Pen = New Pen(Color.Red, 3)
p.DashStyle = DashStyle.DashDot
Dim newImage As Image

newImage = Image.FromFile("C:\2.bmp")

g.DrawRectangle(p, New Rectangle(Me.Location, Me.Size))
g.DrawImage(newImage, New Rectangle(Me.Location, Me.Size))

p.Dispose()
End If
End Sub
End Class

The issue is that the picture only shows once my mouse moves over the
rectangle. Otherwise it just shows the rectangle with the random color. I
can not understand why this is, and any help would be much appreciated.

I am using VB.NET on VS 2003.

Lau Lei Cheong
2/13/2006 12:00:00 AM
Have you tried moving the followings outside the Highlight "IF" block?

As far as I can see from the code, the image is shown only when "Highlight =
True".

[quoted text, click to view]

AddThis Social Bookmark Button