C# 从硬盘托图片在picturebox中打开

主菜 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类得到你想要的资料
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值