fjkilken
asked on
MessageBox command format in C#
Hi
I have code which I have written in VBA which basically is callback methods to a custom Ribbon in Excel.
I am re-building the solution now in Visual Studio in C# (I'd preferto use VB but am not permitted)
I am trying to get my MessageBox to render the same way as in VBA code, but am unsure of the C# syntax/format.
Here is the code in VBA:
So it basically is a messagebox with the title = "File not opened"
the main text =
"An error occured when trying to open this file.
Please contact GRL-DS to advise of the issue." (note new line)
and the icon is an exclamation mark.
I have only got this far in C#:
Fergal
I have code which I have written in VBA which basically is callback methods to a custom Ribbon in Excel.
I am re-building the solution now in Visual Studio in C# (I'd preferto use VB but am not permitted)
I am trying to get my MessageBox to render the same way as in VBA code, but am unsure of the C# syntax/format.
Here is the code in VBA:
MsgBox "An error occured when trying to open this file." & vbCr & "Please contact GRL-DS to advise of the issue.", vbExclamation, "File not opened"
So it basically is a messagebox with the title = "File not opened"
the main text =
"An error occured when trying to open this file.
Please contact GRL-DS to advise of the issue." (note new line)
and the icon is an exclamation mark.
I have only got this far in C#:
MessageBox.Show("An error occured when trying to open this file.")
Thanks for your help!Fergal
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The other solutions I believe to be the correct ones. I just wanted to make a side comment that technically speaking "vbCR" is a carriage return, and carriage return in C# is just "\r". Environment.NewLine is equivalent whatever the system running the code uses to represent a newline, which on Windows is "\r\n"--carriage return-new line. So technically speaking you would simply replace your "vbCR" to "\r" to get a literal translation. But as I mentioned, I think the comments above are what you would want.
If you plan on porting your code to a non-windows system, such as through Mono, then use Environment.NewLine as EaswaranP suggests so it is sure to convert correctly.
Otherwise \r\n is usually more convenient as you can embed it directly in the string itself.
*Obviously this is a subjective statement and reflects my personal preference. =)
Otherwise \r\n is usually more convenient as you can embed it directly in the string itself.
*Obviously this is a subjective statement and reflects my personal preference. =)
ASKER
thanks for the info and advice
http://www.dotnetperls.com/newline