dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Add new line to the text in a button

  1. #1
    Join Date
    Mar 2010
    Posts
    12

    Add new line to the text in a button

    Hi folks,

    The text I have in a button is too long and I wish to have it in 2 lines. How can I get the text in a button to the next line. Can anyone please help me with this ? I am using VS2008 and .NET 3.5.

    Any help is appreciated. Thank you

  2. #2
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: Add new line to the text in a button

    Code:
          
      private void button1_Click(object sender, EventArgs e)
            {
                button1.Text = "line1\nline2";
            }
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  3. #3
    Join Date
    Mar 2010
    Posts
    12

    Re: Add new line to the text in a button

    Hi Toraj,

    I already tried that but only the first line gets printed. I do not know the reason for that. I also tried drawString method but the button covers the text. I do not know how to print the text over the button.

    Thank you

  4. #4
    Join Date
    Dec 2009
    Posts
    34

    Re: Add new line to the text in a button

    have you tried \n and enlarged the Y size of it ?

  5. #5
    Join Date
    Mar 2010
    Posts
    12

    Re: Add new line to the text in a button

    Yep, I increased the Y size of the button but nothing changed. I can see just the first line.

  6. #6
    Join Date
    Mar 2007
    Posts
    90

    Re: Add new line to the text in a button

    Did you try adding the height of the button font?
    Code:
    button1.Height += button1.Font.Height;

  7. #7
    Join Date
    Dec 2009
    Posts
    34

    Re: Add new line to the text in a button

    Ok, i made a simple test on my VS2008...

    When i made the button and enlarged it's vertical size and then typed what i wanted it did broke to new lines when it reached the end.

    but if you create a new button and try to alter it's text it won't work.

    So what i did to make it fit was:

    Code:
    button1.Height = 70;
                button1.Text = "Trying to make the text fits into the button.";
    since with 70px i was sure all that text would fit in.

    someuser77 method also works but if u have a big text it won't show up everything at once...

  8. #8
    Join Date
    Mar 2007
    Posts
    90

    Re: Add new line to the text in a button

    What about setting the button AutoSize property to true? Do you need to limit the button width?

  9. #9
    Join Date
    Mar 2010
    Posts
    12

    Re: Add new line to the text in a button

    Hi someuser77, prixone

    I tried both the method you mentioned and nothing worked. I did set the size of the button and also the button size + font size but got the same result. Please, let me know if there is any fix. Actually I am developing an application for smart phone and may be that's the reason I do not find autosize property for button.

    Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)