Drawline and DrawString Error?

  • Thread starter Butt Chin Chuan
  • Start date
B

Butt Chin Chuan

I got this error message when I try to call this line:
pbGraph.CreateGraphics.DrawLine(redPen, 250, 2500, 250,
2500)
pbGraph.CreateGraphics.DrawLine(redPen, 20, 180, 20, 180)
pbGraph.CreateGraphics.DrawLine(redPen, CInt(20.0F), CInt
(180.0F), CInt(20), CInt(180)) ' x axis

Error message displayed:
An unhandled exception of
type 'System.NotSupportedException' occurred in
System.Windows.Forms.dll

Additional information: NotSupportedException

I think the first try have the x and y point exceeded the
limit of the picture box (since I copied and modified the
code from eVB), so, I changed to the second and third
line, but the same error still occurs! What happened!
Anyone have any idea what happened? I looked into MSDN and
I still got stuck (the third line followed MSDN example).

I want to append to my earlier post. The drawString
function too gives me the same problem:
pbGraph.CreateGraphics.DrawString("0", drawFont,
drawBrush, 25, 150)

I too look into MSDN and got the following example, which
also give me error (StringFormat not supported, DrawFont
cannot fails in overload resolution because no
accessible "New" accepts this number of argument etc when
the code is actually from MSDN!) :
Public Sub DrawStringFloatFormat(e As PaintEventArgs)
' Create string to draw.
Dim drawString As [String] = "Sample Text"
' Create font and brush.
Dim drawFont As New Font("Arial", 16)
Dim drawBrush As New SolidBrush(Color.Black)
' Create point for upper-left corner of drawing.
Dim x As Single = 150F
Dim y As Single = 50F
' Set format of string.
Dim drawFormat As New StringFormat()
drawFormat.FormatFlags =
StringFormatFlags.DirectionVertical
' Draw string to screen.
e.Graphics.DrawString(drawString, drawFont, drawBrush, _
x, y, drawFormat)
End Sub

To overcome the problems (DrawFont), I have to changed it
to the following by adding an extra argument, which works
(at least I think so, unable to test out since I got stuck
calling DrawString method:
Dim drawFont As New Font("Arial", 16, FontStyle.Regular)

Any comments?
 
D

DarinJ

Take a look at the Bubbles sample that comes with .Net for the Compact
Framework.

I ran into those problems when trying to Draw to a picture box. The sample
shows to draw to an offscreen bitmap then draw the bimap to the picturebox.
 
B

Butt Chin Chuan

If possible, can you include a code snippet how to draw
line and draw string in the picture box? I'm not good
in .Net programming yet, and I don't really understand the
Bubble sample. I just need to draw some lines and text in
the picture box, in eVB, I can do it by
picturebox1.drawline or something, so I assumed
pbGraph.CreateGraphics.DrawLine(redPen, CInt(20.0F), CInt
(180.0F), CInt(20), CInt(180)) is the equavalent in .Net.
Seems I wrong. Can anyone please help? Thank you.
-----Original Message-----
Take a look at the Bubbles sample that comes with .Net for the Compact
Framework.

I ran into those problems when trying to Draw to a picture box. The sample
shows to draw to an offscreen bitmap then draw the bimap to the picturebox.



I got this error message when I try to call this line:
pbGraph.CreateGraphics.DrawLine(redPen, 250, 2500, 250,
2500)
pbGraph.CreateGraphics.DrawLine(redPen, 20, 180, 20, 180)
pbGraph.CreateGraphics.DrawLine(redPen, CInt(20.0F), CInt
(180.0F), CInt(20), CInt(180)) ' x axis

Error message displayed:
An unhandled exception of
type 'System.NotSupportedException' occurred in
System.Windows.Forms.dll

Additional information: NotSupportedException

I think the first try have the x and y point exceeded the
limit of the picture box (since I copied and modified the
code from eVB), so, I changed to the second and third
line, but the same error still occurs! What happened!
Anyone have any idea what happened? I looked into MSDN and
I still got stuck (the third line followed MSDN example).

I want to append to my earlier post. The drawString
function too gives me the same problem:
pbGraph.CreateGraphics.DrawString("0", drawFont,
drawBrush, 25, 150)

I too look into MSDN and got the following example, which
also give me error (StringFormat not supported, DrawFont
cannot fails in overload resolution because no
accessible "New" accepts this number of argument etc when
the code is actually from MSDN!) :
Public Sub DrawStringFloatFormat(e As PaintEventArgs)
' Create string to draw.
Dim drawString As [String] = "Sample Text"
' Create font and brush.
Dim drawFont As New Font("Arial", 16)
Dim drawBrush As New SolidBrush(Color.Black)
' Create point for upper-left corner of drawing.
Dim x As Single = 150F
Dim y As Single = 50F
' Set format of string.
Dim drawFormat As New StringFormat()
drawFormat.FormatFlags =
StringFormatFlags.DirectionVertical
' Draw string to screen.
e.Graphics.DrawString(drawString, drawFont, drawBrush, _
x, y, drawFormat)
End Sub

To overcome the problems (DrawFont), I have to changed it
to the following by adding an extra argument, which works
(at least I think so, unable to test out since I got stuck
calling DrawString method:
Dim drawFont As New Font("Arial", 16, FontStyle.Regular)

Any comments?


.
 

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