943,937 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 1858
  • C# RSS
Nov 10th, 2007
0

circles erased ??

Expand Post »
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
C# Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
claudiu_is is offline Offline
40 posts
since Jul 2007
Nov 12th, 2007
0

Re: circles erased ??

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.
Reputation Points: 11
Solved Threads: 6
Light Poster
InfiNate is offline Offline
30 posts
since Nov 2007
Nov 12th, 2007
0

Re: circles erased ??

Actually, I think you need to put the code
C# Syntax (Toggle Plain Text)
  1. this.Invalidate()
in the minimized event handler or similar.
Featured Poster
Reputation Points: 975
Solved Threads: 140
Posting Virtuoso
scru is offline Offline
1,624 posts
since Feb 2007
Nov 12th, 2007
0

Re: circles erased ??

Click to Expand / Collapse  Quote originally posted by scru ...
Actually, I think you need to put the code
C# Syntax (Toggle Plain Text)
  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.
Reputation Points: 11
Solved Threads: 6
Light Poster
InfiNate is offline Offline
30 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: c# login trouble
Next Thread in C# Forum Timeline: Books





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC