Results 1 to 13 of 13

Thread: [2005] Multiline Label

  1. #1

    Thread Starter
    Junior Member Aabra's Avatar
    Join Date
    Jan 2007
    Posts
    23

    [2005] Multiline Label

    Hey, I apologize for this rather basic question but I can't seem to figure out how to create a multiline label that wraps text.

    I tried creating a textbox and disabling it, but the text gets grayed out when I do that.

    While I'm asking the incredibly embarrassing basic questions I also can't seem to figure out how to make a combobox that you can't type in. I just want a simple drop down box.... like the ones for font, size, and color that we have when we post here.

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Multiline Label

    You change the combobox dropdownstyle to DropDownList so that it wont change.

    As for the label, do you mean having a multi-line label?


    Label1.Text = "Hello" & Environment.NewLine & "World"
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  3. #3

    Thread Starter
    Junior Member Aabra's Avatar
    Join Date
    Jan 2007
    Posts
    23

    Re: [2005] Multiline Label

    Thanks - couple minor things though.

    Environment.NewLine isn't exactly what I'm looking for as I'm not sure how long the text will be. What I'd really like is to be able to define the complete area like a textbox, and have word wrap enabled so that the text wraps around. I do not however want the user to be able to edit that text. It's just a label really.

    As for the combo box. Thanks a bunch! That's exactly what I want. How do I set the default value though? I can't seem to find that property.

  4. #4
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Multiline Label

    You can define the combobox index by code only I think. On form load for example you could put this:

    ComboBox1.SelectedIndex = 4

    I'm not sure about the label. If you want to stop the input from a user on a textbox you could add this code and stop user input:

    VB Code:
    1. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
    2.         e.Handled = True
    3.     End Sub




    would set the 5th value in the combobox as the default
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  5. #5

    Thread Starter
    Junior Member Aabra's Avatar
    Join Date
    Jan 2007
    Posts
    23

    Re: [2005] Multiline Label

    Awesome - that's working great. Thanks a ton. That code for the Textbox is working. Is there something similar you can do to disable mouseclicks? Right now you can still click in there, highlight the text etc which is a bit goofy.

  6. #6
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Multiline Label

    I'm silly, the textbox control has a ReadOnly property which you could change to True.

    That way you wouldn't have to add any code. Although having just tried it, it also allows the mouse to select text.

    There's probably an easier way but you could add code for stopping mouse click by setting focus to a label instead.

    So, if you have a control like a label that doesn't do anything you could write:

    VB Code:
    1. Private Sub TextBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseClick
    2.         Label1.Select()
    3.     End Sub
    4.  
    5. Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
    6.         Label1.Select()
    7.     End Sub


    And so on... although there is probably a better way.
    Last edited by stimbo; Jan 7th, 2007 at 04:29 PM.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2005] Multiline Label

    If you are going to use a textboxt to simulate a label, you should keep it from looking like a textbox. Nothing is more annoying than a textbox that you can't touch. You can make the textbox look like a label by adjusting the backcolor and the style. I think the 2D, flat, or borderless (or something like that) style would appear the same as a label.

    I can't remember a lable that wasn't automatically multi-line if it was created big enough to hold multiple lines. Has that changed? I guess I haven't tried that recently, but I'd be surprised if that was taken away.
    My usual boring signature: Nothing

  8. #8

    Thread Starter
    Junior Member Aabra's Avatar
    Join Date
    Jan 2007
    Posts
    23

    Re: [2005] Multiline Label

    I already changed the color/border etc to match the background. It doesn't look like a textbox at all. It's a bit goofy that you can highlight the text in it and if you click on it a little curser will start blinking, but 99% of the time I don't think a user will try to do that. Nor does it really affect the program if they do.

    Edit: I forgot to mention that unfortunately that mouse code doesn't seem to work. It's ok though - I can live with it in its current state.

  9. #9
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Multiline Label

    I've just checked again and the mouse code does work.

    Did you try it with the MouseDown event on the textbox?

    I added that after the initial post.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2005] Multiline Label

    Haven't been able to test 2005, but I have tested 2003, and labels all automatically wrap text. Has that changed in 2005?
    My usual boring signature: Nothing

  11. #11

    Thread Starter
    Junior Member Aabra's Avatar
    Join Date
    Jan 2007
    Posts
    23

    Re: [2005] Multiline Label

    Well I can't test it with 2003 as I don't have it but in 2005 - they don't wrap.

    Edit: Stimbo - thx for all the help. It didn't look like it worked because I changed the label1 to textbox1... which needless to say didn't work. I switched it to ok_button.select() and now it's working great.
    Last edited by Aabra; Jan 7th, 2007 at 08:26 PM.

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Multiline Label

    Labels DO wrap in 2005. The AutoSize property is True by default, so if you add more text then the Label will grow to accommodate it. Set the AutoSize property to False and the text will wrap if it is too long to fit the current Width.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13

    Thread Starter
    Junior Member Aabra's Avatar
    Join Date
    Jan 2007
    Posts
    23

    Re: [2005] Multiline Label

    LOL Well.... all that work for nothing. Thanks for the info jm.

Posting Permissions

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



Click Here to Expand Forum to Full Width