private void btnChangeIcon_Click(object sender, RoutedEventArgs e) { System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog(); ofd.Filter = "PNG文件|*.png"; ofd.ShowDialog(); string FileName = ofd.FileName; if (System.IO.File.Exists(FileName)) { FileStream fs = new FileStream(FileName, FileMode.Open); byte[] b = null; fs.Position = 0; using (BinaryReader br = new BinaryReader(fs)) { b = br.ReadBytes((int)fs.Length); } this.imgIcon.Source = GetIcon.ByteArrayToIS(b); itemdata.IconChanged = true; } else { Manage.TipPublic.ShowFixed(this, "File doesn't exists."); } }
public wndItemInformation(Item item) { InitializeComponent(); //填充信息 this.Item = item; this.Itemdata = item.refItemData; this.ItemName = this.Itemdata.Name; this.Path = this.Itemdata.Path; this.Arguments = this.Itemdata.Arguments; this.ItemIcon = GetIcon.ByteArrayToIS(this.Itemdata.Icon); this.WorkingDirectory = this.Itemdata.WorkingDirectory; this.TagName = this.Itemdata.TagName; this.txtHotKey.InputKeyString(this.Itemdata.HotKey); this.vtnMain.GetTags(Manage.WindowMain.Recent); this.Show(); }
/// <summary> /// 从数据文件路径初始化内部数据 /// </summary> /// <param name="path"></param> /// <returns></returns> private int ConnectDB() { if (objDB != null) { this.data.Name = objDB.ReadFirstByName("Name") as string; this.data.ID = objDB.ReadFirstByName("ID") as string; int Count = Convert.ToInt32(objDB.ReadFirstByName("Icon")); try { using (BinaryReader br = new BinaryReader(new FileStream(Manage.IconPath + data.ID + ".ib", FileMode.Open))) { data.Icon = br.ReadBytes(Count); } data.IS = GetIcon.ByteArrayToIS(data.Icon); } catch { } this.data.Path = objDB.ReadFirstByName("Path") as string; this.data.Arguments = objDB.ReadFirstByName("Arguments") as string; this.data.RunAs = Convert.ToInt32(objDB.ReadFirstByName("Runas")); this.data.AutoRun = Convert.ToInt32(objDB.ReadFirstByName("Autorun")); this.data.Levels = Convert.ToInt32(objDB.ReadFirstByName("Levels")); this.data.WorkingDirectory = objDB.ReadFirstByName("WorkingDirectory"); this.data.tagName = objDB.ReadFirstByName("TagName"); string strHKI = objDB.ReadFirstByName("HotKey"); if (strHKI != null) { if (!string.IsNullOrEmpty(strHKI.Replace(",", "").Replace(" ", ""))) { string[] HKISplit; try { HKISplit = strHKI.Split(','); } catch { HKISplit = new string[] { }; } if (HKISplit.Length >= 3) { System.Windows.Forms.KeysConverter keyCvt = new System.Windows.Forms.KeysConverter(); this.data.HotKey = new HotKeyItem(this, (System.Windows.Forms.Keys)keyCvt.ConvertFromString(HKISplit[0]), Convert.ToUInt32(HKISplit[1]), Convert.ToInt32(HKISplit[2]), HotKeyItem.HotKeyParentType.Item); if (Manage.CheckAndRegisterHotKey(data.HotKey)) { Anything_wpf_main_.cls.HotKey.CurrentID++; data.EnableHotKey = true; } } else { this.data.HotKey = new HotKeyItem(null, System.Windows.Forms.Keys.None, 0, 0, HotKeyItem.HotKeyParentType.Item); } } else { data.HotKey = new HotKeyItem(this, System.Windows.Forms.Keys.None, 0, 0, HotKeyItem.HotKeyParentType.Item); } } return(0); } return(-1); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return(GetIcon.ByteArrayToIS((byte[])value)); }
/// <summary> /// 添加新项目 /// </summary> /// <param name="Path"></param> /// <param name="Name"></param> /// <param name="Arguments"></param> /// <returns></returns> public static Item AddItem(String Path, string Name = "", string Arguments = "", string tagName = "") { //try { //检查路径 CheckPath(Path); string subPath = ""; if (!string.IsNullOrEmpty(lnkInfo.Name)) { Path = lnkInfo.TargetPath; if (string.IsNullOrEmpty(Name)) { Name = lnkInfo.Name; if (string.IsNullOrEmpty(Arguments)) { Arguments = lnkInfo.Arguments; } if (string.IsNullOrEmpty(lnkInfo.WorkingDirectory)) { subPath = GetSubPath(Path); } else { subPath = lnkInfo.WorkingDirectory; } } } else { if (string.IsNullOrEmpty(Name)) { Name = FileOperation.GetNameWithoutExtension(FileOperation.GetName(Path)); } subPath = GetSubPath(Path); if (string.IsNullOrEmpty(Arguments)) { if (!new Regex("::\\{.+\\}").IsMatch(Path)) { Arguments = GetArgumentsFromFullPath(Path); } } } //获取图标 byte[] b; if (FileOperation.IsFile(Path) == -1) { b = GetResourcesIcon("folder.png"); } else { //系统引用 if (Path.IndexOf("{") > 0 && Path.IndexOf("}") > 0) { switch (Path) { case MyComputer: b = GetResourcesIcon("computer.png"); break; case ControlPanel: b = GetResourcesIcon("controlpanel.png"); break; case MyDocument: b = GetResourcesIcon("mydocument.png"); break; case RecycleBin: b = GetResourcesIcon("recyclebin.png"); break; case NetworkNeighborhood: b = GetResourcesIcon("networkneighborhood.png"); break; default: b = GetIcon.GetIconByteArray(Path); break; } } else { b = GetIcon.GetIconByteArray(Path); } } string id = ClsMD5.ClsMD5.Encrypt(Name + Path); ImageSource IS = GetIcon.ByteArrayToIS(b); //构造UI对象 Item item = new Item(id, Name, IS, ApplicationInformations.Anything.AppInfoOperations.GetItemSize(), tagName); item.Path = Path; //构造itemdata类对象 ItemData itemdata = new ItemData(new ItemData.DataST(Name, Path, id, IS, b, "", 1, 0, 0)); if (!string.IsNullOrEmpty(tagName)) { itemdata.TagName = tagName; } //有参数则填充参数 if (!string.IsNullOrEmpty(Arguments.Trim())) { itemdata.Arguments = Arguments; } //填充工作路径 if (!string.IsNullOrEmpty(subPath.Trim())) { itemdata.WorkingDirectory = subPath; } Manage.listOfInnerData.Add(itemdata); item.RefItemData = itemdata; item.Margin = new System.Windows.Thickness(5); item.Click += Item_Click; return(item); } }