Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hard coding text in a textbox. How can I accomplish this.

Status
Not open for further replies.

RotorTorque

Programmer
Joined
Apr 29, 2007
Messages
100
Location
US
Hi all,
I have a VB2005 app that uses a multiline textbox. I want the first line in the textbox to be hardcoded and give the user's the ability to edit all other lines. The user's should not be able to delete or modify this first line. How can I acccomplish this?

Thanks in advance,
RotorTorque :-)
 
I wouldn't use that method myself. I would put a label right above the textbox on the form that holds the "text". If this "text" needs to be added to an output or somesuch, then just join the two during the output process -
Me.Label1.Text & " " & Me.TextBox1.Text

BUT...if your setup really is necessary, you could possibly make use of the length property of the textbox. Since you have the "block" of text at the top of your textbox, you probably know the length. Using the TextChanged property of the textbox, check to see if the length of the textbox is less than or equal to the length of the set text. If it is, reset the text to that text. You also might want to give the users a prompt, as I would find this behavior quite bizzare. Finally, I would also include some code (or maybe there is a property - I don't remember) that forces the cursor to always go to the end of the text when you enter that textbox. That way the users don't begin with overwrite as is default.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
Thanks mstrmage1768,
I will use your suggestion.

RotorTorque :-)
 
If they do not have to see the text, but you need it for something eles I would suggest just adding it to the begining of the text before you use it. You could use two textboxes, have the edges meet, and make the first textbox uneditable.

-I hate Microsoft!
-Forever and always forward.
 
Thank you Sorwen for your suggestion.


RotorTorque :-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top