473,382 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Using System.Drawing.Graphics MeasureString() in a console Applicaiton

I'm trying to use MeasureString() to determine the length in pixels of a
string

However to do I need a System.Drawing.Graphics object

to do this I need to create a System.Drawing.Graphics object for which there
is only
two constructors

System.Drawing.Graphics.FromHdc

and

System.Drawing.Graphics.FromHwnd

My application is a C# Console application and I don't have and Forms to
pass the handle
into.

Does anyone know of a way of me overcoming this problem? perhaps I can get
the DesktopWindow in C#?

public SizeF HowBigIsThisText(string myString)
{
Font MyFontObject = new Font("MS San Serif",8);
System.Draing.Graphics gr=System.Drawing.Graphics.FromHwnd(<Don't know
what handle to provide here>)

return gr.MeasureStringmyString,MyFontObject);
}

Many thanks in advance

Dr Paul Hoad
Nov 15 '05 #1
1 9545
Paul Hoad wrote:
I'm trying to use MeasureString() to determine the length in pixels
of a string

However to do I need a System.Drawing.Graphics object

to do this I need to create a System.Drawing.Graphics object for
which there is only
two constructors

System.Drawing.Graphics.FromHdc

and

System.Drawing.Graphics.FromHwnd

My application is a C# Console application and I don't have and
Forms to pass the handle
into.

Does anyone know of a way of me overcoming this problem? perhaps I
can get the DesktopWindow in C#?

public SizeF HowBigIsThisText(string myString)
{
Font MyFontObject = new Font("MS San Serif",8);
System.Draing.Graphics gr=System.Drawing.Graphics.FromHwnd(<Don't
know what handle to provide here>)

return gr.MeasureStringmyString,MyFontObject);
}

Many thanks in advance

Dr Paul Hoad


Just create a form, set its Visible to false, then use its CreateGraphics
method.

- Pete
Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Yaron | last post by:
Hi, I made a procedure which receives a Graphics parameter, and with that Graphics parameter, performs various things. The area of confusion here is that when I pass the procedure a Graphics...
1
by: Dan Kelley | last post by:
I have 2 projects - 1 Winform project that sends Udp messages using the UdpClient class when a button is clicked, and a Console application that listens for these Udp messages. If I try to use...
0
by: Nigel | last post by:
I successfully create a .NET Component (Visual Basic .NET) that would print, unfortunately when used within a web browser it appears that .NET security doesn't allow you to run code that interacts...
3
by: Hitesh | last post by:
Hi, I am getting the response from another Website by using the HttpHandler in my current site. I am getting the page but all the images on that page are not appearing only placeholder are...
8
by: Al Jones | last post by:
Okay, this is dumb.... In gwbasic I can print using "#####.####"; 12.987654 and that produces ,,,12.9876 (commas for spaces). I've looked at buildstring, and tostring but nothing I've seen...
4
by: John Swan | last post by:
Hello. I'm trying to create a simple program that amongst other things creates a thumbnail of an image (Bitmap) to a set size determined by the user in pixels? The problem is: All of the...
1
by: jjbutera | last post by:
There are a lot of examples out there, but I was hoping something could help me further. I'd like to draw text (unknown length) to an image, but then crop the image to the height and width of the...
10
by: Paul | last post by:
Hi, I was wondering if anyone knows if it is possible in C# given x,y coordinates of several straight lines to draw these on the screen and then save this as an image file, also adding text to the...
0
by: thirunavukarasukm | last post by:
Hai.... To print Html page using PrintDialog and Print Document i am created one windows appication.. the windows application have many pages in my booking page i have two buttons one...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.