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
sing System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace GraphCApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
int i=0, x, y;
String s = "";
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
///
public void mouseDownForm(object sender, System.Windows.Forms.MouseEventArgs e)
{
Font f;
SolidBrush br;
Pen pn;
Rectangle rct;
switch(e.Button)
{
case MouseButtons.Left:
x = e.X;
y = e.Y;
i++;
s = i.ToString();
//Graphics g = Graphics.FromHwnd(this.Handle);
Graphics g = CreateGraphics();
//Draw(g);
//g.FillRectangle(new SolidBrush(this.BackColor), this.ClientRectangle);
f = new Font("Arial", 14);
br = new SolidBrush(Color.Red);
pn = new Pen(Color.GreenYellow);
rct = new Rectangle(e.X, e.Y, 50, 50);
g.DrawEllipse(pn, rct);
g.DrawString(s, f, br, rct);
//MessageBox.Show(this, "click stanga");
break;
case MouseButtons.Right:
/*if (RightClick != null)
{
RightClick(sender, e);
}*/
MessageBox.Show(this, "click dreapta");
break;
}
}
/*public void Draw(Graphics g)
{
Rectangle r = new Rectangle(x, y, 20, 20);
g.DrawEllipse(new Pen(Color.Coral), r);
g.DrawString(s, new Font("Arial", 10), new SolidBrush(Color.Coral), r);
}*/
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.mouseDownForm);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}