Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Label / Form Resizing

Label / Form Resizing

Scheduled Pinned Locked Moved C#
questionhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    danielk_
    wrote on last edited by
    #1

    I have built a custom message box form (Windows form), on this form I have a label which displays a message that gets passed in to the message box. My question is how can I resize the label and form based on the text passed in? if a large block of text is passed in, the form and label need to resize to be able to show all the text and not just cut it off. thanks for help

    A L 2 Replies Last reply
    0
    • D danielk_

      I have built a custom message box form (Windows form), on this form I have a label which displays a message that gets passed in to the message box. My question is how can I resize the label and form based on the text passed in? if a large block of text is passed in, the form and label need to resize to be able to show all the text and not just cut it off. thanks for help

      A Offline
      A Offline
      Anthony Mushrow
      wrote on last edited by
      #2

      Check out this for measuring a string (in pixels) http://msdn2.microsoft.com/en-us/library/403ezxd2(VS.80).aspx[^] Just use MeasureString on your string, and it will return the width and height of the text, which you can then use to resize your label and form. Hopefully ;)

      My current favourite word is: Bacon!

      -SK Genius

      1 Reply Last reply
      0
      • D danielk_

        I have built a custom message box form (Windows form), on this form I have a label which displays a message that gets passed in to the message box. My question is how can I resize the label and form based on the text passed in? if a large block of text is passed in, the form and label need to resize to be able to show all the text and not just cut it off. thanks for help

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, set label.AutoSize true so the label grows and shrinks automatically, then set label.Text, now get label.Size and adapt form.Size accordingly. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups