Windows Develop Bookmark and Share   
 index > Windows Forms General > Restricting window button from wrapping its text/caption
 

Restricting window button from wrapping its text/caption

Hi All,

Is there anyway to restrict the window button from wrapping its text/caption, if So then how do we do that

Thanks in advance

BipulKumar  Sunday, May 25, 2008 11:44 AM

You can subclass Button as follows to make Button text not wrap:

Code Snippet

public class NoWrapButton : Button

{

private const int BS_MULTILINE = 8192;

protected override CreateParams CreateParams

{

get

{

CreateParams p = base.CreateParams;

p.Style = p.Style & ~BS_MULTILINE;

return p;

}

}

}

For this to have effect, you need to set the FlatStyleproperty of the button toFlatStyle.System. That doesn't seem to affect the appearance on my Vista system.

BinaryCoder  Sunday, May 25, 2008 3:26 PM

Hi BipulKumar,

How is your problem going on now?

Based on my test, setting Button.AutoSize = false works great in my VS2008 using C#, both under the conditions that Button.Text added dynamically and Button.Font grew by design.

Hope it helps.

Please feel free to let me know how your problem is going on.

Thanks.

Best wishes,

Jun Wang

Jun Wang Tim  Friday, May 30, 2008 7:15 AM
What is a "window button"?
nobugz  Sunday, May 25, 2008 1:17 PM

You can subclass Button as follows to make Button text not wrap:

Code Snippet

public class NoWrapButton : Button

{

private const int BS_MULTILINE = 8192;

protected override CreateParams CreateParams

{

get

{

CreateParams p = base.CreateParams;

p.Style = p.Style & ~BS_MULTILINE;

return p;

}

}

}

For this to have effect, you need to set the FlatStyleproperty of the button toFlatStyle.System. That doesn't seem to affect the appearance on my Vista system.

BinaryCoder  Sunday, May 25, 2008 3:26 PM

Options:

A. Set AutoEllipsis = True

This will clip excess text and add"..." to the end of the displayable text.

B. Set AutoSize = True

The button will grow to fit the text within automatically.

C. Programmatically set the button's Font size to fit within the width of the button (shrink text instead of wrapping)

JayStation3  Monday, May 26, 2008 9:13 PM

Please find my comment inline

Options:

A. Set AutoEllipsis = True

This will clip excess text and add"..." to the end of the displayable text.

Will not work for the button having broad width and height

B. Set AutoSize = True

The button will grow to fit the text within automatically.

Will enlarge the button size and wont actually wrap the text

C. Programmatically set the button's Font size to fit within the width of the button (shrink text instead of wrapping)

Here we are compromising with the font size.

I am ok If some of the text/caption is getting out of the button size and getting invisible

Note: wellI am using .Net win-formand its button.

BipulKumar  Tuesday, May 27, 2008 3:13 PM

I was wondering if there is any property exposed to us by the button control in win-form in .Net 2005 to stop the text wrapping??

Or any work around ?

BipulKumar  Tuesday, May 27, 2008 3:17 PM

How about using the top and bottom padding values to allow only the first line of text to display? The text will still technically be wrapping, but won't be visible.

JayStation3  Tuesday, May 27, 2008 3:22 PM

Hi BipulKumar,

How is your problem going on now?

Based on my test, setting Button.AutoSize = false works great in my VS2008 using C#, both under the conditions that Button.Text added dynamically and Button.Font grew by design.

Hope it helps.

Please feel free to let me know how your problem is going on.

Thanks.

Best wishes,

Jun Wang

Jun Wang Tim  Friday, May 30, 2008 7:15 AM

You can use google to search for other answers

Custom Search

More Threads

• scrolling a custom control on a data panel
• Strange problem with TreeView images
• Controlling one form to another
• Settings: Select a Type Dialog Box
• VB2005 EE - Is there a Split Button ?
• Best way to implement different configs for different environments?
• Downloading data updates
• Passing TextBox to a method as an argument
• Login from winform to an aspx page
• Accessing PDF file properties in code