TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
srinath
NA
144
0
numberpad using delegates and events
Aug 31 2009 7:08 AM
hi,
I am trying to a write a code for a numberpad which is useful for both Calculator and Mobile phone using delegates and events. Here each operation is treated separately like addition(also other math operations) is treated as one event, likewise,Character, number and Equalto is treated as another events. The approriate event should raise whenever the button keypress action is done.This should be done using C# Windows Application in .net 2.0.
I did for number event, but stucked in between for math operations and character events( here the action is like typing sms in a mobile phone).
Till now I tried like this..
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Drawing;
using
System.Data;
using
System.Text;
using
System.Windows.Forms;
namespace
NumberPad
{
public
partial
class
UserControl1
:
UserControl
{
public
UserControl1()
{
InitializeComponent();
}
public
delegate
void
NumberArgumentHandle
(
object
source,
NumberArgs
args);
public
delegate
void
MathOperationHandler
(
object
sender,
Math
m);
// public delegate void EqualtoHandler(object sender, EventArgs e);
public
delegate
void
CharacterArgumentHandler
(
object
sender,
EventArgs
e );
public
object
key =
new
object
();
public
event
NumberArgumentHandle
NumberSelected
{
add
{
Events.AddHandler(key,
value
);
}
remove
{
Events.RemoveHandler(key,
value
);
}
}
public
event
MathOperationHandler
op
{
add
{
Events.AddHandler(key,
value
);
}
remove
{
Events.RemoveHandler(key,
value
);
}
}
public
event
CharacterArgumentHandler
c
{
add
{
Events.AddHandler(key,
value
);
}
remove
{
Events.RemoveHandler(key,
value
);
}
}
private
void
btn_key(
object
sender,
KeyPressEventArgs
e)
{
int
x =
int
.MaxValue;
int
.TryParse((sender
as
Button
).Text,
out
x);
if
(x !=
int
.MaxValue)
{
NumberArgs
args =
new
NumberArgs
(
Convert
.ToInt32((sender
as
Button
).Text));
RaiseEvent(args);
}
// for storing first number
}
private
void
RaiseEvent(
NumberArgs
args)
{
if
(Events[key] !=
null
)
{
(Events[key]
as
NumberArgumentHandle
)(
this
, args);
}
}
/* private void RaiseEvent(Math m)
{
if (Events[key] != null)
{
(Events[key] as MathOperationHandler)(this, m);
}
}*/
// calculator controls.
private
double
Additions(
double
value1,
double
value2)
{
return
(value1 + value2);
}
/*private int Additions(int value1, int value2)
{
return (value1 + value2);
}*/
private
double
Subtraction(
double
value3,
double
value4)
{
return
(value3 - value4);
}
/* private double Subtraction(int value1, int value2)
{
return (value1 - value2);
}*/
private
double
Multiplication(
double
value5,
double
value6)
{
return
(value5 * value6);
}
/* private double Multiplication(int value1, int value2)
{
return (value1 * value2);
}*/
private
double
Division(
double
value7,
double
value8)
{
return
(value7 * value8);
}
/* private double Division(int value1, int value2)
{
return (value1 * value2);
}*/
// cell controls.
}
public
class
NumberArgs
:
EventArgs
{
int
number =
int
.MaxValue;
public
NumberArgs(
int
number)
{
this
.number = number;
}
public
int
Number
{
get
{
return
number;}
}
}
}
Please help me....
Reply
Answers (
1
)
how to use undocumented dll?
compare the status of network card at every startup