设置拖拽事件,获取拖拽内容

设置dragEnter

设置DragDrop

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;namespace WindowsFormsApp25
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){#region 单独设置textBox1.AllowDrop = true;//设置控件AllowDrop的属性textBox2.AllowDrop = true;textBox1.DragEnter += C_DragEnter;//设置控件的DragEnter效果textBox2.DragEnter += C_DragEnter;#endregion#region 批量设置//foreach (Control c in this.Controls)//{//    if (c is TextBox)//    {//        c.AllowDrop = true;//        c.DragEnter += C_DragEnter;//    }//}#endregiontextBox1.DragDrop += TextBox1_DragDrop;}private void TextBox1_DragDrop(object sender, DragEventArgs e){string html = GetHtmlContent(e.Data);string txt = GetStringContent(e.Data);}private void C_DragEnter(object sender, DragEventArgs e){//设置控件的DragEnter效果e.Effect = DragDropEffects.All;}/// <summary>/// 获得网页格式的信息/// </summary>/// <param name="data"></param>/// <returns></returns>public static string GetHtmlContent(IDataObject data){//先判断数据是否为html格式的数据if (data.GetDataPresent(DataFormats.Html)){return data.GetData(DataFormats.Html).ToString();}elsereturn "";}/// <summary>/// 获得文本内容/// </summary>/// <param name="data"></param>/// <returns></returns>public static string GetStringContent(IDataObject data){//先判断数据是否为html格式的数据if (data.GetDataPresent(DataFormats.StringFormat)){return data.GetData(DataFormats.StringFormat).ToString();}elsereturn "";}}
}
View Code

