public void AddToolboxItem(ToolboxItem toolboxItem, string category) { ToolboxTab2 tab = CreateTab(category, true, -1); tab.AddItem(toolboxItem); }
public void CreatePrimaryObjTab() { Bitmap bmpInt = new Bitmap(GetType(), "int.bmp"); Bitmap bmpDec = new Bitmap(GetType(), "decimal.bmp"); Bitmap bmpAbc = new Bitmap(GetType(), "abc.bmp"); Bitmap bmpObj = new Bitmap(GetType(), "obj.bmp"); Bitmap bmpBool = new Bitmap(GetType(), "bool.bmp"); Bitmap bmpDate = new Bitmap(GetType(), "date.bmp"); Bitmap bmpByte = new Bitmap(GetType(), "byte.bmp"); Bitmap bmpEarg = new Bitmap(GetType(), "eargv.bmp"); Bitmap bmpSByte = new Bitmap(GetType(), "sbyte.bmp"); Bitmap bmpChar = new Bitmap(GetType(), "char.bmp"); ToolboxTab2 tab = CreateTab("Primary Objects", true, -1); tab.Persist = false; tab.AddItem(new xToolboxItem(typeof(object), bmpObj)); tab.AddItem(new xToolboxItem(typeof(char), bmpChar)); tab.AddItem(new xToolboxItem(typeof(sbyte), bmpSByte)); tab.AddItem(new xToolboxItem(typeof(Int16), bmpInt)); tab.AddItem(new xToolboxItem(typeof(Int32), bmpInt)); tab.AddItem(new xToolboxItem(typeof(Int64), bmpInt)); tab.AddItem(new xToolboxItem(typeof(byte), bmpByte)); tab.AddItem(new xToolboxItem(typeof(UInt16), bmpInt)); tab.AddItem(new xToolboxItem(typeof(UInt32), bmpInt)); tab.AddItem(new xToolboxItem(typeof(UInt64), bmpInt)); tab.AddItem(new xToolboxItem(typeof(string), bmpAbc)); tab.AddItem(new xToolboxItem(typeof(float), bmpDec)); tab.AddItem(new xToolboxItem(typeof(double), bmpDec)); tab.AddItem(new xToolboxItem(typeof(bool), bmpBool)); tab.AddItem(new xToolboxItem(typeof(DateTime), bmpDate)); tab.AddItem(new xToolboxItem(typeof(EventArgs), bmpEarg)); tab.AddItem(new xToolboxItem(typeof(void), bmpObj, "Object")); tab.AdjustSize(); }
/// <summary> /// IDesignerHost is a service provided by DesignSurface /// </summary> /// <param name="toolboxItem"></param> /// <param name="category"></param> /// <param name="host"></param> public void AddLinkedToolboxItem(ToolboxItem toolboxItem, string category, IDesignerHost host) { ToolboxTab2 tab = CreateTab(category, true, -1); tab.AddItem(toolboxItem); }
public void ReadFromXmlFile(out string error) { if (_toolboxXml == null || _toolboxXml.Length == 0) { error = "ToolboxXml is empty"; return; } if (!System.IO.File.Exists(_toolboxXml)) { error = "ToolboxXml does not exist at " + _toolboxXml; return; } error = ""; try { StreamReader sr = new StreamReader(_toolboxXml); XmlDocument xml = new XmlDocument(); xml.LoadXml(sr.ReadToEnd()); sr.Close(); foreach (XmlNode nodeDoc in xml.ChildNodes) { if (string.CompareOrdinal(nodeDoc.Name, "Toolbox") == 0) { foreach (XmlNode node in nodeDoc.ChildNodes) { if (string.CompareOrdinal(node.Name, "ToolboxTab") == 0) { XmlAttribute xa = node.Attributes["title"]; if (xa != null && xa.Value != null && xa.Value.Length > 0) { string name = xa.Value; bool bReadOnly = true; xa = node.Attributes["readonly"]; if (xa != null && xa.Value != null && xa.Value.Length > 0) { bReadOnly = (string.Compare(xa.Value, "false", StringComparison.OrdinalIgnoreCase) != 0); } ToolboxTab2 tab = CreateTab(name, bReadOnly, -1); foreach (XmlNode nd in node.ChildNodes) { if (string.CompareOrdinal(nd.Name, "Item") == 0) { try { string s = nd.InnerText.Replace("\r", "").Replace("\n", "").Trim(); Type t = Type.GetType(s); if (t != null) { xToolboxItem xi; xa = nd.Attributes["Type"]; if (xa != null) { Type xt = Type.GetType(xa.Value); xi = (xToolboxItem)Activator.CreateInstance(xt, new object[] { t }); } else { xi = new xToolboxItem(t); } xi.ReadNode(nd); tab.AddItem(xi); } } catch (Exception ee) { if (error.Length == 0) { error += ee.Message; } else { error += "\r\n" + ee.Message; } } } } tab.AdjustSize(); } } } } } } catch (Exception e) { error = string.Format(CultureInfo.InvariantCulture, "{0}. \r\n{1}", e.Message, e.StackTrace); } OnResize(null); AdjustTabPos(0); }