Esempio n. 1
0
        private void flowLayoutPanel1_DragDrop(object sender, DragEventArgs e)
        {
            List<LinkDataClass> ldc = new List<LinkDataClass>();

            // ドラッグ中のファイルやディレクトリの取得
            string[] drags = (string[])e.Data.GetData(DataFormats.FileDrop);
            System.Drawing.Icon myicon;
            if (drags != null)
            {
                foreach (string tmp in drags)
                {
                    if (System.IO.Directory.Exists(tmp))
                    {

                        SHFILEINFO shinfo = new SHFILEINFO();
                         //Use this to get the small Icon
                        IntPtr hImgSmall = Win32.SHGetFileInfo(tmp, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_LARGEICON);
                        myicon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
                    }
                    else
                    {
                        myicon = System.Drawing.Icon.ExtractAssociatedIcon(tmp);
                    }
                    ldc.Add(new LinkDataClass(tmp, myicon,LinkDataClass.LType.EXE));
                }
            }
            else
            {
                string tmp = (string)e.Data.GetData(DataFormats.UnicodeText);
                if (tmp.StartsWith("http://") || tmp.StartsWith("https://"))
                {
                    ldc.Add(new LinkDataClass(tmp, bricon,LinkDataClass.LType.LINK));
                }
                else
                {
                    ldc.Add(new LinkDataClass(tmp, SystemIcons.Information,LinkDataClass.LType.TEXT));
                }
            }


            LinkControl lc = new LinkControl(ldc[0]);
            lc.Name = Guid.NewGuid().ToString();

            this.flowLayoutPanel1.Controls.Add(lc);            
        }
Esempio n. 2
0
 public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
Esempio n. 3
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
           
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {

                DataContractSerializer ser = new DataContractSerializer(typeof(ArrayLinkDataClass));
                string fileName = openFileDialog1.FileName;
                XmlReader xr = XmlReader.Create(fileName);
                ArrayLinkDataClass t;
                try
                {
                    t = (ArrayLinkDataClass) ser.ReadObject(xr);
                }catch(Exception ex){
                    MessageBox.Show("ファイルの読み込みに失敗しました。", "読み込み", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                xr.Close();

                //削除
                foreach (Control c in  this.flowLayoutPanel1.Controls){
                    c.Dispose();
                }
                foreach (LinkDataClass f in t.list)
                {
                    
                    if (f.MyType == LinkDataClass.LType.LINK)
                    {
                        f.MyIcon = bricon;
                    }
                    else if (f.MyType == LinkDataClass.LType.EXE)
                    {
                        if (System.IO.Directory.Exists(f.MyLink))
                        {

                            SHFILEINFO shinfo = new SHFILEINFO();
                            //Use this to get the small Icon
                            IntPtr hImgSmall = Win32.SHGetFileInfo(f.MyLink, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_LARGEICON);
                            f.MyIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
                        }
                        else
                        {
                            if (System.IO.File.Exists(f.MyLink))
                            {
                                f.MyIcon = System.Drawing.Icon.ExtractAssociatedIcon(f.MyLink);
                            }
                            else
                            {
                                f.MyIcon = SystemIcons.Information;
                            }
                        }
                    }
                    else
                    {
                        f.MyIcon = SystemIcons.Information;
                    }
                    LinkControl lc = new LinkControl(f);
                    lc.Name = Guid.NewGuid().ToString();
                    this.flowLayoutPanel1.Controls.Add(lc);           
                }                
            }
        }