Frm_Main.cs

View Code

 1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 using System.IO;//添加的命名空间,对文件进行操作10 using System.Threading;//线程序的命名空间11 12 namespace DragImageToForm13 {14     public partial class Frm_Main : Form15     {16         public Frm_Main()17         {18             InitializeComponent();19         }20 21         public static bool Var_Style = true;22         public static string tempstr="";23 24         /// <summary>25 /// 在窗体背景中显示被拖放的图片26 /// </summary>27 /// <param Frm="Form">窗体</param>28 /// <param e="DragEventArgs">DragDrop、DragEnter 或 DragOver 事件提供数据</param>29         public void SetDragImageToFrm(Form Frm, DragEventArgs e)30         {31             if (Var_Style == true)32             {33                 e.Effect = DragDropEffects.Copy;//设置拖放操作中目标放置类型为复制34                 String[] str_Drop = (String[])e.Data.GetData(DataFormats.FileDrop, true);//检索数据格式相关联的数据35                 string tempstr;36                 Bitmap bkImage;//定义Bitmap变量37                 tempstr = str_Drop[0];//获取拖放文件的目录38                 try39                 {40                     bkImage = new Bitmap(tempstr);//存储拖放的图片41 //根据图片设置窗体的大小42                     Frm.Size = new System.Drawing.Size(bkImage.Width + 6, bkImage.Height + 33);43                     Frm.BackgroundImage = bkImage;//在窗体背景中显示图片44                 }45                 catch { }46             }47         }48 49         private void Frm_Main_DragEnter(object sender, DragEventArgs e)50         {51             SetDragImageToFrm(this, e);//在窗体中显示拖放到窗体上的图片52         }53     }54 }

Frm_Main.designer.cs

