Label strings

D

David Sobey

I've been using the GDI+ DrawString() lately and have noticed it is very
slow. I'm curious, how do basic components like Label etc draw their
strings? I just assumed they used DrawString like us normal humans, but am i
wrong?

cheers
dave
 
H

Herfried K. Wagner [MVP]

David Sobey said:
I've been using the GDI+ DrawString() lately and have noticed it is very
slow. I'm curious, how do basic components like Label etc draw their
strings? I just assumed they used DrawString like us normal humans, but am
i wrong?

If 'FlatStyle' of labels, buttons, etc. is set to a value <> 'System' GDI+
is used to draw the control, otherwise GDI. GDI is hardware-accelerated,
GDI+ is not accelerated by hardware and is thus slower than GDI.
 
S

Supra

no. u r not wrong.
i usually drawn line first then do drawstring
take a llok od my code in below:

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
'local scope
Dim myGraphics As Graphics
Dim myPen As New Pen(Color:=Color.Blue, Width:=2)
Dim myPath As New System.Drawing.Drawing2D.GraphicsPath
Dim myPoints(2) As Point
Dim myRegion As Region
Dim i As Short

'define a triangle
myPath.StartFigure()
myPoints(0) = New Point(x:=100, y:=20)
myPoints(1) = New Point(x:=50, y:=100)
myPoints(2) = New Point(x:=150, y:=100)

'add triangle to the path
myPath.AddPolygon(points:=myPoints)

'create a region based on the path
myRegion = New Region(path:=myPath)

'return the current form as a drawing surface
myGraphics = Graphics.FromHwnd(hwnd:=ActiveForm().Handle)

'draw the region's outline to the screen
myGraphics.DrawPath(Pen:=myPen, path:=myPath)

'set the clipping region
myGraphics.SetClip(Region:=myRegion, _
CombineMode:=Drawing.Drawing2D.CombineMode.Replace)

'draw the string multiple times
For i = 20 To 100 Step 20
'draw clipped text
myGraphics.DrawString(s:="VISUALBASIC", _
Font:=New Font(familyName:="Arial", emSize:=18, _
style:=FontStyle.Regular, _
unit:=GraphicsUnit.Pixel), _
Brush:=New SolidBrush(Color:=Color.Red), _
x:=50, y:=i)
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top