主菜 Form from1一个 配菜 PictureBox pictureBox1 一个 香料 如下代码一堆 //呵~想加赏多少分?哈` public partial class Form1 : Form { string fileName = string.Empty; public Form1() { InitializeComponent(); this.Load += new EventHandler(Form1_Load); this.DragEnter += new DragEventHandler(Form1_DragEnter); this.DragDrop += new DragEventHandler(Form1_DragDrop); } void Form1_Load(object sender, EventArgs e) { this.AllowDrop = true; } void Form1_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.All; else e.Effect = DragDropEffects.None; } void Form1_DragDrop(object sender, DragEventArgs e) { //获取第一个文件名 fileName = (e.Data.GetData(DataFormats.FileDrop, false) as String[])[0]; try { this.pictureBox1.ImageLocation = fileName; } catch (Exception) { MessageBox.Show("文件格式不对"); } } } //当前鼠标坐标 //MousePosition.X //MousePosition.Y //你可以在MouseDonw和MouseUp分别记录一下坐标值就可以了 //关于绘制 Graphics gc = this.CreateGraphics(); //得到当前的gc gc.DrawLine(new Pen(Color.Red, 10), 100, 100, 200, 200); //画一条宽20的红线,位置在 100,100开始画到200,200 Graphics还有很多其它画圆啊~画框啊很多方法的~ 可以去MSDN查Graphice类得到你想要的资料
C# 从硬盘托图片在picturebox中打开
最新推荐文章于 2018-08-11 15:56:10 发布