circles erased ??

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2007
Posts: 31
Reputation: claudiu_is is an unknown quantity at this point 
Solved Threads: 1
claudiu_is's Avatar
claudiu_is claudiu_is is offline Offline
Light Poster

circles erased ??

 
0
  #1
Nov 10th, 2007
Hello, first you need to know that this is my first Win Application made in C#!!

I`m trying to draw some circles based on mouse left click coordinates but the circles disappear when I minimize the window, Solutions found on the internet didn`t helped me too much . Here is my code:

u
  1. sing System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7.  
  8.  
  9. namespace GraphCApplication1
  10. {
  11. /// <summary>
  12. /// Summary description for Form1.
  13. /// </summary>
  14. public class Form1 : System.Windows.Forms.Form
  15. {
  16. int i=0, x, y;
  17. String s = "";
  18. /// <summary>
  19. /// Required designer variable.
  20. /// </summary>
  21. private System.ComponentModel.Container components = null;
  22.  
  23. public Form1()
  24. {
  25. //
  26. // Required for Windows Form Designer support
  27. //
  28. InitializeComponent();
  29.  
  30.  
  31. //
  32. // TODO: Add any constructor code after InitializeComponent call
  33. //
  34. }
  35.  
  36. /// <summary>
  37. /// Clean up any resources being used.
  38. /// </summary>
  39. protected override void Dispose( bool disposing )
  40. {
  41. if( disposing )
  42. {
  43. if (components != null)
  44. {
  45. components.Dispose();
  46. }
  47. }
  48. base.Dispose( disposing );
  49. }
  50. protected override void OnPaint(PaintEventArgs e)
  51. {
  52. base.OnPaint (e);
  53. }
  54.  
  55. #region Windows Form Designer generated code
  56. /// <summary>
  57. /// Required method for Designer support - do not modify
  58. /// the contents of this method with the code editor.
  59. /// </summary>
  60. ///
  61. public void mouseDownForm(object sender, System.Windows.Forms.MouseEventArgs e)
  62. {
  63. Font f;
  64. SolidBrush br;
  65. Pen pn;
  66. Rectangle rct;
  67.  
  68. switch(e.Button)
  69. {
  70. case MouseButtons.Left:
  71.  
  72. x = e.X;
  73. y = e.Y;
  74. i++;
  75. s = i.ToString();
  76. //Graphics g = Graphics.FromHwnd(this.Handle);
  77. Graphics g = CreateGraphics();
  78. //Draw(g);
  79. //g.FillRectangle(new SolidBrush(this.BackColor), this.ClientRectangle);
  80. f = new Font("Arial", 14);
  81. br = new SolidBrush(Color.Red);
  82. pn = new Pen(Color.GreenYellow);
  83. rct = new Rectangle(e.X, e.Y, 50, 50);
  84. g.DrawEllipse(pn, rct);
  85. g.DrawString(s, f, br, rct);
  86.  
  87. //MessageBox.Show(this, "click stanga");
  88. break;
  89. case MouseButtons.Right:
  90. /*if (RightClick != null)
  91. {
  92. RightClick(sender, e);
  93. }*/
  94. MessageBox.Show(this, "click dreapta");
  95. break;
  96. }
  97. }
  98. /*public void Draw(Graphics g)
  99. {
  100. Rectangle r = new Rectangle(x, y, 20, 20);
  101. g.DrawEllipse(new Pen(Color.Coral), r);
  102. g.DrawString(s, new Font("Arial", 10), new SolidBrush(Color.Coral), r);
  103. }*/
  104. private void InitializeComponent()
  105. {
  106. this.components = new System.ComponentModel.Container();
  107. this.Size = new System.Drawing.Size(300,300);
  108. this.Text = "Form1";
  109. this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.mouseDownForm);
  110. }
  111. #endregion
  112.  
  113. /// <summary>
  114. /// The main entry point for the application.
  115. /// </summary>
  116. [STAThread]
  117. static void Main()
  118. {
  119. Application.Run(new Form1());
  120. }
  121. }
  122. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 30
Reputation: InfiNate is an unknown quantity at this point 
Solved Threads: 6
InfiNate InfiNate is offline Offline
Light Poster

Re: circles erased ??

 
0
  #2
Nov 12th, 2007
What I would do is create a data structure to keep track of the places you have clicked and any corresponding info you need, then when the form is minimized/maximized/given focus/whatever else, redraw all the circles.

What i think is happening, is the form 'forgets' whats been drawn when you minimize it, not sure about this as I'm no expert, but storing what you need and re-drawing when required should fix it.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,607
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 130
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: circles erased ??

 
0
  #3
Nov 12th, 2007
Actually, I think you need to put the code
  1. this.Invalidate()
in the minimized event handler or similar.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 30
Reputation: InfiNate is an unknown quantity at this point 
Solved Threads: 6
InfiNate InfiNate is offline Offline
Light Poster

Re: circles erased ??

 
0
  #4
Nov 12th, 2007
Originally Posted by scru View Post
Actually, I think you need to put the code
  1. this.Invalidate()
in the minimized event handler or similar.
Looks like invalidate will solve this problem. There's always an easier way to do it
My solution would work, its just needlessly complicated.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC