hi,
I've been using c# for a short time and there is a little thing a don't understand:
if I write this line (where outputLabel is a label in a form)
outputLabel.Text = "hi\teveryone";
the tab is not displayed correctly (there is not blank space, I see a strange character)
if I use \t in a messageBox as in:
MessageBox.Show("hi\teveryone");
everything is OK and I see: hi everyone
why I use visual C# espress edition)
thanks

escape \t
Mumose
with:
CharConverter b = new CharConverter();
label1.Text = "hi" + b.ConvertFrom("\t").ToString() + "Everyone";
the result is: hiEveryone with no spaces in it.
using the method
private void whitespace
is a good solution, but I don't understand why \t works well in MessageBox but doesn't in Label
JYP
Woods Barrack
Try this;
string a;
a = @"hi\teveryone";
By adding the @ symbol, you are telling the compiler to read the string literally instead of symbolically...
BrEnO_LEWROY
hi everyone
I'd like string being read symbolically. I'd like to see whitespaces instead of \t
\t works well on forms but not in labels
Mike_maul
I too do not think I would use an environmental variable - we are settings a Tab stop.
It just goes to show you that all of us use different methodology to achive the same results.
I thought of a different way to accomplish what you were attempting to do; Make your own control
make the control look for the \t in the text and when it reaches it add x amount of spaces. Where x is set by you when you call the control. If you have never made a control this would be a great learning project...
John Finney
>> but I don't understand why \t works well in MessageBox but doesn't in Label
Mainly because Tab doesn't mean "add some whitespace". It means "Move to the column of the next predefined tabstop". Labels do not have predefined tabstops, hence there no place to go.
wattlebee
Hello, You can Use Environment to set the Environment variable for tab. Then Using the GetEnvironmentVariable, u can emulate tabs in Labels
C#:Environment.SetEnvironmentVariable("tab"," ");
str = "Hello " + Environment.GetEnvironmentVariable("tab") + ".NET";
label1.Text = str;
.Net.Not
Are you doing this in forms or asp.net
you can also do this;
CharConverter
b = new CharConverter();label1.Text = "hi" + b.ConvertFrom("\t").ToString() + "Everyone";
The problem that I saw was in Windows forms, it add a box character in the label.
HTML, the tab character is - you would have to add the number of them you want, easily done with a loop. You can also add a loop in forms.
The problem that I see is there is no way to establish the number of white spaces you want simply by using the \t sequence
Maybe try this
protected
void Page_Load(object sender, EventArgs e){
Label1.Text = "hi";whitespace(3);
Label1.Text += "everyone";
}
private
void whitespace(int length) {}
Dominator Legend
MrHeo
I tried changing some of the control's attributes just to see what would happen...
Nada!! My best guess is the messagebox isn't a control. Thus it doesn't have an attribute that is causing the problem..
Good Luck!
Fyyre
set the textbox property Multiline to true and then try.
jeroen_nl
Please don't use b.ConvertFrom("\t").ToString(). It's the same as just "\t".
Alexey_
It appears like it is a limitation of the label control. If you switch the property "UseCompatibleTextRendering" to true then the character disappears but it does not display any whitespaces.
Perhaps you can use a text box.
Set MultiLine to true if you need to.
Set border to none
Set BackColor to Control.
Nobody will be any the wiser
Mark Cabaniss
Huh
This is just a long winded way of doing:
str = "Hello" + " " + ".NET";
or even simpler
str = "Hello .NET";
You definitely should NOT use an environment variable to define a tab replacement. What's wrong with a const string
private const string _tab = " ";
str = "Hello" + _tab + ".NET";