Adam Turner

Adam Turner

  • NA
  • 60
  • 0

Painting textures to a windows form

Aug 22 2007 1:29 AM

I'm trying to get a library I found for using XNA textures on a Windows Form to work. I had it working in a datagridview, but now I'm trying to do the same thing on the windows form itself and I'm running into problems as I'm a novice C# programmer.

Here's what I've got so far:

private void RefreshButton_Click(object sender, EventArgs e)

{

ManageTreeview();

this.Paint += new PaintEventHandler(MainForm_Paint);

this.CreateGraphics();

}

private void MainForm_Paint(object sender,

System.Windows.Forms.PaintEventArgs e)

{

string filePath = Path.Combine(Environment.CurrentDirectory, Path.Combine("Content", Path.Combine("Textures", "racer.dds")));

Image img = XNAGDIImageLoader.LoadImageFromFile(filePath, this.Handle);

e.Graphics.DrawImage(img, new RectangleF(500, 500, img.Width, img.Height) );

}

The refresh button just calls the repainting done in MainForm_Paint. I haven't the foggiest clue however as to how I get my img to paint on the form. The this.CreateGraphics() doesn't seem to be doing anything, and I tried this.Invalidate, but that didn't seem to do anything either.


Answers (2)