public static DialogResult Show(string text) { if (ThemeKit.forms.Count == 0) { return(MessageBox.Show(text)); } ThemeForm form = new ThemeForm(); form.Text = "Message"; form.Theme = ThemeKit.forms[0].Theme; form.Style = "MessageBox"; form.FormBorderStyle = FormBorderStyle.FixedSingle; form.StartPosition = FormStartPosition.CenterParent; form.MinimizeBox = false; form.MaximizeBox = false; ThemeLabel lbl = new ThemeLabel(); lbl.Text = text; lbl.Left = 10; lbl.Top = 10; lbl.Visible = true; lbl.AutoSize = true; form.Controls.Add(lbl); lbl.Style = "MessageBox"; ThemeButton btn = new ThemeButton(); btn.Text = "OK"; btn.Tag = DialogResult.OK; btn.Click += new EventHandler(btn_Click); btn.Visible = true; form.Controls.Add(btn); btn.Style = "MessageBox"; form.ClientSize = new Size(lbl.Width + 20, lbl.Height + 20 + btn.Height + 10); btn.Top = form.ClientSize.Height - btn.Height - 10; btn.Left = form.ClientSize.Width - btn.Width - 10; form.ShowDialog(); return(DialogResult.OK); }
public ThemeStyleSelector(Control Control, string Value, IWindowsFormsEditorService Editor) { editorService = Editor; Dictionary <string, object> d = null; ThemeForm frm = null; if (Control is ThemeForm) { frm = (ThemeForm)Control; } else if (Control is ThemeControl) { frm = ((ThemeControl)Control).Form; } else if (Control is ThemeContainerControl) { frm = ((ThemeContainerControl)Control).Form; } if (frm == null) { this.Items.Add("Unable to Find ThemeForm"); return; } if (frm.controlstyledictionaries.ContainsKey(Control.GetType())) { d = frm.controlstyledictionaries[Control.GetType()]; } if (d != null) { foreach (string s in d.Keys) { this.Items.Add(s); } } this.Value = Value; }
/// <param name="form">The form the Theme will act upon</param> /// <param name="Theme">The theme file as a byte array</param> public Theme(ThemeForm form, byte[] Theme) { files = new Dictionary <string, Stream>(); if (form.controlstyledictionaries == null || form.controlstyledictionaries.Count > 0) { form.controlstyledictionaries = new Dictionary <Type, Dictionary <string, object> >(); } Type[] types = Assembly.GetExecutingAssembly().GetTypes(); foreach (Type type in types) { object[] atts = type.GetCustomAttributes(typeof(ThemeKitControl), false); if (atts.Length == 1) { ThemeKitControl att = (ThemeKitControl)atts[0]; Dictionary <string, object> d = new Dictionary <string, object>(); if (Theme.Length == 0) { object o = Activator.CreateInstance(att.ElementsType); FieldInfo[] fields = att.ElementsType.GetFields(); foreach (FieldInfo field in fields) { if (field.FieldType == typeof(ExBrush[])) { field.SetValue(o, new ExBrush[] { new ExBrush() }); } } d.Add("Default", o); } form.controlstyledictionaries.Add(type, d); } } if (Theme.Length == 0) { return; } MemoryStream themexml = null; if ((char)Theme[0] == '<') { themexml = new MemoryStream(Theme); } else { MemoryStream themestream = new MemoryStream(); themestream.Write(Theme, 0, Theme.Length); themestream.Position = 0; ZipFile zipreader = ZipFile.Read(themestream); foreach (ZipEntry e in zipreader) { MemoryStream stream = new MemoryStream(); e.Extract(stream); if (e.FileName.ToLower() == "theme.xml") { themexml = stream; } else { files.Add(e.FileName, stream); } } zipreader.Dispose(); themestream.Dispose(); } if (themexml == null) { throw new Exception("Invalid Theme"); } themexml.Position = 0; XmlDocument xml = new XmlDocument(); xml.Load(themexml); themexml.Dispose(); this.form = form; if (xml["Theme"] == null) { throw new Exception("Invalid Theme XML"); } XmlElement root = xml["Theme"]; foreach (Type type in types) { object[] tmp = type.GetCustomAttributes(typeof(ThemeKitControl), false); if (tmp.Length == 1) { LoadStyles(root[((ThemeKitControl)tmp[0]).XmlName], type, ((ThemeKitControl)tmp[0]).ElementsType); } } }