|
-
Sep 30th, 2008, 04:24 AM
#1
Thread Starter
Junior Member
[RESOLVED] Message box with two lines
Hi there
I need one message box with two lines. How can i do that?
Thank you
-
Sep 30th, 2008, 05:36 AM
#2
Re: Message box with two lines
-
Sep 30th, 2008, 06:35 AM
#3
Re: Message box with two lines
Code:
MessageBox.Show("First line." & ControlChars.NewLine & "Second line.")
-
Sep 30th, 2008, 06:38 AM
#4
Re: Message box with two lines
Code:
MessageBox.Show("This" & Environment.NewLine & "is" & Environment.NewLine & "a test", "Lines", MessageBoxButtons.YesNoCancel)
-
Sep 30th, 2008, 10:06 AM
#5
Re: Message box with two lines
Hi,
This is another way to do it;
vb Code:
MessageBox.Show("This is your fist line," & vbNewLine & "this your second line.")
This is also working like the others but what's the difference between all three!
Wkr,
sparrow1
-
Sep 30th, 2008, 10:12 AM
#6
Re: Message box with two lines
 Originally Posted by sparrow1
Hi,
This is another way to do it;
vb Code:
MessageBox.Show("This is your fist line," & vbNewLine & "this your second line.")
This is also working like the others but what's the difference between all three!
Wkr,
sparrow1
http://msdn.microsoft.com/en-us/libr...h0(VS.80).aspx
-
Sep 30th, 2008, 11:58 AM
#7
Frenzied Member
Re: Message box with two lines
 Originally Posted by JuggaloBrotha
Is vbNewLine the same as vbCrLf? I always use the latter. According to that link they are both Chr(13)+Chr(10). Just wondering why there are two constants for the same thing...
-
Sep 30th, 2008, 12:20 PM
#8
Re: Message box with two lines
-
Sep 30th, 2008, 12:43 PM
#9
Re: Message box with two lines
 Originally Posted by nbrege
Is vbNewLine the same as vbCrLf? I always use the latter. According to that link they are both Chr(13)+Chr(10). Just wondering why there are two constants for the same thing...
Don't use either, use Environment.NewLine instead.
-
Sep 30th, 2008, 01:58 PM
#10
Junior Member
Re: Message box with two lines
Juggalo ... why ?
I have always used vbCrLF (chr(13) + chr(10)) so I am just wondering what the percieved advantage of Environment.NewLine is, from what I can tell with the following code
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim lString As String = ""
For Each l As Char In Environment.NewLine
lString += "," & Asc(l)
Next
MsgBox(lString)
End Sub
Environment.Newline just returns chrs 13 and 10 (although this may change on other machines I suppose)
-
Sep 30th, 2008, 02:16 PM
#11
Re: Message box with two lines
 Originally Posted by SpaceMonkeys
Juggalo ... why ?
The environment class is there to allow you to use things based on the environment (the OS) that your app is running on. For instance, ControlChars.NewLine, vbNewLine, vbCrLf, vbLf should all fail in your .Net applications when it's running on Mono (Linux/Mac) because all you need is the Cr (Carrage Return) and not the Lf (Line Feed) for a new line, whereas in windows it uses both Cr and Lf for a new line. So on Windows Environment.NewLine gives you the CrLf combination whereas the same Environment.NewLine on Mono gives you just the Cr.
In short, Environment.NewLine reduces the need to check for what OS your app is running on because that's already defined in the Environment class.
And a quote from MSDN:
Property Value
Type: System.String
A string containing "\r\n" for non-Unix platforms,
or
a string containing "\n" for Unix platforms.
http://msdn.microsoft.com/en-us/libr...t.newline.aspx
-
Sep 30th, 2008, 02:20 PM
#12
Frenzied Member
Re: Message box with two lines
Juggalo ... makes perfect sense. But if we only develope Windows apps then it shouldn't make a difference one way or the other, right?
-
Sep 30th, 2008, 02:30 PM
#13
Junior Member
Re: Message box with two lines
Cool, that's what I though you were going to say (coming from a C++ background) just wanted to be sure, if your going to be developing windows only apps yeah either will be fine .... but good practice is good practice
-
Sep 30th, 2008, 02:32 PM
#14
Re: Message box with two lines
 Originally Posted by nbrege
Juggalo ... makes perfect sense. But if we only develope Windows apps then it shouldn't make a difference one way or the other, right?
Yes, but what if you're suddenly told by your boss that your app is going to be modified to run on Mono as well as Windows and tells you to make the changes by the end of the week, would you want to spend a day or more changing all of the vbCrLf's and vbNewLine's and ControlChar.Newline's to Environment.NewLine?
I wouldn't.
-
Sep 30th, 2008, 02:43 PM
#15
Re: Message box with two lines
I personally have a shared routine that I include in every app I work on called NL
It looks like this:
Code:
Public Shared Function NL(Optional ByVal Count As Integer = 1) As String
'HOLDS OUR NEWLINES
Dim temp As String = String.Empty
'IF USER PASSED IN NEGATIVE OR 0, MAKE 1
If Count < 1 Then Count = 1
'LOOP TO MAKE AS MANY NEW LINES AS WE WANT
For i As Integer = 1 To Count
temp &= Environment.NewLine
Next
'RETURN VALUE
Return temp
End Function
It is usually sitting in a module in a linked file to my project so it is easy to reuse. You could also put it in a class and reference it as a DLL though with other support functions you may make and use frequently in many projects.
Anyway, the reason I made a function, is because then when I want a newline all I have to type is NL
Code:
Dim x as string = "Hello" & NL & "World"
'Result:
'Hello
'World
But if I want 2 blank lines, I can also do
Code:
Dim x as string = "Hello" & NL(2) & "World"
'Result:
'Hello
'
'World
etc....
Since the param is optional, it defaults to 1 line when you don't pass an argument. It also would make this very easy to change if I decided for some reason I did want to use vbCrLf or something like that instead of Environment.NewLine (or maybe I want to change to use a stringbuilder object instead of a temp string variable to build my newlines). If I ever did want to change the functionality, I could just change it in the function, and not have to update it in 50 million spots in my app.
-
Sep 30th, 2008, 02:45 PM
#16
Re: Message box with two lines
oh, and just one additional comment. I noticed when I had formatted some messages for a messagebox to be multiline, and it looked fine on XP, I noticed the same messagebox would actually have line breaks in different spots on Vista.
I guess they changed the text area of messageboxes in vista, with relation to the width a messagebox will get to based on its text before it forces a newline. So if you format your messageboxes with newlines to look all nice in 1 OS, it may look like crap in another, so make sure to test.
-
Sep 30th, 2008, 02:57 PM
#17
Frenzied Member
Re: Message box with two lines
 Originally Posted by kleinma
Code:
Public Shared Function NL(Optional ByVal Count As Integer = 1) As String
...snip
For i As Integer = 1 To Count
temp &= Environment.NewLine
Next
...snip
Instead of a loop you could use this:
Code:
temp = StrDup(Count, Environment.NewLine)
It might be a little more efficient. Or maybe not. Nice routine BTW...
Last edited by nbrege; Sep 30th, 2008 at 03:01 PM.
-
Sep 30th, 2008, 03:03 PM
#18
Re: Message box with two lines
StrDup duplicates the first character in a string, so I have not tested, as I don't use it, but environment.newline is a cr and lf as stated above for Windows machines, so there is a good change using StrDup would return ONLY a string of CR characters, and no LF characters.
From Help:
StrDup
This function returns a String made up of repeated characters. The character that makes up the string is the first character in the Character argument, and it is duplicated Number number of times.
Code:
Dim aString As String = "Wow! What a string!"
' Returns "WWWWWWWWWW"
TestString = StrDup(10, aString)
-
Sep 30th, 2008, 03:05 PM
#19
Frenzied Member
Re: Message box with two lines
Oops .. my bad. I should have tested before posting.
-
Oct 1st, 2008, 01:13 AM
#20
Re: Message box with two lines
Hi All,
Thanks for the explanations, I'll use it in the future.
Wkr,
sparrow1
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
|