需要帮助调用方法

时间:2013-09-06 17:32:59

标签: c# winforms methods

我正在尝试将图片上传到winform,然后显示缩略图。我尝试将功能添加到我的btnUpload_click方法,但它不允许我将PaintEventArgs设置为eventhandler。所以为了解决这个问题,我创建了另一种方法,但现在需要知道如何调用它。

private void btnUpload_Click(object sender, EventArgs e)
{}

public void getImage(PaintEventArgs ex)
{
    Image.GetThumbnailImageAbort myCallback =
    new Image.GetThumbnailImageAbort(ThumbnailCallback);

    OpenFileDialog open = new OpenFileDialog();
    // image filters
    open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
    if (open.ShowDialog() == DialogResult.OK)
    {
        // display image in picture box
        upload = new Bitmap(open.FileName);

        pictureBox1.Image.GetThumbnailImage(114, 108, myCallback, IntPtr.Zero);
        ex.Graphics.DrawImage(upload, 150, 75);
    }
}

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

PaintEventArgs个实例不需要Graphics。只需更改代码即可在按钮内单击:

Image.GetThumbnailImageAbort myCallback =
    new Image.GetThumbnailImageAbort(ThumbnailCallback);

OpenFileDialog open = new OpenFileDialog();

// image filters
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
    // display image in picture box
    upload = new Bitmap(open.FileName);

    pictureBox1.Image.GetThumbnailImage(114, 108, myCallback, IntPtr.Zero);
    this.CreateGraphics().DrawImage(upload, 150, 75);
}