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. BOOL FLAG Problem in Paint Handler

BOOL FLAG Problem in Paint Handler

Scheduled Pinned Locked Moved C#
helpquestiongraphics
4 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.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    I have code that will draw a line on a form. When I hard code it to draw the line it works fine, meaning every time the form launches a line is drawn. Now i want to set a bool flag and pass it in as a conditional statement to drawn the line when the Button1 is clicked. I know I'm missing something obvious. public class Form1 : System.Windows.Forms.Form { //Member fields. private bool drawLine1 = false;..............etc /////////////////////////////////////////////////////////////////////////// private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { if(drawLine1) //DRAW LINE 1 IS ALWAYS FALSE..... DrawComplexNumber(e.Graphics);.............etc ////////////////////////////////////////////////////////////////////////// private void Button_1OK_Click(object sender, System.EventArgs e) { drawLine1 = !drawLine1; Invalidate(); } How do I fix it? Please -- need a "nuts and bolts" answer, not an "abstract" explanation. Thanks a lot in advance....

    R M 2 Replies Last reply
    0
    • A Anonymous

      I have code that will draw a line on a form. When I hard code it to draw the line it works fine, meaning every time the form launches a line is drawn. Now i want to set a bool flag and pass it in as a conditional statement to drawn the line when the Button1 is clicked. I know I'm missing something obvious. public class Form1 : System.Windows.Forms.Form { //Member fields. private bool drawLine1 = false;..............etc /////////////////////////////////////////////////////////////////////////// private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { if(drawLine1) //DRAW LINE 1 IS ALWAYS FALSE..... DrawComplexNumber(e.Graphics);.............etc ////////////////////////////////////////////////////////////////////////// private void Button_1OK_Click(object sender, System.EventArgs e) { drawLine1 = !drawLine1; Invalidate(); } How do I fix it? Please -- need a "nuts and bolts" answer, not an "abstract" explanation. Thanks a lot in advance....

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      The code seems to be ok but I noticed that your button click eventhandler has a strange name. You should probably check if the click event of the button is really bound to that method. Just check (eg by setting a brakepoint) if the drawLine1 = !drawLine1 is being hit and if drawLine1 has the correct contents afterwards. Then check if you prpbably set drawLine1 back to false somewhere else in your code. Doing some Console.WriteLine("DrawLine1: " + drawLine1.ToString()) here and there should also help you to trace down the problem. Hope you don't feel this answer is abstract but if you test this code in an empty form you will see that it works and that the error must come from somewhere else.

      A 1 Reply Last reply
      0
      • R Robert Rohde

        The code seems to be ok but I noticed that your button click eventhandler has a strange name. You should probably check if the click event of the button is really bound to that method. Just check (eg by setting a brakepoint) if the drawLine1 = !drawLine1 is being hit and if drawLine1 has the correct contents afterwards. Then check if you prpbably set drawLine1 back to false somewhere else in your code. Doing some Console.WriteLine("DrawLine1: " + drawLine1.ToString()) here and there should also help you to trace down the problem. Hope you don't feel this answer is abstract but if you test this code in an empty form you will see that it works and that the error must come from somewhere else.

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        You were absoutely right. Thought I was going nuts-- thanks works fine now

        1 Reply Last reply
        0
        • A Anonymous

          I have code that will draw a line on a form. When I hard code it to draw the line it works fine, meaning every time the form launches a line is drawn. Now i want to set a bool flag and pass it in as a conditional statement to drawn the line when the Button1 is clicked. I know I'm missing something obvious. public class Form1 : System.Windows.Forms.Form { //Member fields. private bool drawLine1 = false;..............etc /////////////////////////////////////////////////////////////////////////// private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { if(drawLine1) //DRAW LINE 1 IS ALWAYS FALSE..... DrawComplexNumber(e.Graphics);.............etc ////////////////////////////////////////////////////////////////////////// private void Button_1OK_Click(object sender, System.EventArgs e) { drawLine1 = !drawLine1; Invalidate(); } How do I fix it? Please -- need a "nuts and bolts" answer, not an "abstract" explanation. Thanks a lot in advance....

          M Offline
          M Offline
          Mahesh Kumar V K
          wrote on last edited by
          #4

          Try out this code as an example - public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; private bool drawline = false; private int radius = 25; private int green = 10; private int red = 10; private int blue = 10; } private void Button_1OK__Click(object sender, System.EventArgs e) { drawline = !drawline; Random r = new Random(100); Int32 x = Int32.Parse(r.Next().ToString().Substring(1,2)); Int32 y = Int32.Parse(r.Next().ToString().Substring(1,3)); if (green < 230) green += 10; if (blue < 230) blue += 10; if (red < 230) red += 10; if (drawline) { System.Drawing.Graphics g = this.CreateGraphics(); Point P = new Point(x,100); Point p1 = new Point (100,y); Color j = Color.FromArgb(red,green,blue); Pen Pe = new Pen(j); g.DrawEllipse(Pe,x,x ,radius, radius); radius += 20; } else { System.Drawing.Graphics g = this.CreateGraphics(); Point P = new Point(x,100); Point p1 = new Point (100,y); Color j = Color.FromArgb(red,green,blue); Pen Pe = new Pen(j); g.DrawEllipse(Pe,y,y ,radius, radius); radius += 20; this.Refresh(); } } Regards Mahesh

          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