Hi All,
Im new to C# and having an issue with MessageBoxIcon.
I am trying to use the same piece of code to show a message box which will need to display the appropriate icon ie error or exclamation etc.
In the example below, you can see that the icon name is hard coded as "Exclamation". What I would like to do is use the variable "str3" to tell the MessageBox which icon to display. Is this possible?
using System;
using System.Text;
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
[assembly: CommandClass(typeof(Autodesk.AutoCAD.MsgBox.STDLMessageBox))]
namespace Autodesk.AutoCAD.MsgBox
{
public class STDLMessageBox
{
[LispFunction("ConcatStrings")]
static public string ConcatStrings(ResultBuffer args)
{
Array ArgsArray = args.AsArray();
string str1 = Convert.ToString(((TypedValue)(ArgsArray.GetValue(0))).Value);
string str2 = Convert.ToString(((TypedValue)(ArgsArray.GetValue(1))).Value);
string str3 = Convert.ToString(((TypedValue)(ArgsArray.GetValue(2))).Value);
MessageBox.Show(str1, str2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return null;
}
}
}
Loading

Danatas GerviRank #4,152 · 361 reputationPosted Oct 29, 2009, 2:56 AM EDT
use this:
MessageBoxIcon iconParsed = (MessageBoxIcon)Enum.Parse(typeof(MessageBoxIcon), str3);
theLizardRank #1,079 · 1.8K reputationPosted Oct 29, 2009, 1:21 AM EDT
switch(option)
{
case 1:
MessageBoxIcon.Exclamation;
break;
}
MessageBox.Show("Hello", "there", MessageBoxButtons.OK, icon);
theLizardRank #1,079 · 1.8K reputationPosted Oct 29, 2009, 1:21 AM EDT
switch(option)
{
case 1:
icon = MessageBoxIcon.Exclamation;
break;
}
MessageBox.Show("Hello", "there", MessageBoxButtons.OK, icon);
naura paxRank #2,843 · 502 reputationPosted Oct 29, 2009, 1:31 AM EDT
pardon me this is just a vague attempt - you can create your own type and use it in application eg. I have not tested it yet (you can have standard if-else construct otherwise).
public class MessageType: EnumBaseType { public static readonly MessageType None= new Rating(0, "None"); public static readonly MessageType SomeError= new Rating(16, "SomeError"); public static readonly MessageType Surprise= new Rating(48, "Surprise");//For exclamation // and so on. public MessageType(int key, string value) : base(key, value) { } public static ReadOnlyCollection GetValues() { return GetBaseValues(); } public static MessageTypeGetByKey(int key) { return GetBaseByKey(key); }Steve Rudd3 reputationPosted Oct 29, 2009, 2:09 AM EDT