Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 21st, 2007, 11:38 AM
Authorized User
 
Join Date: Feb 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to count Pixels

Hi All,

I am adding a string value to listbox control. I need to set the width of listbox in runtime base on how many pixels string need it to display it within listbox. Idea is to set a width of listbox exactly the number of pixels required by string value. So, I can have perfect width each time base on string value.
Any idea please help.

Thanks,

Asif.

A.Asif
__________________
A.Asif
 
Old November 26th, 2007, 05:28 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

[Assuming you are talking WinForms and not ASP.Net]

You can use the Graphics.MeasureString to get the width of a text string in a given font. There will be some 'excess' pixels needed for the sides of the listbox control itself.

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting pixels shanthi85 VB How-To 0 May 22nd, 2007 02:13 AM
what is best way to determine pixels of pic audi Dreamweaver (all versions) 4 January 1st, 2006 09:20 AM
get size (W x H, pixels) of .swf archive ACE2084 Javascript How-To 0 April 27th, 2005 11:32 AM
get size (W x H, pixels) of .swf archive ACE2084 ASP.NET 1.0 and 1.1 Basics 1 April 26th, 2005 04:34 PM
Inches 2 Pixels Conversion ejan Pro VB 6 3 October 20th, 2004 04:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.