void LoadConfig(GeoStar.Utility.Config config) { m_CursorMgr = new CursorMgr(config["Cursors"]); Text = config.Child("Caption").StringValue(""); string strIcon = config.Child("Icon").StringValue(""); if (!string.IsNullOrEmpty(strIcon)) { if (!System.IO.Path.IsPathRooted(strIcon)) { strIcon = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strIcon); } if (System.IO.File.Exists(strIcon)) { this.Icon = new Icon(strIcon); } } m_MainToolBar = new CToolLoader(toolStrip1); m_MainMenuBar = new CToolLoader(menuStrip1, 16); if (config.Exist("Menu")) { m_MainMenuBar.Load(config.Child("Menu")); } if (config.Exist("ToolBar")) { m_MainToolBar.Load(config.Child("ToolBar")); } }
/// <summary> /// 实例化为对象化的Value,初始化参数为空 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static Type ValueType(this GeoStar.Utility.Config config) { Type t = config.Type; if (null != t) { return(t); } string strType = config.TypeString; t = Type.GetType(strType); if (null != t) { return(t); } foreach (var item in AppDomain.CurrentDomain.GetAssemblies()) { t = item.GetType(strType); if (null != t) { return(t); } } return(t); }
/// <summary> /// 构造。 /// </summary> /// <param name="c"></param> public CursorMgr(GeoStar.Utility.Config c) { foreach (GeoStar.Utility.Config item in c) { Add(item); } }
void LoadContextMenu(GeoStar.Utility.Config config) { foreach (var item in config) { ContextMenuStrip menu = new ContextMenuStrip(); menu.Name = item.Name; CToolLoader load = new CToolLoader(menu); load.Load(item); } }
/// <summary> /// 根据配置添加一个游标 /// </summary> /// <param name="c"></param> void Add(GeoStar.Utility.Config c) { string strVal = c.StringValue(""); if (string.IsNullOrEmpty(strVal)) { return; } System.Windows.Forms.Cursor cur = Create(strVal); if (null == cur) { return; } m_Dic[c.Name] = cur; }
public DataSourceTree(GeoStar.Utility.Config config, TreeView tree) { LoadImage(config["Image"]); LoadContextMenu(config["Image"]); m_TreeView = tree; m_TreeView.ImageList = m_ImageList; m_Root = m_TreeView.Nodes.Add("文件"); m_Root.Nodes.Add(ReplaceNode); m_Root.ImageKey = ImageKey(NodeSourceType.eComputer); m_Root.SelectedImageKey = m_Root.ImageKey; m_Root.Tag = new NodeSource(); m_TreeView.BeforeExpand += new TreeViewCancelEventHandler(m_TreeView_BeforeExpand); m_TreeView.AfterCollapse += new TreeViewEventHandler(m_TreeView_AfterCollapse); m_TreeView.NodeMouseClick += new TreeNodeMouseClickEventHandler(m_TreeView_NodeMouseClick); }
/// <summary> /// 将自身配置作为参数传递给对象。 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static T ObjectValueConfig <T>(this GeoStar.Utility.Config config) where T : class { Type t = config.ValueType(); if (t == null) { return(null); } try { return(Activator.CreateInstance(t, new object[] { config }) as T); } catch (Exception e) { } return(null); }
/// <summary> /// 获取枚举类型的值。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="eDefault"></param> /// <returns></returns> public static T EnumValue <T>(this GeoStar.Utility.Config config, T eDefault)// where T : Enum { string strValue = config.Value; if (string.IsNullOrEmpty(strValue)) { return(eDefault); } try { return((T)Enum.Parse(typeof(T), strValue, true)); } catch (Exception e) { } return(eDefault); }
void LoadImage(GeoStar.Utility.Config config) { int w = 0; int h = 0; Dictionary <string, System.Drawing.Image> vIcons = new Dictionary <string, System.Drawing.Image>(); foreach (var item in config) { string strKey = item.Name; string strIcon = item.Value; if (!System.IO.Path.IsPathRooted(strIcon)) { strIcon = System.IO.Path.GetFullPath(strIcon); } if (!System.IO.File.Exists(strIcon)) { return; } System.Drawing.Image pIcon = System.Drawing.Image.FromFile(strIcon); vIcons[strKey] = pIcon; if (w < pIcon.Size.Width) { w = pIcon.Size.Width; } if (h < pIcon.Size.Height) { h = pIcon.Size.Height; } } if (w > 24 || h > 24) { w = 16; h = 16; } m_ImageList.ImageSize = new System.Drawing.Size(w, h); foreach (var item in vIcons) { m_ImageList.Images.Add(item.Key, item.Value); } }