Click here to Skip to main content
15,886,069 members
Please Sign up or sign in to vote.
3.40/5 (2 votes)
See more:
http://i.stack.imgur.com/YlIrR.png[^]


the above image is of label created dyanamic on runtime.
text on label is from database
if i add text by right click on label the text is apended on label

NAME: Rahul Roy
Kadam

not like above label
Posted
Updated 27-May-16 1:34am
v2
Comments
José Amílcar Casimiro 19-Apr-13 6:39am    
what's your question?
Omkaara 19-Apr-13 6:53am    
the text on label present is "Rahul Roy
Kadam"
i right click it and appends the "NAME"

i want my text in label to appear as same as in image
like

NAME: Rahul Roy
Kadam


but is appears as

NAME: Rahul Roy
Kadam

the label is dyanamically created on runtime
José Amílcar Casimiro 19-Apr-13 6:58am    
Justify your text into the right.
ZurdoDev 19-Apr-13 7:50am    
You need to apply formatting to get it to look the way you want.
Omkaara 19-Apr-13 9:01am    
how to do that please ellaborate

1 solution

It's hard to give good advice when you don't post the code you are currently using to fill the text of the label. If your database stores first, middle, and last names seperately then when you put the text in the label, include a newline after the middle name. Then a tab and/or the number of spaces that would move the last name over to where the end of "NAME:" is, and then append the last name.

use vbNewLine[^] or vbCRLF[^] (which stands for carriage return line feed).

I assume it would look something like this:

VB
lblYourLabel.Text = "NAME: " & Trim(strFirstName & " " & strMiddleName) & vbNewLine & "     " & strLastName
 
Share this answer
 
Comments
Omkaara 20-Apr-13 2:31am    
actully code is so vast thts y i cant share my code
actully every thing is dynamically done using add handler
Omkaara 20-Apr-13 2:36am    
no the whole name is in one field itself
on rightclick mouse event i am calling input box in which i enter the text;
that particular text appends the existing label text as a prefix
since its dyanamic i can change heigt and widht of label at runtime
so the text of label i want to format which will look like
prefix : value from
database
Kschuler 22-Apr-13 9:35am    
If you can assume that the last name doesn't have a space in it, you could split the input and then use the code I've posted above. Other than that, I think right justifying as these others have suggested is your best bet. There is no other way to get it to understand how you want your formatting. I don't know how you could set margins or indents in label the way you can in a word processing program like Microsoft Word. However, it appears a RichTextBox control can. If you could use that and put it in read only mode instead of a label, perhaps that would work. See MSDN:
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.selectionhangingindent(v=vs.90).aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900