System.Drawing
-
Hello, recently I have been toying around with the System.Drawing namespace. But it does not seem that it ever updates even if it is in an onPaint event handler. This is all the code i put in the entire class. I changed nothing else.
public partial class Form1 : Form
{
int Cheese = 1;
public Form1()
{
InitializeComponent();
}private void Form1\_Paint(object sender, PaintEventArgs e) { //initiate Graphics MyGraphics = e.Graphics; //Brush Brush MyBrush = Brushes.Aqua; //Font Font MyFont = new Font(FontFamily.GenericSansSerif, 12); //show text MyGraphics.DrawString(System.Convert.ToString(Cheese), MyFont, MyBrush, 10, 10); //make string higher Cheese = Cheese + 1; } }
What should i be doing? (The output is constantly "1") Thanks.:)
-
Hello, recently I have been toying around with the System.Drawing namespace. But it does not seem that it ever updates even if it is in an onPaint event handler. This is all the code i put in the entire class. I changed nothing else.
public partial class Form1 : Form
{
int Cheese = 1;
public Form1()
{
InitializeComponent();
}private void Form1\_Paint(object sender, PaintEventArgs e) { //initiate Graphics MyGraphics = e.Graphics; //Brush Brush MyBrush = Brushes.Aqua; //Font Font MyFont = new Font(FontFamily.GenericSansSerif, 12); //show text MyGraphics.DrawString(System.Convert.ToString(Cheese), MyFont, MyBrush, 10, 10); //make string higher Cheese = Cheese + 1; } }
What should i be doing? (The output is constantly "1") Thanks.:)
Call Invalidate() to force a paint event, in a button handler, and it will work. Use Cheese.ToString() instead of Convert.ToString. Or " " + Cheese, will also work.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Hello, recently I have been toying around with the System.Drawing namespace. But it does not seem that it ever updates even if it is in an onPaint event handler. This is all the code i put in the entire class. I changed nothing else.
public partial class Form1 : Form
{
int Cheese = 1;
public Form1()
{
InitializeComponent();
}private void Form1\_Paint(object sender, PaintEventArgs e) { //initiate Graphics MyGraphics = e.Graphics; //Brush Brush MyBrush = Brushes.Aqua; //Font Font MyFont = new Font(FontFamily.GenericSansSerif, 12); //show text MyGraphics.DrawString(System.Convert.ToString(Cheese), MyFont, MyBrush, 10, 10); //make string higher Cheese = Cheese + 1; } }
What should i be doing? (The output is constantly "1") Thanks.:)
It's because the window only paints itself once unless there's reason to repaint it again. For example, the number should increase if you hide the window (maybe minimize it), then reshow the window. It will have repainted a number of times. FYI, you can force a paint in code using the Invalidate() method of the Form class. Invalidate tells the operating system that a repaint is needed, and it will repaint at the next opportunity.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Christian Zionism as seen from a Jewish perspective The apostle Paul, modernly speaking: Epistles of Paul Judah Himango