Ejemplo n.º 1
0
 private void mainForm_KeyDown(object sender, KeyEventArgs e)
 {
     Control factive = this.ActiveControl;
     if (factive is LinkControl)
     {
         LinkControl uactive = (LinkControl)factive;
         if (uactive.ActiveControl is TextBox)
         {
             return;
         }
     }
     if ((e.Modifiers & Keys.Control) == Keys.Control && e.KeyCode == Keys.V)
     {
         Console.WriteLine("key");
         IDataObject data = Clipboard.GetDataObject();
         string str = (string)data.GetData(DataFormats.Text);
         if (! string.IsNullOrEmpty(str))
         {
             
             LinkControl lc = new LinkControl(new LinkDataClass(str, SystemIcons.Information, LinkDataClass.LType.TEXT));
             lc.Name = Guid.NewGuid().ToString();
             this.flowLayoutPanel1.Controls.Add(lc);    
         }
     }
     this.Focus();
 }
Ejemplo n.º 2
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
                {
                    /*
                    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, SystemIcons.Information,LinkDataClass.LType.TEXT));
                }
            }

            //EventHandler handle = 
            //    (ss, ee) =>{
            //        Button btn = (Button)ss;
            //        btn.Parent.Dispose();
            //    };

            //Button test1 = new Button();
            //test1.Name = Guid.NewGuid().ToString();
            //test1.Text = test1.Name;
            //test1.Click += handle;

            LinkControl lc = new LinkControl(ldc[0]);
            lc.Name = Guid.NewGuid().ToString();
            //Control[] cls =  lc.Controls.Find("DisposeButton",false);
            //cls[0].Click += handle;

            this.flowLayoutPanel1.Controls.Add(lc);            
        }
Ejemplo 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);           
                }                
            }
        }