HI all
I am writing a code for creating a cell with numbers one to nine three in
a row is there any problem with the following code?
using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows. Forms;
using System.Diagnost ics;
namespace Sudoku
{
public partial class SudokuCell : UserControl
{
public enum CELLMODE
{
LighButton = 1,
DarkButton = 2,
ProtectedButton = 3
}
public delegate void FLeftClick(int ID);
public delegate void FRightClick (int ID);
private FLeftClick _LeftClick;
private FRightClick _RightClick;
private CELLMODE _CellMode = CELLMODE.LighBu tton;
public CELLMODE CellMode
{
get { return _CellMode; }
set
{
_CellMode = value;
switch (_CellMode)
{
case CELLMODE.DarkBu tton:
this.Background Image = global::Sudoku. Properties.Reso urces.SudokuCel l01;
break;
case CELLMODE.LighBu tton:
this.Background Image = global::Sudoku. Properties.Reso urces.SudokuCel l02;
break;
case CELLMODE.Protec tedButton:
this.Background Image = global::Sudoku. Properties.Reso urces.SudokuCel l00;
break;
}
}
}
private int NotesCount = 0;
private int _Caption;
private int _ID;
private System.Windows. Forms.Label[] Notes = new Label[6];
public FLeftClick LeftClick
{
get { return _LeftClick; }
set { _LeftClick = value; }
}
public FRightClick RightClick
{
get { return _RightClick; }
set { _RightClick = value; }
}
public int Caption
{
get { return _Caption; }
set
{
_Caption = value;
if (_Caption == 0)
{
this.lblCaption .Text = "";
}
else
{
this.lblCaption .Text = _Caption.ToStri ng();
ClearNotes();
}
this.Refresh();
}
}
public int ID
{
get { return _ID; }
set { _ID = value; }
}
public SudokuCell()
{
InitializeCompo nent ();
CreateNotes();
}
private void CreateNotes()
{
int x, y;
for (int i = 0; i < Notes.Length ; i++)
{
Notes[i] = new Label();
Notes[i].AutoSize = false;
Notes[i].BackColor = System.Drawing. Color.Transpare nt;
Notes[i].ForeColor = System.Drawing. Color.FromArgb( 64,64,64);
Notes[i].Font = new System.Drawing. Font("Georgia", 8F, ((System.Drawin g.FontStyle)((S ystem.Drawing.F ontStyle.Bold | System.Drawing. FontStyle.Itali c))), System.Drawing. GraphicsUnit.Po int, ((byte)(0)));
if (i < 4)
{
x = i;
y = 0;
}
else
{
x = i - 4;
y = 15;
}
Notes[i].Location = new System.Drawing. Point(11*x, y);
Notes[i].Name = "Notes" + i.ToString();
Notes[i].Size = new System.Drawing. Size(12, 8);
Notes[i].TabIndex = 0;
Notes[i].Tag = i.ToString();
Notes[i].Text = "0";
Notes[i].Cursor = System.Windows. Forms.Cursors.H and;
Notes[i].Visible = false ;
Notes[i].MouseUp += new MouseEventHandl er (NotesClick);
Notes[i].MouseEnter += new EventHandler(th is.NotesMouseEn ter);
Notes[i].MouseLeave += new EventHandler(th is.NotesMouseLe ave);
this.Controls.A dd(Notes[i]);
}
}
public void Display()
{
this.Visible = true;
this.Refresh();
}
private void lblCaption_Mous eUp (object sender, MouseEventArgs e)
{
if (this.CellMode == CELLMODE.Protec tedButton)
{
return;
}
if (e.Button == MouseButtons.Le ft)
{
LeftClick (ID);
}
else
{
RightClick (ID);
}
}
private void SudokuCell_Mous eUp (object sender, MouseEventArgs e)
{
if (this.CellMode == CELLMODE.Protec tedButton)
{
return;
}
if (e.Button == MouseButtons.Le ft)
{
LeftClick (ID);
}
else
{
RightClick (ID);
}
}
private void NotesClick (Object sender, MouseEventArgs e)
{
Label X = (Label)sender;
this.SuspendLay out();
if (e.Button == MouseButtons.Le ft)
{
Caption = Convert.ToInt16 (X.Text);
ClearNotes();
}
else
{
int j = Convert.ToInt16 (X.Tag);
for (int i = j; i < Notes.Length-1; i++)
{
Notes[i].Text = Notes[i + 1].Text;
}
Notes[Notes.Length-1].Text = "0";
ShowNotes();
NotesCount--;
}
this.ResumeLayo ut(false);
}
public void ClearNotes()
{
if (NotesCount > 0)
{
for (int i = 0; i < Notes.Length; i++)
{
Notes[i].Text = "0";
}
ShowNotes();
NotesCount = 0;
}
}
public void AddNote(int NewNote)
{
if (this.CellMode == CELLMODE.Protec tedButton)
{
return;
}
if (NotesCount >= 0 && NotesCount < Notes.Length)
{
for (int i = 0; i < Notes.Length-1; i++)
{
if (Convert.ToInt1 6(Notes[i].Text) == NewNote)
{
return ;
}
else if (Notes[i].Text == "0" || Convert.ToInt16 (Notes[i].Text) > NewNote)
{
for (int j = Notes.Length-1; j > i; j--)
{
Notes[j].Text = Notes[j-1].Text;
}
Notes[i].Text = NewNote.ToStrin g();
Caption = 0;
NotesCount++;
ShowNotes();
return ;
}
}
Notes[Notes.Length-1].Text = NewNote.ToStrin g();
NotesCount++;
Caption = 0;
ShowNotes();
}
}
private void ShowNotes()
{
for (int i = Notes.Length-1; i >= 0; i--)
{
Notes[i].Visible = (Notes[i].Text != "0");
}
}
private void NotesMouseEnter (object sender, EventArgs e)
{
Label X = (Label)sender;
X.BackColor = System.Drawing. Color.Black;
X.ForeColor = System.Drawing. Color.Yellow;
}
private void NotesMouseLeave (object sender, EventArgs e)
{
Label X = (Label)sender;
X.BackColor = System.Drawing. Color.Transpare nt;
X.ForeColor = System.Drawing. Color.FromArgb( 64, 64, 64);
}
}
}
I am writing a code for creating a cell with numbers one to nine three in
a row is there any problem with the following code?
using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows. Forms;
using System.Diagnost ics;
namespace Sudoku
{
public partial class SudokuCell : UserControl
{
public enum CELLMODE
{
LighButton = 1,
DarkButton = 2,
ProtectedButton = 3
}
public delegate void FLeftClick(int ID);
public delegate void FRightClick (int ID);
private FLeftClick _LeftClick;
private FRightClick _RightClick;
private CELLMODE _CellMode = CELLMODE.LighBu tton;
public CELLMODE CellMode
{
get { return _CellMode; }
set
{
_CellMode = value;
switch (_CellMode)
{
case CELLMODE.DarkBu tton:
this.Background Image = global::Sudoku. Properties.Reso urces.SudokuCel l01;
break;
case CELLMODE.LighBu tton:
this.Background Image = global::Sudoku. Properties.Reso urces.SudokuCel l02;
break;
case CELLMODE.Protec tedButton:
this.Background Image = global::Sudoku. Properties.Reso urces.SudokuCel l00;
break;
}
}
}
private int NotesCount = 0;
private int _Caption;
private int _ID;
private System.Windows. Forms.Label[] Notes = new Label[6];
public FLeftClick LeftClick
{
get { return _LeftClick; }
set { _LeftClick = value; }
}
public FRightClick RightClick
{
get { return _RightClick; }
set { _RightClick = value; }
}
public int Caption
{
get { return _Caption; }
set
{
_Caption = value;
if (_Caption == 0)
{
this.lblCaption .Text = "";
}
else
{
this.lblCaption .Text = _Caption.ToStri ng();
ClearNotes();
}
this.Refresh();
}
}
public int ID
{
get { return _ID; }
set { _ID = value; }
}
public SudokuCell()
{
InitializeCompo nent ();
CreateNotes();
}
private void CreateNotes()
{
int x, y;
for (int i = 0; i < Notes.Length ; i++)
{
Notes[i] = new Label();
Notes[i].AutoSize = false;
Notes[i].BackColor = System.Drawing. Color.Transpare nt;
Notes[i].ForeColor = System.Drawing. Color.FromArgb( 64,64,64);
Notes[i].Font = new System.Drawing. Font("Georgia", 8F, ((System.Drawin g.FontStyle)((S ystem.Drawing.F ontStyle.Bold | System.Drawing. FontStyle.Itali c))), System.Drawing. GraphicsUnit.Po int, ((byte)(0)));
if (i < 4)
{
x = i;
y = 0;
}
else
{
x = i - 4;
y = 15;
}
Notes[i].Location = new System.Drawing. Point(11*x, y);
Notes[i].Name = "Notes" + i.ToString();
Notes[i].Size = new System.Drawing. Size(12, 8);
Notes[i].TabIndex = 0;
Notes[i].Tag = i.ToString();
Notes[i].Text = "0";
Notes[i].Cursor = System.Windows. Forms.Cursors.H and;
Notes[i].Visible = false ;
Notes[i].MouseUp += new MouseEventHandl er (NotesClick);
Notes[i].MouseEnter += new EventHandler(th is.NotesMouseEn ter);
Notes[i].MouseLeave += new EventHandler(th is.NotesMouseLe ave);
this.Controls.A dd(Notes[i]);
}
}
public void Display()
{
this.Visible = true;
this.Refresh();
}
private void lblCaption_Mous eUp (object sender, MouseEventArgs e)
{
if (this.CellMode == CELLMODE.Protec tedButton)
{
return;
}
if (e.Button == MouseButtons.Le ft)
{
LeftClick (ID);
}
else
{
RightClick (ID);
}
}
private void SudokuCell_Mous eUp (object sender, MouseEventArgs e)
{
if (this.CellMode == CELLMODE.Protec tedButton)
{
return;
}
if (e.Button == MouseButtons.Le ft)
{
LeftClick (ID);
}
else
{
RightClick (ID);
}
}
private void NotesClick (Object sender, MouseEventArgs e)
{
Label X = (Label)sender;
this.SuspendLay out();
if (e.Button == MouseButtons.Le ft)
{
Caption = Convert.ToInt16 (X.Text);
ClearNotes();
}
else
{
int j = Convert.ToInt16 (X.Tag);
for (int i = j; i < Notes.Length-1; i++)
{
Notes[i].Text = Notes[i + 1].Text;
}
Notes[Notes.Length-1].Text = "0";
ShowNotes();
NotesCount--;
}
this.ResumeLayo ut(false);
}
public void ClearNotes()
{
if (NotesCount > 0)
{
for (int i = 0; i < Notes.Length; i++)
{
Notes[i].Text = "0";
}
ShowNotes();
NotesCount = 0;
}
}
public void AddNote(int NewNote)
{
if (this.CellMode == CELLMODE.Protec tedButton)
{
return;
}
if (NotesCount >= 0 && NotesCount < Notes.Length)
{
for (int i = 0; i < Notes.Length-1; i++)
{
if (Convert.ToInt1 6(Notes[i].Text) == NewNote)
{
return ;
}
else if (Notes[i].Text == "0" || Convert.ToInt16 (Notes[i].Text) > NewNote)
{
for (int j = Notes.Length-1; j > i; j--)
{
Notes[j].Text = Notes[j-1].Text;
}
Notes[i].Text = NewNote.ToStrin g();
Caption = 0;
NotesCount++;
ShowNotes();
return ;
}
}
Notes[Notes.Length-1].Text = NewNote.ToStrin g();
NotesCount++;
Caption = 0;
ShowNotes();
}
}
private void ShowNotes()
{
for (int i = Notes.Length-1; i >= 0; i--)
{
Notes[i].Visible = (Notes[i].Text != "0");
}
}
private void NotesMouseEnter (object sender, EventArgs e)
{
Label X = (Label)sender;
X.BackColor = System.Drawing. Color.Black;
X.ForeColor = System.Drawing. Color.Yellow;
}
private void NotesMouseLeave (object sender, EventArgs e)
{
Label X = (Label)sender;
X.BackColor = System.Drawing. Color.Transpare nt;
X.ForeColor = System.Drawing. Color.FromArgb( 64, 64, 64);
}
}
}
Comment