|
-
Nov 29th, 2010, 06:11 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] System.Drawing.Drawing2D.GraphicsPath Question
Hey all,
I'm trying to write a method that is called from a variety of forms at load.
So with a Form1 load event I would call the following:
Code:
Dim testpoint As New Point(10, 20)
DrawVerticalStringFromBottomUp("Hello", testpoint, Me)
The DrawVerticalSTringFromBottomUp Method is as follows:
Code:
Public Sub DrawVerticalStringFromBottomUp(ByVal textToAdd As String, ByVal location As Point, ByVal callingForm As Form)
' Create the string to draw on the form.
Dim text As String = textToAdd
' Create a GraphicsPath.
Dim path As New System.Drawing.Drawing2D.GraphicsPath
' Add the string to the path; declare the font, font style, size, and
' vertical format for the string.
path.AddString(text, callingForm.Font.FontFamily, 1, 10, New PointF(0.0F, 0.0F), _
New StringFormat(StringFormatFlags.DirectionVertical))
' Declare a matrix that will be used to rotate the text.
Dim rotateMatrix As New System.Drawing.Drawing2D.Matrix
' Set the rotation angle and starting point for the text.
rotateMatrix.RotateAt(180.0F, location)
' Transform the text with the matrix.
path.Transform(rotateMatrix)
With callingForm.CreateGraphics
.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
.FillPath(Brushes.Black, path)
End With
' Dispose of the path.
path.Dispose()
End Sub
When I call the code at a form's load event, nothing happens.
When I call it from a button click after the form has loaded it works!
I know this should be called from the paint method, but that doesn't suit my purposes.
Can anyone suggest a way to make this work from the form load event?
Thanks!
Nick
-
Nov 29th, 2010, 06:36 PM
#2
Re: System.Drawing.Drawing2D.GraphicsPath Question
I think it's failing because when the Load event occurs, there is nothing to paint on. Try moving the code into the Form.Shown event handler instead.
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Nov 29th, 2010, 11:18 PM
#3
Thread Starter
Hyperactive Member
Re: System.Drawing.Drawing2D.GraphicsPath Question
I just tried with the form Shown event with no luck.
If I place it in the paint event, it keeps flashing up.
-
Nov 30th, 2010, 03:37 AM
#4
Re: System.Drawing.Drawing2D.GraphicsPath Question
A Paint event always fires at the end of the form startup sequence and wipes anything you try to do beforehand with CreateGraphics.
Do want to flash the text just once only at startup? If so, you could draw it in the Paint Event in the normal way (using e.Graphics), but only if a Boolean flag is set to true. In the form's Load event, set the flag to true and start a timer to expire in say 0.5 seconds. In the timer's Tick event, set the flag to false, invalidate the form and stop the timer.
BB
-
Nov 30th, 2010, 01:37 PM
#5
Thread Starter
Hyperactive Member
Re: System.Drawing.Drawing2D.GraphicsPath Question
Thanks Boops Boops; I managed to get your flag method to work.
Not ideal, but does the trick!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|