473,383 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Doubt for number generation 1

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.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

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.LighButton;

public CELLMODE CellMode
{
get { return _CellMode; }
set
{
_CellMode = value;
switch (_CellMode)
{
case CELLMODE.DarkButton:
this.BackgroundImage = global::Sudoku.Properties.Resources.SudokuCell01;
break;

case CELLMODE.LighButton:
this.BackgroundImage = global::Sudoku.Properties.Resources.SudokuCell02;
break;

case CELLMODE.ProtectedButton:
this.BackgroundImage = global::Sudoku.Properties.Resources.SudokuCell00;
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.ToString();
ClearNotes();
}
this.Refresh();
}
}

public int ID
{
get { return _ID; }
set { _ID = value; }
}

public SudokuCell()
{
InitializeComponent ();
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.Transparent;
Notes[i].ForeColor = System.Drawing.Color.FromArgb(64,64,64);
Notes[i].Font = new System.Drawing.Font("Georgia", 8F, ((System.Drawing.FontStyle)((System.Drawing.FontSt yle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((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.Hand;
Notes[i].Visible = false ;
Notes[i].MouseUp += new MouseEventHandler (NotesClick);
Notes[i].MouseEnter += new EventHandler(this.NotesMouseEnter);
Notes[i].MouseLeave += new EventHandler(this.NotesMouseLeave);
this.Controls.Add(Notes[i]);
}
}

public void Display()
{
this.Visible = true;
this.Refresh();
}

private void lblCaption_MouseUp (object sender, MouseEventArgs e)
{
if (this.CellMode == CELLMODE.ProtectedButton)
{
return;
}

if (e.Button == MouseButtons.Left)
{
LeftClick (ID);
}
else
{
RightClick (ID);
}
}

private void SudokuCell_MouseUp (object sender, MouseEventArgs e)
{
if (this.CellMode == CELLMODE.ProtectedButton)
{
return;
}

if (e.Button == MouseButtons.Left)
{
LeftClick (ID);
}
else
{
RightClick (ID);
}
}

private void NotesClick (Object sender, MouseEventArgs e)
{
Label X = (Label)sender;

this.SuspendLayout();
if (e.Button == MouseButtons.Left)
{
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.ResumeLayout(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.ProtectedButton)
{
return;
}

if (NotesCount >= 0 && NotesCount < Notes.Length)
{
for (int i = 0; i < Notes.Length-1; i++)
{
if (Convert.ToInt16(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.ToString();
Caption = 0;
NotesCount++;
ShowNotes();
return ;
}
}
Notes[Notes.Length-1].Text = NewNote.ToString();
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.Transparent;
X.ForeColor = System.Drawing.Color.FromArgb(64, 64, 64);
}
}
}
Mar 25 '08 #1
1 909
r035198x
13,262 8TB
What happens when you run it?
Does it give you the correct results?
Mar 25 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Max M | last post by:
Yesterday there was an article on Slashdot: http://books.slashdot.org/article.pl?sid=03/09/04/1415210&mode=flat&tid=108&tid=126&tid=156 It is about automatic code generation. I got interrested...
0
by: Rasmus Fogh | last post by:
Someone raised the question of automatic code generation a few weeks back. And yes, we (CCPN) are using automatic Python code generation in a major way. Basically we are making data models in...
10
by: Ioannis Vranos | last post by:
I want to create some random numbers for encryption purposes, and i wonder if the following scheme makes it more hard to guess the underneath number generation pattern, than the plain use of...
4
by: Dimos | last post by:
Hello All, I need some help with random number generation. What I need exactly is: To create a few thousand numbers, decimal and integers, between 5 and 90, and then to export them as a...
2
by: robertoviperbr | last post by:
Hello to everybody. I have a doubt see the code: #include <vector> #include <iostream> #include <string> #include <algorithm> #include <sstream> #include <fstream> #include <iomanip>
22
by: gagan.singh.arora | last post by:
Hi there. I want to generate random numbers with a given probability, say 80% even and 20% odd. Is it possible to implement such an algorithm in C?
21
by: chico_yallin | last post by:
I just wana make a random id number based on4 digits-for examples?? Thanks in Advance Ch.Yallin
16
by: jason.cipriani | last post by:
I am looking for a random number generator implementation with the following requirements: - Thread-safe, re-entrant. - Produces consistently reproducible sequences of psuedo-random numbers...
6
by: Fan924 | last post by:
How do I add random number generation to this background image slide show? Everything I try kills if. TIA _____________________________________ <html> <head> <meta http-equiv="Content-Type"...
13
by: Rajshekhar | last post by:
Hi Group, I woud like to know how can i store a number generated out of 2 to power of 150 i.e pow(2,150); mainly i want to knw how can i get the value a large powers of a number....! ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.