EDIT: This is not a duplicate of "How to use the OnPaint event in C#" because I didn't even know it existed. I am asking a question, when I don't know the answer. It's like asking "How do I check oil in my car" when i don't even know what a dip stick is. Please remove the duplicate sign if this edits it in a way that explains why it is not a duplicate.
I am trying to make a random terrain generator. At the moment, I am using Windows Forms Graphics to draw it all. I can't seem to get the engine to work. The following code ran does not display anything on the form, even though it should draw a black rectangle from 0,0 to 50,50. Can anyone solve?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Random_Terrain_Generator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Engine e = new Engine(100, 100);
e.Color3(Color.Blue);
e.rect(new Rectangle(0,0,50,50));
Graphics fg = this.CreateGraphics();
fg.DrawImage(e.getBuffer(), 1, 100, 100, 100);
}
}
public class Engine
{
Color fillColor;
Bitmap buffer;
Graphics bufferGraphics;
public Engine(int bufferWidth, int bufferHeight)
{
buffer = new Bitmap(bufferWidth, bufferHeight);
bufferGraphics = Graphics.FromImage(buffer);
}
public void fRect(Rectangle r)
{
bufferGraphics.FillRectangle(new SolidBrush(fillColor), r);
}
public void rect(Rectangle r)
{
bufferGraphics.DrawRectangle(new Pen(fillColor), r);
}
public void Color3(Color c)
{
fillColor = c;
}
public Bitmap getBuffer()
{
return buffer;
}
}
}