|
-
Jan 7th, 2007, 03:21 PM
#1
Thread Starter
Junior Member
[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.
-
Jan 7th, 2007, 03:33 PM
#2
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"
-
Jan 7th, 2007, 03:53 PM
#3
Thread Starter
Junior Member
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.
-
Jan 7th, 2007, 04:05 PM
#4
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:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
e.Handled = True
End Sub
would set the 5th value in the combobox as the default
-
Jan 7th, 2007, 04:13 PM
#5
Thread Starter
Junior Member
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.
-
Jan 7th, 2007, 04:24 PM
#6
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:
Private Sub TextBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseClick
Label1.Select()
End Sub
Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
Label1.Select()
End Sub
And so on... although there is probably a better way.
Last edited by stimbo; Jan 7th, 2007 at 04:29 PM.
-
Jan 7th, 2007, 05:28 PM
#7
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
 
-
Jan 7th, 2007, 05:31 PM
#8
Thread Starter
Junior Member
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.
-
Jan 7th, 2007, 05:56 PM
#9
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.
-
Jan 7th, 2007, 07:05 PM
#10
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
 
-
Jan 7th, 2007, 08:23 PM
#11
Thread Starter
Junior Member
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.
-
Jan 7th, 2007, 08:33 PM
#12
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.
-
Jan 7th, 2007, 08:52 PM
#13
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|