NotSupportException caused by DrawString

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I create a custom control which inherits Picturebox. the e.Graphics.DrawString in the OnPaint method causes a NotSupportedException.

Could anyone help?
 
Can you post the complete code for your OnPaint method?

--
Tim Wilson
..Net Compact Framework MVP

Kempton said:
I create a custom control which inherits Picturebox. the
e.Graphics.DrawString in the OnPaint method causes a NotSupportedException.
 
Public Class PicBody
Inherits System.Windows.Forms.PictureBox

Private xArr() As Integer = {-1, -1, -1, -1, -1, -1} 'the x-coordinates of all nodes
Private yArr() As Integer = {-1, -1, -1, -1, -1, -1} 'the y-coordinates of all nodes


Protected Overrides Sub onPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
e.Graphics.DrawImage(Me.Image, 0, 0) 'show the body picture
Dim b As New SolidBrush(Color.Red)

Dim i As Integer
For i = 0 To xArr.Length - 1
If xArr(i) >= 0 And yArr(i) >= 0 Then
e.Graphics.FillEllipse(b, xArr(i), yArr(i), 5, 5)
Dim s As String
If i = 0 Then
s = "Primary"
Else
s = "Node " & i.ToString
End If
'e.Graphics.DrawString(s, Font, b, (xArr(i) + 10), yArr(i))
End If
Next

b.Dispose()
End Sub


Public Sub setNode(ByVal nodeNum As Integer, ByVal x As Integer, ByVal y As Integer)
If nodeNum < xArr.Length Then
xArr(nodeNum) = x
yArr(nodeNum) = y
End If
End Sub
End Class
 
The actual issue is with getting and setting the Font property. It looks
like it's not supported for the PictureBox. If you create your own property
to store the font it should work. Add the code below to your PicBody class.

Private _Font As Font = New Font("Tahoma", 8, FontStyle.Regular)

Public Overrides Property Font() As System.Drawing.Font
Get
Return _Font
End Get
Set(ByVal Value As System.Drawing.Font)
_Font = Value
End Set
End Property
 
Yes, Tim is correct. The Font property is not supported by the PictureBox
control.

Thank you,
Sergiy.

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM>
| References: <[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: NotSupportException caused by DrawString
| Date: Thu, 8 Jul 2004 08:25:37 -0400
| Lines: 83
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host:
cpe00045af65bf7-cm014210012048.cpe.net.cable.rogers.com 24.103.185.244
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGXS01.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP0
8.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:56916
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| The actual issue is with getting and setting the Font property. It looks
| like it's not supported for the PictureBox. If you create your own
property
| to store the font it should work. Add the code below to your PicBody
class.
|
| Private _Font As Font = New Font("Tahoma", 8, FontStyle.Regular)
|
| Public Overrides Property Font() As System.Drawing.Font
| Get
| Return _Font
| End Get
| Set(ByVal Value As System.Drawing.Font)
| _Font = Value
| End Set
| End Property
|
| --
| Tim Wilson
| .Net Compact Framework MVP
|
| | > Public Class PicBody
| > Inherits System.Windows.Forms.PictureBox
| >
| > Private xArr() As Integer = {-1, -1, -1, -1, -1, -1} 'the
| x-coordinates of all nodes
| > Private yArr() As Integer = {-1, -1, -1, -1, -1, -1} 'the
| y-coordinates of all nodes
| >
| >
| > Protected Overrides Sub onPaint(ByVal e As
| System.Windows.Forms.PaintEventArgs)
| > e.Graphics.DrawImage(Me.Image, 0, 0) 'show the body
picture
| > Dim b As New SolidBrush(Color.Red)
| >
| > Dim i As Integer
| > For i = 0 To xArr.Length - 1
| > If xArr(i) >= 0 And yArr(i) >= 0 Then
| > e.Graphics.FillEllipse(b, xArr(i), yArr(i), 5, 5)
| > Dim s As String
| > If i = 0 Then
| > s = "Primary"
| > Else
| > s = "Node " & i.ToString
| > End If
| > 'e.Graphics.DrawString(s, Font, b, (xArr(i) + 10),
| yArr(i))
| > End If
| > Next
| >
| > b.Dispose()
| > End Sub
| >
| >
| > Public Sub setNode(ByVal nodeNum As Integer, ByVal x As Integer,
ByVal
| y As Integer)
| > If nodeNum < xArr.Length Then
| > xArr(nodeNum) = x
| > yArr(nodeNum) = y
| > End If
| > End Sub
| > End Class
| >
| > "Tim Wilson" wrote:
| >
| > > Can you post the complete code for your OnPaint method?
| > >
| > > --
| > > Tim Wilson
| > > ..Net Compact Framework MVP
| > >
| > > | > > > I create a custom control which inherits Picturebox. the
| > > e.Graphics.DrawString in the OnPaint method causes a
| NotSupportedException.
| > > >
| > > > Could anyone help?
| > >
| > >
| > >
|
|
|
 
Back
Top