I'm making a text game with a solar clock that will be drawn to a panel during run-time. I've noticed that I can't exactly just reference the panel (even after making it public) and call DrawEllipse() directly from another class. I will need to update the position of the circle being drawn during run-time, and I'm not exactly sure how to pass in information to panel_Paint().
what I'd like to do is this:
public Class Circle
{
public void Draw()
Graphics g = panel.CreateGraphics();
Pen p = new Pen(Color.White);
g.DrawEllipse(p,100,100,50,50);
{
I have panel set to public so I can access it. This had failed me, so I tried going with:
public partial class Form : System.Windows.Forms.Form
{
public Form()
{
InitializeComponent();
}
public void DrawCircle()
{
Graphics g = panel1.CreateGraphics();
Pen p = new Pen(Color.White);
g.DrawEllipse(p, 100, 100, 50, 50);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void gameText_TextChanged(object sender, EventArgs e)
{
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
}
and then calling DrawCircle() from main(), but this had also lead to more failure. yay... so I tried again with:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form game = new Form();
var t = new Vec(1, 1);
var m = +t;
Clock c = new Clock();
Graphics g = game.panel1.CreateGraphics();
game.DrawCircle();
game.gameText.Text = m.ToString("0.#####");
Application.Run(game);
}
and still doesn't work. so I tried accessing panel from my Utils class, can't do that, I've tried pulling the game variable out of the main class, can't do that, I've tried making it public, and I can't do that. I'm seriously at a loss here. any ideas or suggestions would be greatly appreciated.
EDIT: I've looked into the similar post here, but I have no idea where to declare panel1.Paint += new PaintEventHandler(panel1_Paint);
like, where can I put it, and how do I use it in the external classes. It says in the constructor, but constructor of what class? the one that sends the draw information? or some other class? some clarification on the proper implementation of what was described.