View Code

 1 namespace DragImageToForm 2 { 3     partial class Frm_Main 4     { 5         /// <summary> 6 /// 必需的设计器变量。 7 /// </summary> 8         private System.ComponentModel.IContainer components = null; 9 10         /// <summary>11 /// 清理所有正在使用的资源。12 /// </summary>13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>14         protected override void Dispose(bool disposing)15         {16             if (disposing && (components != null))17             {18                 components.Dispose();19             }20             base.Dispose(disposing);21         }22 23         #region Windows 窗体设计器生成的代码24 25         /// <summary>26 /// 设计器支持所需的方法 - 不要27 /// 使用代码编辑器修改此方法的内容。28 /// </summary>29         private void InitializeComponent()30         {31             this.components = new System.ComponentModel.Container();32             this.panel_face = new System.Windows.Forms.Panel();33             this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);34             this.Tool_Ima = new System.Windows.Forms.ToolStripMenuItem();35             this.Tool_File = new System.Windows.Forms.ToolStripMenuItem();36             this.contextMenuStrip1.SuspendLayout();37             this.SuspendLayout();38             // 39 // panel_face40 // 41             this.panel_face.ContextMenuStrip = this.contextMenuStrip1;42             this.panel_face.Dock = System.Windows.Forms.DockStyle.Fill;43             this.panel_face.Location = new System.Drawing.Point(0, 0);44             this.panel_face.Name = "panel_face";45             this.panel_face.Size = new System.Drawing.Size(391, 238);46             this.panel_face.TabIndex = 0;47             this.panel_face.Visible = false;48             // 49 // contextMenuStrip150 // 51             this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {52             this.Tool_Ima,53             this.Tool_File});54             this.contextMenuStrip1.Name = "contextMenuStrip2";55             this.contextMenuStrip1.Size = new System.Drawing.Size(137, 48);56             // 57 // Tool_Ima58 // 59             this.Tool_Ima.Name = "Tool_Ima";60             this.Tool_Ima.Size = new System.Drawing.Size(136, 22);61             this.Tool_Ima.Tag = "1";62             this.Tool_Ima.Text = "拖放图片";63             // 64 // Tool_File65 // 66             this.Tool_File.Name = "Tool_File";67             this.Tool_File.Size = new System.Drawing.Size(136, 22);68             this.Tool_File.Tag = "2";69             this.Tool_File.Text = "拖放文件夹";70             // 71 // Frm_Main72 // 73             this.AccessibleRole = System.Windows.Forms.AccessibleRole.None;74             this.AllowDrop = true;75             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);76             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;77             this.ClientSize = new System.Drawing.Size(391, 238);78             this.ContextMenuStrip = this.contextMenuStrip1;79             this.Controls.Add(this.panel_face);80             this.Name = "Frm_Main";81             this.Text = "向窗体中拖放图片并显示";82             this.DragEnter += new System.Windows.Forms.DragEventHandler(this.Frm_Main_DragEnter);83             this.contextMenuStrip1.ResumeLayout(false);84             this.ResumeLayout(false);85 86         }87 88         #endregion89 90         private System.Windows.Forms.Panel panel_face;91         private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;92         private System.Windows.Forms.ToolStripMenuItem Tool_Ima;93         private System.Windows.Forms.ToolStripMenuItem Tool_File;94 95     }96 }

作者:墨明棋妙
出处:http://www.cnblogs.com/ynbt/
关于作者:专注于.Net、WCF和移动互联网开发。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过ynbt_wang@163.com联系我,非常感谢。 。

向窗体中拖放图片并显示相关推荐

  1. Vue.js项目中,当图片无法显示时则显示默认图片

    Vue.js项目中,当图片无法显示时则显示默认图片使用onerror方法 最近在学习Vue时,遇到了一个问题,就是从后台传过来的图片路径无效时,需要在页面显示默认图片 本人试了3种方法,2种方法失败了 ...

  2. Element-UI中走马灯图片无法显示的问题

    Element-UI中走马灯图片无法显示的问题 废话不多说代码奉上:这里说一下height的大小问题,我放的图片是3200*1250的 看了其他帖子上试了很多都不行,后来发现可能就是图片大小的原因 然 ...

  3. VSCode中MarkDown图片无法显示

    VSCode中MarkDown图片无法显示 这是由于 VSCode 中MarkDown默认配置中只允许载入安全内容,更改设置即可. 在MarkDown文件中输入快捷键 Ctrl + Shift + P ...

  4. html邮件修改不了图片,邮件模板中的图片不显示,该怎么解决

    邮件模板中的图片不显示 这个是我邮件模板 html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...

  5. 在access窗体中加图片_如何在Access窗体中显示指定路径的图片

    在Access中,如果把图形对象以OLE格式的字段保存,那么在窗体中可以直接显示出图片来.但是这样做有以下不足:一.需要将图片逐一插入到表中,工作量太大.二.使数据库文件变得庞大.三.相同的图片文件, ...

  6. java窗体中添加图片_在java窗体程序中添加图片的方法

    在java窗体程序中添加图片的方法 发布时间:2020-06-16 11:24:13 来源:亿速云 阅读:148 作者:Leah 这篇文章主要为大家详细介绍了在java窗体程序中添加图片的方法,图文详 ...

  7. Word文档中粘贴图片不显示

    1. 完全不显示 转自 https://zhidao.baidu.com/question/940969054291935092.html 排除图片文件问题,如果粘贴的图片在Word中不现实,一般是设 ...

  8. img显示保存在服务器中的图片,img显示服务器图片不显示

    img显示服务器图片不显示 内容精选 换一换 训练模板分类模型后,需要对模板分类器和模板图片进行评估和考察.您可以通过上传测试图片,在线评估模板分类情况和模板的文字识别情况,保证能在多个模板情况下正确 ...

  9. word中插入图片只显示底边,其他看不到,插入公式显示不全

    在word中插入图片发现只能显示底边,其他内容看不到,图片上方还有文字,好像图片隐形了一样.插入公式显示不全,少些边角,尤其是公式的上下显示不完整. 原因: 段落中设置了固定行间距 解决方法: 先选中 ...

最新文章

  1. Objective-C中的一些特殊的数据类型
  2. IOS开发之----异常处理
  3. java 读取使用keytool生产的keystore文件
  4. Wireshark coloring rules tips
  5. 斩获双奖 | 悬镜安全亮相IDC 2022 CSO全球网络安全峰会
  6. 电脑重启命令c语言,命令提示符重启电脑_命令提示符 重启
  7. 平面束方程少一个面的原因
  8. SAS学习笔记27 卡方检验
  9. 计算机网络:计算路由表下一跳
  10. 推荐一款前端轻量级的toolTip插件-Tippy.js
  11. 使用Springboot+Feign Clients快速搭建REST客户端应用
  12. msm8909 android5.1.1,MSM8909+Android5.1.1启动流程(1)---概述
  13. c语言口语评分系统,FCE口语评分标准:考官更喜欢这样的考生
  14. 使用pyBigWig模块查看bigwig文件中的内容
  15. 小米手机miui12稳定版蓝牙时断不稳定的解决办法。
  16. ES Module和CommonJS的区别
  17. 140版本 boost_看完这篇,相信对UB4.0 boost这双鞋你会有新的感受!
  18. 论文查重网站要怎么选?
  19. 通信算法之九十四:4G LTE通信系统 PBCH/PCFICH/PHICH信道处理流程
  20. 同城外卖APP开发高级功能详情

热门文章

  1. InteractiveGraph 实现酷炫关系图谱之前瞻
  2. 虚拟中央处理器新星软机公司即将被收购
  3. NodeJS是用来做什么的
  4. 如何安装或卸载 Internet Explorer 9?
  5. string Format转义大括号
  6. P1759 通天之潜水(不详细,勿看)(动态规划递推,组合背包,洛谷)
  7. ElasticSearch(3)-安装kibana
  8. 日志——Vue.js开发在线简历生成器
  9. Android--SoundPool
  10. 《马哥教育协办GIAC、GOPS顶级技术峰会完美落幕》