コード例 #1
0
        private void btnAddImage_Click(object sender, EventArgs e)
        {
            CtrlImage ctrl = new CtrlImage();

            ctrl.BorderStyle  = BorderStyle.Fixed3D;
            ctrl.OnRemoveItem = OnRemoveImageItem;
            fpnlImageList.Controls.Add(ctrl);

            IDataObject iData = Clipboard.GetDataObject();

            if (iData.GetDataPresent(DataFormats.Html))
            {
                string html       = iData.GetData(DataFormats.Html).ToString();
                int    indexStart = html.IndexOf("SourceURL:", StringComparison.OrdinalIgnoreCase);
                int    indexEnd   = html.IndexOf("<!DOCTYPE HTML PUBLIC", StringComparison.OrdinalIgnoreCase);
                if (indexStart >= 0 && indexEnd > indexStart)
                {
                    string src = html.Substring(indexStart + "SourceURL:".Length, indexEnd - indexStart - "SourceURL:".Length);
                    indexStart = html.IndexOf("<IMG", StringComparison.OrdinalIgnoreCase);
                    if (indexStart >= 0)
                    {
                        indexEnd = html.IndexOf(">", indexStart, StringComparison.OrdinalIgnoreCase);
                        if (indexEnd > indexStart)
                        {
                            string img = html.Substring(indexStart, indexEnd - indexStart + 1);
                            indexStart = img.IndexOf("src=\"", StringComparison.OrdinalIgnoreCase);
                            if (indexStart >= 0)
                            {
                                indexEnd = img.IndexOf("\"", indexStart + "src=\"".Length, StringComparison.OrdinalIgnoreCase);
                                if (indexEnd > indexStart)
                                {
                                    string imgUrl = img.Substring(indexStart + "src=\"".Length, indexEnd - indexStart - "src=\"".Length).Trim('"');
                                    if (CheckImage(imgUrl))
                                    {
                                        if (CheckWebSite(imgUrl))
                                        {
                                            if (lastImageUrl != imgUrl)
                                            {
                                                ctrl.Value   = imgUrl;
                                                lastImageUrl = imgUrl;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (iData.GetDataPresent(DataFormats.Text))
            {
                string imgUrl = iData.GetData(DataFormats.Text).ToString();
                if (CheckImage(imgUrl))
                {
                    if (CheckWebSite(imgUrl))
                    {
                        if (lastImageUrl != imgUrl)
                        {
                            ctrl.Value   = imgUrl;
                            lastImageUrl = imgUrl;
                        }
                    }
                }
            }
        }
コード例 #2
0
        private void btnAddImage_Click(object sender, EventArgs e)
        {
            CtrlImage ctrl = new CtrlImage();
            ctrl.BorderStyle = BorderStyle.Fixed3D;
            ctrl.OnRemoveItem = OnRemoveImageItem;
            fpnlImageList.Controls.Add(ctrl);

            IDataObject iData = Clipboard.GetDataObject();
            if (iData.GetDataPresent(DataFormats.Html))
            {
                string html = iData.GetData(DataFormats.Html).ToString();
                int indexStart = html.IndexOf("SourceURL:", StringComparison.OrdinalIgnoreCase);
                int indexEnd = html.IndexOf("<!DOCTYPE HTML PUBLIC", StringComparison.OrdinalIgnoreCase);
                if (indexStart >= 0 && indexEnd > indexStart)
                {
                    string src = html.Substring(indexStart + "SourceURL:".Length, indexEnd - indexStart - "SourceURL:".Length);
                    indexStart = html.IndexOf("<IMG", StringComparison.OrdinalIgnoreCase);
                    if (indexStart >= 0)
                    {
                        indexEnd = html.IndexOf(">", indexStart, StringComparison.OrdinalIgnoreCase);
                        if (indexEnd > indexStart)
                        {
                            string img = html.Substring(indexStart, indexEnd - indexStart + 1);
                            indexStart = img.IndexOf("src=\"", StringComparison.OrdinalIgnoreCase);
                            if (indexStart >= 0)
                            {
                                indexEnd = img.IndexOf("\"", indexStart + "src=\"".Length, StringComparison.OrdinalIgnoreCase);
                                if (indexEnd > indexStart)
                                {
                                    string imgUrl = img.Substring(indexStart + "src=\"".Length, indexEnd - indexStart - "src=\"".Length).Trim('"');
                                    if (CheckImage(imgUrl))
                                    {
                                        if (CheckWebSite(imgUrl))
                                        {
                                            if (lastImageUrl != imgUrl)
                                            {
                                                ctrl.Value = imgUrl;
                                                lastImageUrl = imgUrl;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (iData.GetDataPresent(DataFormats.Text))
            {
                string imgUrl = iData.GetData(DataFormats.Text).ToString();
                if (CheckImage(imgUrl))
                {
                    if (CheckWebSite(imgUrl))
                    {
                        if (lastImageUrl != imgUrl)
                        {
                            ctrl.Value = imgUrl;
                            lastImageUrl = imgUrl;
                        }
                    }
                }
            }
        }