Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MessageBox command format in C#

Posted on 2013-02-01
5
Medium Priority
?
402 Views
Last Modified: 2013-02-01
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:

MsgBox "An error occured when trying to open this file." & vbCr & "Please contact GRL-DS to advise of the issue.", vbExclamation, "File not opened"

Open in new window


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.")

Open in new window

Thanks for your help!

Fergal
0
Comment
Question by:fjkilken
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 38843503
You could use Environment.NewLine instead of vbCr. Please do look at below one.

http://www.dotnetperls.com/newline
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 38843557
...so the whole thing can look like:
MessageBox.Show("An error occured when trying to open this file.\r\nPlease contact GRL-DS to advise of the issue.", "File not opened", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38843594
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.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 38843640
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.  =)
0
 

Author Closing Comment

by:fjkilken
ID: 38843722
thanks for the info and advice
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question