Advertisement
filmee24

xmlTheme

Oct 4th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1.     public class XmlTheme
  2.     {
  3.  
  4.         internal protected XDocument Xdoc;
  5.         public Form Window = new Form();
  6.         public Jint.JintEngine JScript = new Jint.JintEngine();
  7.         public string JScriptSource;
  8.  
  9.         public static XmlTheme FromText(string text)
  10.         {
  11.             var theme = new XmlTheme {Xdoc = XDocument.Parse(text)};
  12.  
  13.             foreach (var doc in theme.Xdoc.Descendants("theme").Elements("item"))
  14.             {
  15.                 var type = typeof(Form).Assembly.CreateInstance(doc.Attribute("type").Value) as Control;
  16.  
  17.                 type.Name = doc.Attribute("name").Value;
  18.  
  19.                 (type as Control).BackColor = Color.Transparent;
  20.  
  21.                
  22.                 theme.JScript.AddPermission(new System.Security.Permissions.UIPermission(System.Security.Permissions.PermissionState.Unrestricted));
  23.  
  24.                 theme.JScript.SetFunction("alert", new Action<string>(m => MessageBox.Show(m)));
  25.  
  26.                 theme.Window.Controls.Add(type);
  27.                 theme.JScriptSource = doc.Value;
  28.             }
  29.  
  30.             return theme;
  31.         }
  32.  
  33.         public static XmlTheme FromFile(string filename)
  34.         {
  35.             return FromText(File.ReadAllText(filename));
  36.         }
  37.  
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement