| C#扩展WebBrowser控件,使其支持拖放文件
					当前位置:点晴教程→知识管理交流
					
					→『 技术文档交流 』
					
				 
 publicpartialclassUserControl1 : WebBrowser{    privateconstintWmDropfiles = 0x233;    [DllImport("shell32.dll")]    privatestaticexternuintDragQueryFile(IntPtr hDrop, uintiFile, StringBuilder lpszFile, uintcch);    [DllImport("shell32.dll")]    privatestaticexternvoidDragAcceptFiles(IntPtr hWnd, boolfAccept);    protectedoverridevoidOnHandleCreated(EventArgs e)    {        base.OnHandleCreated(e);        //指示接受文件拖放操作        if(!DesignMode)        {            DragAcceptFiles(Handle, true);        }    }    protectedoverridevoidWndProc(refMessage m)    {        if(m.Msg == WmDropfiles)        {            #region 解析消息            //获取拖放的文件数量            varcount = DragQueryFile(m.WParam, 0xffffffff, null, 0);            //解析所有播放的文件路径            varfilePaths = newstring[count];            for(uinti = 0; i < count; i++)            {                varsb = newStringBuilder();                DragQueryFile(m.WParam, i, sb, 1024);                filePaths[i] = sb.ToString();            }            #endregion            //是否继续触发之后的消息处理            varisCancel = false;            #region 触发自定义文件拖放事件            if(DragFile != null)            {                varargs = newDragFileEventArgs(filePaths);                DragFile(this, args);                isCancel = args.IsCancel;            }            #endregion            if(isCancel) return;        }        base.WndProc(refm);    }    publiceventEventHandler<DragFileEventArgs> DragFile;    publicclassDragFileEventArgs : EventArgs    {        privatereadonlystring[] _filePaths;        publicboolIsCancel { get; set; }        publicDragFileEventArgs(string[] filePaths)        {            _filePaths = filePaths;        }        publicstring[] FilePaths        {            get{ return_filePaths; }        }    }}该文章在 2021/2/8 17:07:23 编辑过 | 关键字查询 相关文章 正在查询... |