Actually internal represenation of a rectangle consists of X, Y (left top
corner) and cx, cy (dimensions). All 4 are settable independently. THis
means you can use just one rectangle and keep changing its size and position
as needed
"Richard Jones" <(E-Mail Removed)> wrote in message
news:0EC9ED2E-18BB-406E-A6D4-(E-Mail Removed)...
> Hi Alex
> Thanks for the advice... I've done most of what you suggested, but I'm a
bit stuck on what to do with the rectangles. I will be drawing various sizes
and positions of rectangles; so I guess I need a separate rectangle instance
of each size/position? I can't change the position or size of a rectangle
after it's been instantiated can I? So will I have to create a new rectangle
instance every time the draw method is called, and then dispose of it?
>
> Any ideas? I've put the beginnings of the class below so you can get an
idea of where I'm going.
>
> Cheers
>
> Rich
>
>
> Public Class DirectDraw
>
> ' --------------- Declare Class Variables -------------------
>
> ' Brushes
> Private BrushWhite As New SolidBrush(Color.White)
> Private Brushcyan As New SolidBrush(Color.Cyan)
> Private Brushskyblue As New SolidBrush(Color.SkyBlue)
> Private Brushplum As New SolidBrush(Color.Plum)
> Private Brushlime As New SolidBrush(Color.Lime)
> Private Brushyellowgreen As New SolidBrush(Color.YellowGreen)
> Private Brushspringgreen As New SolidBrush(Color.SpringGreen)
> Private Brushdodgerblue As New SolidBrush(Color.Gold)
> Private Brushgold As New SolidBrush(Color.Gold)
>
> ' Rectangles
> ' ???
>
> ' Fonts
> Private f_arial_10 As New Font("arial", 10, FontStyle.Regular)
> Private f_tahoma_10 As New Font("tahoma", 10, FontStyle.Regular)
> Private f_arial_11 As New Font("arial", 11, FontStyle.Regular)
> Private f_tahoma_11 As New Font("tahoma", 11, FontStyle.Regular)
> Private f_arial_12 As New Font("arial", 12, FontStyle.Regular)
> Private f_tahoma_12 As New Font("tahoma", 12, FontStyle.Regular)
> Private f_tahoma_70 As New Font("tahoma", 70, FontStyle.Regular)
>
> ' Bitmaps
> Private bmpOff As New Bitmap(640, 480) ' off-screen bitmap : full
screen
>
> ' Graphics Objects
> Private gxOff As Graphics = Graphics.FromImage(bmpOff) ' graphics
object associated with offscreen drawing
>
> 'Private r As New RectangleF(pointx, pointy, sizex, sizey)
> 'Private rr As New RectangleF(0, 0, sizex, sizey)
> 'Private b As New SolidBrush(text_col)
>
>
> ' ------------------- Create Properties ----------------------
>
>
> ' -------------------- Create Methods ------------------------
> Public Sub draw_text(ByVal text_col As String, ByVal pointx As
Integer, ByVal pointy As Integer, ByVal sizex As Integer, ByVal sizey As
Integer, ByVal drawtext As String, ByVal e As
System.Windows.Forms.PaintEventArgs)
>
> ' To avoid flicker, double buffer onto bitmap then display.
> ' clear the section of bitmap
> ' to do : need to handle rectangles...
>
> ' decide what colour this is and draw text onto bitmap
> Select Case text_col
> Case "white"
> gxOff.DrawString(drawtext, f_tahoma_10, BrushWhite,
pointx, pointy)
> Case "cyan"
> gxOff.DrawString(drawtext, f_tahoma_10, Brushcyan, pointx,
pointy)
> Case "dodgerblue"
> gxOff.DrawString(drawtext, f_tahoma_10, Brushdodgerblue,
pointx, pointy)
> Case "skyblue"
> gxOff.DrawString(drawtext, f_tahoma_10, Brushskyblue,
pointx, pointy)
> Case "lime"
> gxOff.DrawString(drawtext, f_tahoma_10, Brushlime, pointx,
pointy)
> Case "yellowgreen"
> gxOff.DrawString(drawtext, f_tahoma_10, Brushyellowgreen,
pointx, pointy)
> Case "springgreen"
> gxOff.DrawString(drawtext, f_tahoma_10, Brushspringgreen,
pointx, pointy)
> Case "plum"
> gxOff.DrawString(drawtext, f_tahoma_10, Brushplum, pointx,
pointy)
> Case "gold"
> gxOff.DrawString(drawtext, f_tahoma_10, Brushgold, pointx,
pointy)
>
> End Select
>
> ' Draw bitmap section onto screen
> ' this bit draws the appropriate section of bmpOff (written to
above) to the passed graphics object
> ' r needs to be sorted out, as does the last parameter
> e.Graphics.DrawImage(bmpOff, r, pointx, pointy, sizex, sizey,
GraphicsUnit.Pixel, 0)
>
> End Sub
>
> End Class