Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. System.Drawing

System.Drawing

Scheduled Pinned Locked Moved C#
graphicsquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dsl fahk
    wrote on last edited by
    #1

    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.:)

    C J 2 Replies Last reply
    0
    • D dsl fahk

      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.:)

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • D dsl fahk

        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.:)

        J Offline
        J Offline
        Judah Gabriel Himango
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups