c# - cannot convert from 'string' to 'System.Windows.Forms.MessageBoxIcon -
i'm working on piece of software lets generate own customized messagebox
. code has no errors until try , put in messageboxbuttons , messageboxicon
. then, error
2 argument 3: cannot convert 'string' 'system.windows.forms.messageboxbuttons' , error 3 argument 4: cannot convert 'string' 'system.windows.forms.messageboxicon'. issue here?
if (textboxx1.text == string.empty) messagebox.show("you must enter title."); else if (richtextboxex1.text == string.empty) messagebox.show("you must enter body."); else { string previewtype = string.empty; string previewbutton = string.empty; if (radiobutton1.checked == true) previewtype = "messageboxicon.error"; else if (radiobutton2.checked == true) previewtype = "messageboxicon.information"; else if (radiobutton3.checked == true) previewtype = "messageboxicon.exclamation"; else if (radiobutton4.checked == true) previewtype = "messageboxicon.question"; if (radiobutton8.checked == true) previewbutton = "messageboxbuttons.abortretryignore"; else if (radiobutton7.checked == true) previewbutton = "messageboxbuttons.ok"; else if (radiobutton6.checked == true) previewbutton = "messageboxbuttons.okcancel"; else if (radiobutton5.checked == true) previewbutton = "messageboxbuttons.retrycancel"; else if (radiobutton9.checked == true) previewbutton = "messageboxbuttons.yesno"; else if (radiobutton10.checked == true) previewbutton = "messageboxbuttons.yesnocancel"; messagebox.show(textboxx1.text, richtextboxex1.text, previewbutton, previewtype); }
the error because you're passing strings messagebox.show(), should passing messageboxbuttons , messageboxicon. in other words, cannot this:
messagebox.show("some text", "a caption", "messageboxbuttons.abortretryignore", "messageboxicon.error");
but can this:
messagebox.show("some text", "a caption", messageboxbuttons.abortretryignore, messageboxicon.error);
your previewtype , previewbutton variables should defined actual types, not strings:
messageboxicon previewtype; messageboxbuttons previewbutton;
if update sample use correct data types, looks this:
if (textboxx1.text == string.empty) messagebox.show("you must enter title."); else if (richtextboxex1.text == string.empty) messagebox.show("you must enter body."); else { messageboxicon previewtype; messageboxbuttons previewbutton; if (radiobutton1.checked == true) previewtype = messageboxicon.error; else if (radiobutton2.checked == true) previewtype = messageboxicon.information; else if (radiobutton3.checked == true) previewtype = messageboxicon.exclamation; else if (radiobutton4.checked == true) previewtype = messageboxicon.question; if (radiobutton8.checked == true) previewbutton = messageboxbuttons.abortretryignore; else if (radiobutton7.checked == true) previewbutton = messageboxbuttons.ok; else if (radiobutton6.checked == true) previewbutton = messageboxbuttons.okcancel; else if (radiobutton5.checked == true) previewbutton = messageboxbuttons.retrycancel; else if (radiobutton9.checked == true) previewbutton = messageboxbuttons.yesno; else if (radiobutton10.checked == true) previewbutton = messageboxbuttons.yesnocancel; messagebox.show(textboxx1.text, richtextboxex1.text, previewbutton, previewtype);
Comments
Post a Comment