I've been tasked with writing a windows form application that offers some options to modify the drawing of shapes within another window. I have very little experience with event-driven programming and I'd like to improve my skill.
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GDIDrawer;
namespace ICA3
{
public enum ShapeType
{
Square,
Circle
};
public partial class master : Form
{
const int _HEIGHT = 600;
const int _WIDTH = 800;
const int _SIZE = 50;
Color DEFAULT_COLOR = Color.Red;
Color CURRENT_COLOR;
CDrawer dr = new CDrawer(_WIDTH, _HEIGHT);
shapeform sf = new shapeform();
public master()
{
InitializeComponent();
}
private void master_btn_start_Click(object sender, EventArgs e)
{
CURRENT_COLOR = DEFAULT_COLOR;
master_timer.Start();
}
private void master_btn_stop_Click(object sender, EventArgs e)
{
master_timer.Stop();
}
private void master_btn_color_Click(object sender, EventArgs e)
{
using (ColorDialog cd = new ColorDialog())
{
if (cd.ShowDialog() == DialogResult.OK)
{
CURRENT_COLOR = cd.Color;
}
}
}
private void master_btn_shape_Click(object sender, EventArgs e)
{
sf.ShowDialog();
}
private void master_timer_Tick(object sender, EventArgs e)
{
Point pt = new Point();
//borders
if (sf._BORDER)
{
if (sf.shape == ShapeType.Circle)
{
if (dr.GetLastMouseLeftClick(out pt))
{
dr.AddCenteredEllipse(pt, _SIZE, _SIZE, CURRENT_COLOR, 1, Color.White);
}
}
else if (sf.shape == ShapeType.Square)
{
if (dr.GetLastMouseLeftClick(out pt))
{
dr.AddCenteredRectangle(pt, _SIZE, _SIZE, CURRENT_COLOR, 1, Color.White);
}
}
}
//no borders
else
{
if (sf.shape == ShapeType.Circle)
{
if (dr.GetLastMouseLeftClick(out pt))
{
dr.AddCenteredEllipse(pt, _SIZE, _SIZE, CURRENT_COLOR);
}
}
else if (sf.shape == ShapeType.Square)
{
if (dr.GetLastMouseLeftClick(out pt))
{
dr.AddCenteredRectangle(pt, _SIZE, _SIZE, CURRENT_COLOR);
}
}
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ICA3
{
public partial class shapeform : Form
{
ShapeType _SHAPE;
public bool _BORDER = false;
public ShapeType shape
{
get { return _SHAPE; }
}
public bool BorderChecked
{
get { return shapeform_cb_border.Checked; }
}
public shapeform()
{
InitializeComponent();
}
private void shapeform_btn_ok_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
}
private void shapeform_btn_cancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void shapeform_cb_border_CheckedChanged(object sender, EventArgs e)
{
_BORDER = shapeform_cb_border.Checked;
}
private void shapeform_rb_circle_CheckedChanged(object sender, EventArgs e)
{
_SHAPE = ShapeType.Circle;
}
private void shapeform_rb_square_CheckedChanged(object sender, EventArgs e)
{
_SHAPE = ShapeType.Square;
}
}
}
I'm trying to learn the best practices in C# and Windows forms, so tips are much appreciated.