设置拖拽事件,获取拖拽内容
设置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
设置拖拽事件,获取拖拽内容相关推荐
- js控制文件拖拽,获取拖拽内容。
在用户拖拽文件到浏览器的某个元素上时,js可以监听到与拖拽相关的事件,并对拖拽结果进行处理,本文讨论下和拖拽文件相关的一些问题,不过没有处理太多关于兼容性的问题. 拖拽事件 js能够监听到拖拽的事件有 ...
- js控制文件拖拽,获取拖拽内容
在用户拖拽文件到浏览器的某个元素上时,js可以监听到与拖拽相关的事件,并对拖拽结果进行处理,本文讨论下和拖拽文件相关的一些问题,不过没有处理太多关于兼容性的问题. 拖拽事件 js能够监听到拖拽的事件有 ...
- html css拖拽设计,css绘制三角形 和 HTML拖拽事件
利用css制作三角形 利用设置边框的三个边的长度和border实现三角形设置,并隐藏其他边 例子:#yz3{ display: inline-block; 0; height: 0; border-t ...
- JavaFX鼠标拖拽事件
一.节点原拖拽事件 //鼠标拖拽进入node node.setOnMouseDragEntered(event->{//do something });//鼠标拖拽退出node node.set ...
- 手机端拖拽事件,获取pageX和pageY坐标方式
手机端拖拽事件: touchstart事件:当手指触摸屏幕时候触发,即使已经有一个手指放在屏幕上也会触发. touchmove事件:当手指在屏幕上滑动的时候连续地触发.在这个事件发生期间,调用prev ...
- JavaScript学习第十六天(键盘事件、表单事件、拖拽事件、框架事件、媒体事件)
文章目录 键盘事件 表单事件 剪贴板事件 拖拽事件 打印事件 框架事件 媒体事件 总结 键盘事件 onkeydown 键盘按下事件,当有按键按下时触发 onkeyup 键盘松开事件,当有按键被松开时触 ...
- jQuery画布以及拖拽事件
jQuery 画布 canvas 属于html元素 H5新元素 需要结合js 在页面上放置一个canvas元素,就相当于放置了一块画布 可以绘制路径 矩形 圆形 字符 图像 主要属性: width 默 ...
- JavaScript(11) - 阻止事件冒泡和默认行为,拖拽,事件监听器
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 一.阻止事件冒泡和默认行为 二.拖拽 1, 实现拖拽相关的三大事件: 2, 实现拖拽思路: 1, 给目标元素添加onmous ...
- vuejs 原生JS 拖拽事件案例
原生JS or Vue 事件案例合集(详细) 提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加 Section 1 单个或多个鼠标拖拽事件的理解 提示:写完文章后,目录可以自动生成,如 ...
- 中如何使用echart_jQueryEasyUI中的拖拽事件如何使用
jQueryEasyUI中的拖拽事件通过给它设置代理元素使其拖拽.可设置拖动元素相对于x.y轴拖动,可设置拖拽何时停止等效果 jQuery中的easyui是一个非常好用的插件,它虽然使用简单方便,但是 ...
最新文章
- 【ACM】UVA - 340 Master-Mind Hints(一定要好好学英语...)
- [C++]VisualAssistX中文注释提示错误 解决办法
- sqlserver——视图
- (52)FPGA条件选择(casex)
- java中插入排序_Java中的插入排序
- 六石管理学:头目们为什么要忽略产品质量
- php 5.5.9安装,php5.5.9+apache2.4.7 编译安装
- 2021年通达信指标公式大全,值得收藏!
- ORA-39194: Table mode jobs require the tables to be comma separated.
- 广东工业大学计算机学院张静,广东工业大学文件.doc
- php中空格怎么表示什么,HTML中的空格符号是什么
- Lab 2 Bomb Lab
- 智能制造MES系统框架
- ISCC2021—检查一下
- [redis] 10 种数据结构详解
- 深入分析 Uniswap V3 流动性供应的数学原理
- 安卓转战React-Native之签名打包成Apk并极速多渠道打包
- CSS之盒子的边距塌陷(兄弟、父子)与解决方案
- ESXI中设置高格作为旁路由并设置双机热备(VRRP)
- TMS320F280049C 学习笔记31 控制率加速器 CLA 学习随笔