截取网页内容的正则

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;namespace WindowsFormsApp25
{class RegexObject{public static Regex reglink = new Regex(@"[a-z]+\x3A//[^\x27\x22\x20\x0A\x0D]+", RegexOptions.IgnoreCase);public static Regex regcont = new Regex(@"\x3C\x21\x2D\x2DStartFragment\x2D\x2D\x3E(?<cont>(\w|\W)*?)\x3C\x21\x2D\x2DEndFragment\x2D\x2D\x3E", RegexOptions.IgnoreCase);public static Regex reghtml = new Regex(@"<[^>]*>", RegexOptions.IgnoreCase);public static Regex regimg = new Regex(@"<\W*img[^>]+src\W*\x3D[\x27\x22\W]*(?<img>(\w|\W)*?)[\x27\x22\x20\x3E]", RegexOptions.IgnoreCase);public static Regex regsource = new Regex(@"sourceURL\x3A(?<source>[^\r\n]*)[\r\n]", RegexOptions.IgnoreCase);public static Regex regsup = new Regex(@"\x3Csup\x3E", RegexOptions.IgnoreCase);public static Regex regsub = new Regex(@"\x3Csub\x3E", RegexOptions.IgnoreCase);public static Regex regsupsubend = new Regex(@"\x3C/su(b|p)\x3E", RegexOptions.IgnoreCase);public static Regex regemail = new Regex(@"([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,5})+", RegexOptions.IgnoreCase);public static Regex regehttp = new Regex(@"((http|https)://)?(www\.)?[A-Za-z0-9]+\.(com|net|cn|com\.cn|com\.net|net\.cn)", RegexOptions.IgnoreCase);public static Regex regdate = new Regex(@"((?<!\d)((\d{2,4}(\.|年|\/|\-))((((0?[13578]|1[02])(\.|月|\/|\-))((3[01])|([12][0-9])|(0?[1-9])))|(0?2(\.|月|\/|\-)((2[0-8])|(1[0-9])|(0?[1-9])))|(((0?[469]|11)(\.|月|\/|\-))((30)|([12][0-9])|(0?[1-9]))))|((([0-9]{2})((0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))(\.|年|\/|\-))0?2(\.|月|\/|\-)29))日?(?!\d))");public static Regex regDomain = new Regex(@"(?<mydomain>(?<Protocol>\w+):\/\/(?<Domain>[\w.\x2D]+))\/?\S*", RegexOptions.IgnoreCase);public static Regex regWWW = new Regex(@"(?<url>http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?)", RegexOptions.IgnoreCase);//((http|https)://)?(www\.)?[A-Za-z0-9]+\.(com|net|cn|com\.cn|com\.net|net\.cn)public static Regex regyear = new Regex(@"\d{4}");public static string GetWWW(string txt){return regWWW.Match(txt).Value;}public static string GetYear(string txt){return regyear.Match(txt).Value;}public static string Getdomain(string url){return regDomain.Match(url).Groups["Domain"].Value;}/// <summary>/// 截取日期/// </summary>/// <param name="txt"></param>/// <returns></returns>public static string GetDate(string txt){return regdate.Match(txt).Value.ToString();}/// <summary>/// 只获得如https://www.baidu.com的部分/// </summary>/// <param name="txt"></param>/// <returns></returns>public static string GetHttp(string txt){return regehttp.Match(txt).Value.ToString();}/// <summary>/// 获取当前拖拽的内容(拖拽文本)/// </summary>/// <param name="text"></param>/// <returns></returns>public static string GetText(string text){string cont = regcont.Match(text).Groups["cont"].Value;string r = reghtml.Replace(cont, "").Trim();return r;}/// <summary>/// 获得链接字段的网址(将要打开的网页)/// </summary>/// <param name="text"></param>/// <returns></returns>public static string GetLink(string text){string cont = regcont.Match(text).Groups["cont"].Value;string r = reglink.Match(cont).Value;return r;}/// <summary>/// 获得链接字段的当前网址(现在的网址)/// </summary>/// <param name="text"></param>/// <returns></returns>public static string GetRefPage(string text){return regsource.Match(text).Groups["source"].Value.Trim();}/// <summary>/// 获取网址信息(包含version,源网址和当前拖拽链接的网址信息)/// </summary>/// <param name="text"></param>/// <returns></returns>public static string ReplaceSubSup(string text){text = regsup.Replace(text, "(↑");text = regsub.Replace(text, "(↓");text = regsupsubend.Replace(text, ")").Trim();return text;}}
}
View Code

 

转载于:https://www.cnblogs.com/wwz-wwz/p/7017269.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/468430.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

笔记本电脑锁_2020年双11有哪些值得选购的笔记本电脑?(全能本/便携高性能笔记本电脑/设计本)...

&#xff08;本文于2020年10月22日更新&#xff09;本文章会不定期更新&#xff0c;保证文章的时效性和准确性&#xff0c;可点赞或收藏本文章&#xff0c;这样在需要的时候可以找到啦。文章推荐产品较多&#xff0c;按价位排序&#xff0c;篇幅较长&#xff0c;可按键盘CtrlF快…

android libc 有哪些函数_Android scudo功能介绍

一 简述前面介绍了malloc_debug功能&#xff0c;用来进行内存泄露等检测&#xff0c;其实android可以使用多种方法进行内存相关的监控。比如利用llvm功能再编译时添加内存的相关检测。Android R默认开启了scudo。scudo这个选项主要功能是再分配内存时会添加64 bit的Header// Ou…

300来行代码实现最小Linux文件系统

Linux作为一个类UNIX系统&#xff0c;其文件系统保留了原始UNIX文件系统的表象形式&#xff0c;它看起来是这个样子&#xff1a;rootname-VirtualBox:/# lsbin boot cdrom dev etc home lib lib64 lostfound media mnt opt proc root run sbin snap srv sys …

淘宝怎么多个订单一起付款_淘宝未付款订单如何催付?

淘宝未付款订单如何催付&#xff1f;很多人只认为运营就是技巧&#xff0c;其实客服也是需要技巧的&#xff0c;客服也是关键的数据支撑。一个好的客服团队&#xff0c;能够很好地提高转化率、客单价、复购率&#xff0c;有效的降低退款率、纠纷等售后问题。今天和大家分享一下…

mysql存储过程触发器游标_MySQL存储过程,触发器,游标

语法&#xff1a;1.存储过程&#xff1a;create PROCEDURE name(argment_list)beginsql_statement;end2.触发器&#xff1a;create trigger name (before|after) (insert | update | delete) on table_namefor each rowbeginsql_statement;end3.游标:declare cursor_name curso…

爱大姚,恨男篮

先祝姚明生日快乐2019年9月12日。是中国篮协主席、CBA董事长姚明39岁的生日&#xff0c;时间已经过去几天了&#xff0c;当时铺天盖地的都是其他的热点新闻&#xff0c;很多人&#xff0c;包括我也忘记了这个大个子已经39岁了&#xff0c;看着中国男篮的惨败&#xff0c;很想冲…

Linux 内核系统架构

描述Linux内核的文章已经有上亿字了但是对于初学者&#xff0c;还是应该多学习多看&#xff0c;毕竟上亿字不能一下子就明白的。即使看了所有的Linux 内核文章&#xff0c;估计也还不是很明白&#xff0c;这时候&#xff0c;还是需要fucking the code.28年前(1991年8月26日)Lin…

gif透明背景动画_如何利用premiere制作GIF动态图片

GIF制作流程(也可以用此教程把视频变成GIF动图)作者&#xff1a;益红一、导出设计文件将要做动画的文件在ps里面导出 (透明图层用PNG)(也可以将合适的视频片段作为素材)二、在PR里面新建项目打开 Adobe premiere选择 新建项目找到新建项目 — 命名 —设置合适的项目 位置-点击浏…

mysql sqlserver分页_SqlServer、MySql万能分页代码

sql数据库中常用的分页 我做了一个万能的 用的上的小伙伴拿去耍吧go ----SqlServer万能分页代码create procedure [dbo].[sp_datapager]pagesize int,--每一页的大小pageindex int,--页码数tablename varchar(Max),--表的名称keycolumn varchar(20),---主键idcolumns varchar(…

并查集做题总结

CF 469B 构造出两个节点n1,n2来存放A集合和B集合中的数据&#xff0c;显然一个合理的分配不会使得一个元素既在A里面&#xff0c;也在B里面。而由于每一个元素都要去分配&#xff0c;如果a-x没有那它就得在B里面&#xff08;和n2合并&#xff09;&#xff0c;同理对于b-x没有的…

离职了

这是我毕业后的第一份工作...面试时&#xff0c;HR小姐姐告诉我...然鹅...我入职之后才发现&#xff1a;对标阿里的只有加班强度对标华为的只有狼性文化对标百度的&#xff0c;额&#xff0c;没有对标百度同事们有的住在海淀区、有的住在朝阳区&#xff0c;作为刚毕业的一枚“穷…

windows7官方原版_如何下载微软原版操作系统、办公软件

如何下载微软原版操作系统、办公软件&#xff1f;简介&#xff1a;微软操作系统从MS-DOS到Windows XP&#xff0c;Windows 7&#xff0c;Windows 8&#xff0c;再到现在的Windows 10 &#xff0c;一代比一代强&#xff0c;每代都有自己的特点。现在我们能从官网上下载到的只有W…

gojs 部分功能实现

最近做的项目用到了gojs&#xff0c;使用了一段时间发现其功能特别强大&#xff0c;先记录下目前自己用到的把 1. 初始化画布 myDiagram $(go.Diagram, "myDiagramDiv", {}); 2. 定义node 模型 myDiagram.nodeTemplate $(go.Node, "Vertical", { locati…

CPU是如何访问到内存的?

讨论的重点我们知道CPU有地址总线&#xff0c;数据总线和控制总线数据总线&#xff08;Data Bus&#xff09;&#xff1a;在CPU与RAM之间来回传送需要处理或是需要储存的数据。地址总线&#xff08;Address Bus&#xff09;&#xff1a;用来指定在RAM&#xff08;Random Access…

海量url mysql_海量数据mysql优化步骤

第一优化你的sql和索引&#xff1b;第二加缓存&#xff0c;memcached,redis&#xff1b;第三以上都做了后&#xff0c;还是慢&#xff0c;就做主从复制或主主复制&#xff0c;读写分离&#xff0c;可以在应用层做&#xff0c;效率高&#xff0c;也可以用三方工具&#xff0c;第…

macos支持exfat吗_打造便捷、人性化的macOS桌面使用环境

原标题&#xff1a;打造便捷、人性化的macOS桌面使用环境打造便捷、人性化的macOS桌面使用环境 2020-10-23 17:25:410点赞4收藏0评论欢迎参加#果粉是怎样炼成的#征稿&#xff0c;围观秋季发布会新品&#xff01;是什么让苹果生态无法割舍&#xff1f;快来讲讲你的果粉炼成记&am…

Delphi XE7的Splash 功能

Delphi XE7的Splash 功能转载于:https://www.cnblogs.com/LittleTiger/p/7020349.html

滴滴是如何搭建起PB级数据中台的?

滴滴公司自12年底上线至今&#xff0c;俨然成功跻身互联网大咖行列&#xff0c;在以流量活命的互联网世界里&#xff0c;如果没有一定的硬核技术为业务做支撑&#xff0c;单靠营销与宣传&#xff0c;是没有办法留住日益挑剔的用户的。我们今天就谈一谈滴滴打车背后所用到的大数…

gdbc 同步mysql_Jdbc数据同步

ElasticSearch 安装安装前准备安装JDK7及以上版本(这里不再讲述JDK安装步骤)下载ElasticSearch安装包&#xff0c;点击 获取elasticsearch-2.1.1.tar.gz安装包(https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.…

CommonJS规范

概述 Node应用由模块组成&#xff0c;采用CommonJS模块规范。 根据这个规范&#xff0c;每个文件就是一个模块&#xff0c;有自己的作用域。在一个文件里面定义的变量、函数、类&#xff0c;都是私有的&#xff0c;对其他文件不可见。转载于:https://www.cnblogs.com/happy1992…