Click here to Skip to main content
15,920,217 members
Home / Discussions / C#
   

C#

 
AnswerRe: Threading Pin
Guffa5-Sep-05 7:42
Guffa5-Sep-05 7:42 
AnswerRe: Threading Pin
Andy Brummer5-Sep-05 8:59
sitebuilderAndy Brummer5-Sep-05 8:59 
Questionxml encoding Pin
mrnoname5-Sep-05 6:27
mrnoname5-Sep-05 6:27 
QuestionIntelligent Datagrid in C# Pin
| Muhammad Waqas Butt |5-Sep-05 6:09
professional| Muhammad Waqas Butt |5-Sep-05 6:09 
AnswerRe: Intelligent Datagrid in C# Pin
tolgattt5-Sep-05 10:35
tolgattt5-Sep-05 10:35 
GeneralRe: Intelligent Datagrid in C# Pin
| Muhammad Waqas Butt |6-Sep-05 22:49
professional| Muhammad Waqas Butt |6-Sep-05 22:49 
QuestionIntelligent Datagrid Pin
| Muhammad Waqas Butt |5-Sep-05 6:08
professional| Muhammad Waqas Butt |5-Sep-05 6:08 
QuestionUse MeasureDisplayStringWidth to Set Button.Width property Pin
ehollar5-Sep-05 5:46
ehollar5-Sep-05 5:46 
Greetings,

I am trying to get the pixel width of a string (using Windows forms default font) so that I can set the .Width property of a button as needed. I'm looking at this article:

http://www.codeproject.com/cs/media/measurestring.asp

But like many of the other responders I can't figure out how to call this thing. What I WOULD LIKE to do is simply have something like this:

private int iWidth;
iWidth = MeasureDisplayStringWidth("some string", Control.DefaultFont)
button1.Width = iWidth;

I cannot understand how to wire up a paint event and get back the int value out of the function in this article. I'm trying:

button1.Paint += new PaintEventHandler(button1_Paint);
...
private void button1_Paint(object sender, PaintEventArgs e)
{ MeasureDisplayStringWidth(e, ((Button sender).Text, Control.DefaultFont); }

this doesn't build and I can't figure out how to get the int value out of MeasureDisplayStringWidth.

Any tips would be appreciated. Thanks.


AnswerRe: Use MeasureDisplayStringWidth to Set Button.Width property Pin
ehollar5-Sep-05 12:26
ehollar5-Sep-05 12:26 
QuestionSystem.Data.NoNullAllowedException Pin
rich_wenger5-Sep-05 5:19
rich_wenger5-Sep-05 5:19 
QuestionRichtextBox Problem Pin
snouto5-Sep-05 5:07
snouto5-Sep-05 5:07 
AnswerRe: RichtextBox Problem Pin
philip_cole5-Sep-05 6:20
philip_cole5-Sep-05 6:20 
QuestionType casting issue Pin
arusmemon5-Sep-05 4:51
arusmemon5-Sep-05 4:51 
AnswerRe: Type casting issue Pin
Luis Alonso Ramos5-Sep-05 14:35
Luis Alonso Ramos5-Sep-05 14:35 
QuestionDate Time Picker MinMaxDate Pin
Greeky5-Sep-05 4:34
Greeky5-Sep-05 4:34 
AnswerRe: Date Time Picker MinMaxDate Pin
Luis Alonso Ramos5-Sep-05 7:22
Luis Alonso Ramos5-Sep-05 7:22 
QuestionThe weird control problem Pin
doph5-Sep-05 4:34
doph5-Sep-05 4:34 
QuestionDLL in C++ with pointers. How to use it in C#? Pin
patgo5-Sep-05 4:18
patgo5-Sep-05 4:18 
AnswerRe: DLL in C++ with pointers. How to use it in C#? Pin
RobVai6-Sep-05 16:37
RobVai6-Sep-05 16:37 
QuestionDelay during first use of Exception Pin
harwanegg5-Sep-05 3:28
harwanegg5-Sep-05 3:28 
AnswerRe: Delay during first use of Exception Pin
Andy Brummer5-Sep-05 4:12
sitebuilderAndy Brummer5-Sep-05 4:12 
AnswerRe: Delay during first use of Exception Pin
Daniel Turini5-Sep-05 6:38
Daniel Turini5-Sep-05 6:38 
GeneralRe: Delay during first use of Exception Pin
harwanegg5-Sep-05 20:21
harwanegg5-Sep-05 20:21 
QuestionT-SQL Clause Pin
Greeky5-Sep-05 3:18
Greeky5-Sep-05 3:18 
AnswerRe: T-SQL Clause Pin
Andy Brummer5-Sep-05 4:20
sitebuilderAndy Brummer5-Sep-05 4:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.