sfSystemMessageBox.cs
上传用户:lctyggxszx
上传日期:2022-06-30
资源大小:280k
文件大小:4k
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using AxShockwaveFlashObjects;
- using Mueller.Wddx;
- namespace SharpFlash
- {
- /// <summary>
- /// Summary description for sfSystemMessageBox.
- /// </summary>
- public class sfSystemMessageBox
- {
- private static WddxSerializer wddxSerializer = new WddxSerializer();
- private static WddxDeserializer wddDeserializer = new WddxDeserializer();
-
- //These libraries can be static for now.. depends on what their use is.
- public sfSystemMessageBox() {
-
- }
- //Handles any command.. Will exist for any library. Main library loop
- public static void Command(Form form, AxShockwaveFlash flashApp, string list, String method) {
- switch(method) {
- case "messageBox":
- sfSystemMessageBox.messageBox(form, flashApp, list);
- break;
- }
- }
- //Method in library. Can pick and choose what to pass in if you want.
- public static void messageBox(Form form, AxShockwaveFlash flashApp, string list) {
-
- MessageBoxButtons mbb;
- MessageBoxIcon mbi;
- MessageBoxDefaultButton mbd;
- //MessageBoxOptions mbo;
-
- System.Collections.Hashtable args = (System.Collections.Hashtable)wddDeserializer.Deserialize(list);
-
- string text = (string)args["text"];
- string caption = (string)args["caption"];
- int buttons = (int)args["buttons"];
- int icon = (int)args["icon"];
- int defaultButton = (int)args["defaultButton"];
- //int options = (int)args["options"];
- try
- {
- mbb = getMessageBoxButtonsFromInt(buttons);
- mbi = getMessageBoxIconFromInt(icon);
- mbd = getMessageBoxDefaultButtonFromInt(defaultButton);
- //mbo = getMessageBoxOptionsFromInt(options);
- }
- catch (ArgumentException ae)
- {
- //MessageBox.Show(ae.Message, "Exception");
-
- flashApp.SetVariable("$SFData", "<sf><callback><id>" + list + "</id>"
- + "<args>"
- + "<arg>" + wddxSerializer.Serialize(false).ToString() + "</arg>"
- + "<arg>" + wddxSerializer.Serialize(ae.Message).ToString() + "</arg>"
- + "</args></callback></sf>");
- return;
- }
-
-
- DialogResult result = MessageBox.Show(text, caption, mbb, mbi, mbd/*, mbo*/);
-
- flashApp.SetVariable("$SFData", "<sf><callback><id>" + (string)args["callback_id"] + "</id>"
- + "<args>"
- + "<arg>" + wddxSerializer.Serialize(result.ToString()).ToString() + "</arg>"
- + "</args></callback></sf>");
-
- }
- private static MessageBoxButtons getMessageBoxButtonsFromInt(int buttons)
- {
- MessageBoxButtons mbb;
-
- switch(buttons)
- {
- case 1: mbb = MessageBoxButtons.AbortRetryIgnore; break;
- case 2: mbb = MessageBoxButtons.OK; break;
- case 3: mbb = MessageBoxButtons.OKCancel; break;
- case 4: mbb = MessageBoxButtons.RetryCancel; break;
- case 5: mbb = MessageBoxButtons.YesNo; break;
- case 6: mbb = MessageBoxButtons.YesNoCancel; break;
- default: throw new ArgumentException("Invalid button type");
- }
- return mbb;
- }
- private static MessageBoxIcon getMessageBoxIconFromInt(int icon)
- {
- MessageBoxIcon mbi;
-
- switch(icon)
- {
- case 1: mbi = MessageBoxIcon.Asterisk; break;
- case 2: mbi = MessageBoxIcon.Error; break;
- case 3: mbi = MessageBoxIcon.Exclamation; break;
- case 4: mbi = MessageBoxIcon.Hand; break;
- case 5: mbi = MessageBoxIcon.Information; break;
- case 6: mbi = MessageBoxIcon.None; break;
- case 7: mbi = MessageBoxIcon.Question; break;
- case 8: mbi = MessageBoxIcon.Stop; break;
- case 9: mbi = MessageBoxIcon.Warning; break;
- default: throw new ArgumentException("Invalid icon type");
- }
- return mbi;
- }
- private static MessageBoxDefaultButton getMessageBoxDefaultButtonFromInt(int buttons)
- {
- MessageBoxDefaultButton mbd;
-
- switch(buttons)
- {
- case 1: mbd = MessageBoxDefaultButton.Button1; break;
- case 2: mbd = MessageBoxDefaultButton.Button2; break;
- case 3: mbd = MessageBoxDefaultButton.Button3; break;
- default: throw new ArgumentException("Invalid default button type");
- }
- return mbd;
- }
- }
- }