C# WinForms problem with draw image

Posted by Paul on Stack Overflow See other posts from Stack Overflow or by Paul
Published on 2010-03-29T13:41:46Z Indexed on 2010/03/29 13:53 UTC
Read the original article Hit count: 538

Filed under:
|
|

Hi I have this class:

class OriginalImage: Form
{
    private Image image;
    private PictureBox pb;

    public OriginalImage()
    {
        pb = new PictureBox {SizeMode = PictureBoxSizeMode.CenterImage};
        pb.SizeMode = PictureBoxSizeMode.StretchImage;

        Controls.Add(pb);

        image = Image.FromFile(@"Image/original.jpg");

        this.Width = image.Width;
        this.Height = image.Height;

        this.Text = "Original image";
        this.Paint += new PaintEventHandler(Drawer);
    }

    public virtual void Drawer(object source, PaintEventArgs e)
    {
        Graphics g = pb.CreateGraphics();
        g.DrawImage(image,0,0);
    }

I call this create object OriginalImage in other form on button click, but image is not draw? Where is problem?

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        var oi = new OriginalImage();
        oi.Show();
    }
}

© Stack Overflow or respective owner

Related posts about graphics

Related posts about c#