PC Review


Reply
Thread Tools Rate Thread

CreateGraphics() throws NotSupportedException

 
 
Christian Schwarz
Guest
Posts: n/a
 
      17th Sep 2003
Hello,

I get a NotSupportedException when using the following code snippet in the
constructor of my ImageButton control:

System.Drawing.Graphics gfx = this.CreateGraphics();
SizeF textSizeF = gfx.MeasureString(this.Text, this.Font);
this.m_TextSize = new Size((int)Math.Floor(textSizeF.Width),
(int)Math.Floor(textSizeF.Height));
gfx.Dispose();

To be exact, the exception is thrown by the first line. Could anyone explain
why CreateGraphics() doesn't work here ?

Christian


 
Reply With Quote
 
 
 
 
Chris Tacke, eMVP
Guest
Posts: n/a
 
      17th Sep 2003
Not sure what "this" is in the context of your code, but ti's likely not an
object that supports CreateGraphics. I think the only items that support
CreateGraphics are Control, Panel, Form and PictureBox.


--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net

"Christian Schwarz" <(E-Mail Removed)> wrote in message
news:bk9tp7$qtokm$(E-Mail Removed)...
> Hello,
>
> I get a NotSupportedException when using the following code snippet in the
> constructor of my ImageButton control:
>
> System.Drawing.Graphics gfx = this.CreateGraphics();
> SizeF textSizeF = gfx.MeasureString(this.Text, this.Font);
> this.m_TextSize = new Size((int)Math.Floor(textSizeF.Width),
> (int)Math.Floor(textSizeF.Height));
> gfx.Dispose();
>
> To be exact, the exception is thrown by the first line. Could anyone

explain
> why CreateGraphics() doesn't work here ?
>
> Christian
>
>



 
Reply With Quote
 
Serg Kuryata [MS]
Guest
Posts: n/a
 
      18th Sep 2003
Hello Christian,

The CreateGraphics() is supported only for the Control and Form classes.
Calling this method for any other classes will throw NotSupportedException.

Thank you,
Sergiy.

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| From: "Christian Schwarz" <(E-Mail Removed)>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| Subject: CreateGraphics() throws NotSupportedException
| Date: Wed, 17 Sep 2003 17:15:33 +0200
| Lines: 17
| Message-ID: <bk9tp7$qtokm$(E-Mail Removed)>
| NNTP-Posting-Host: p50886498.dip0.t-ipconnect.de (80.136.100.152)
| X-Trace: news.uni-berlin.de 1063811687 28238486 80.136.100.152 (16
[57495])
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!newsfeed.freenet.de!fu-berlin.de!uni-berlin.de!p50886498.dip0.t-ipconne
ct.DE!not-for-mail
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:33755
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| Hello,
|
| I get a NotSupportedException when using the following code snippet in the
| constructor of my ImageButton control:
|
| System.Drawing.Graphics gfx = this.CreateGraphics();
| SizeF textSizeF = gfx.MeasureString(this.Text, this.Font);
| this.m_TextSize = new Size((int)Math.Floor(textSizeF.Width),
| (int)Math.Floor(textSizeF.Height));
| gfx.Dispose();
|
| To be exact, the exception is thrown by the first line. Could anyone
explain
| why CreateGraphics() doesn't work here ?
|
| Christian
|
|
|

 
Reply With Quote
 
Christian Schwarz
Guest
Posts: n/a
 
      18th Sep 2003
Thank you for the answers.

My ImageButton's base class is System.Windows.Forms.Button, which you say
doesn't support CreateGraphics() method. What can I do, if I need the
CreateGraphics() method in order to measure a string's size ? Creating a
dummy control to use it's CreateGraphics() method ?

Christian


 
Reply With Quote
 
Serg Kuryata [MS]
Guest
Posts: n/a
 
      18th Sep 2003
You can inherit your custom button from the Control class. Then you will be
able to call the CreateGraphics() method.

Hope this helps,
Sergiy.

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| From: "Christian Schwarz" <(E-Mail Removed)>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| Subject: Re: CreateGraphics() throws NotSupportedException
| Date: Thu, 18 Sep 2003 08:25:52 +0200
| Lines: 10
| Message-ID: <bkbj0r$r70bj$(E-Mail Removed)>
| References: <bk9tp7$qtokm$(E-Mail Removed)>
| NNTP-Posting-Host: p50886498.dip0.t-ipconnect.de (80.136.100.152)
| X-Trace: news.uni-berlin.de 1063866203 28541299 80.136.100.152 (16
[57495])
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGXA06.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP0
8.phx.gbl!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!
fu-berlin.de!uni-berlin.de!p50886498.dip0.t-ipconnect.DE!not-for-mail
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:33818
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| Thank you for the answers.
|
| My ImageButton's base class is System.Windows.Forms.Button, which you say
| doesn't support CreateGraphics() method. What can I do, if I need the
| CreateGraphics() method in order to measure a string's size ? Creating a
| dummy control to use it's CreateGraphics() method ?
|
| Christian
|
|
|

 
Reply With Quote
 
Alex Feinman [MVP]
Guest
Posts: n/a
 
      19th Sep 2003
Call CreateGraphics on Button's parent form:

Form frm = myButton.TopLevelControl as Form;
if ( frm != null )
{
Graphics g = frm.CreateGraphics();
g.MeasureString(myButton.Text, myButton.Font);
}

"Christian Schwarz" <(E-Mail Removed)> wrote in message
news:bkbj0r$r70bj$(E-Mail Removed)...
> Thank you for the answers.
>
> My ImageButton's base class is System.Windows.Forms.Button, which you say
> doesn't support CreateGraphics() method. What can I do, if I need the
> CreateGraphics() method in order to measure a string's size ? Creating a
> dummy control to use it's CreateGraphics() method ?
>
> Christian
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
InvokeMember throws a NotSupportedException Ralfeus Microsoft C# .NET 0 17th May 2007 08:35 PM
System.Diagnostics.Process throws System.NotSupportedException Joe K Microsoft Dot NET Framework 3 6th Feb 2007 07:58 PM
TabPage.CreateGraphics throwing NotSupportedException anon@yahoo.com Microsoft Dot NET Compact Framework 1 7th Feb 2005 07:39 PM
Graphics.MeasureString throws System.NotSupportedException Meetali Goel Microsoft C# .NET 0 7th Dec 2004 01:02 AM
NotSupportedException when CreateGraphics =?Utf-8?B?S2VtcHRvbg==?= Microsoft Dot NET Compact Framework 3 14th May 2004 07:13 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:44 AM.