Can anyone tell me why, when I click on the buttons it register 2
characters on the display?
if you use the right mousebutton it works ok, but the buttons dont
flash??
it works fine without the aqua buttons, (using just windows forms
buttons...
Main Form cs file
//----------------------------------------------------------------------------------------------------------------------
=============== =============== =============== =============== =
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
namespace Calculator
{
/// <summary>
/// Summary description for BFCMainForm.
/// </summary>
public class BFCMainForm : System.Windows. Forms.Form
{
private Wildgrape.Aqua. Controls.Button bttnD4;
private Wildgrape.Aqua. Controls.Button bttnD7;
private Wildgrape.Aqua. Controls.Button bttnD8;
private Wildgrape.Aqua. Controls.Button bttnD9;
private Wildgrape.Aqua. Controls.Button bttnD1;
private Wildgrape.Aqua. Controls.Button bttnD2;
private Wildgrape.Aqua. Controls.Button bttnD3;
private Wildgrape.Aqua. Controls.Button bttnD5;
private Wildgrape.Aqua. Controls.Button bttnD6;
private Wildgrape.Aqua. Controls.Button bttnD0;
private Wildgrape.Aqua. Controls.Button bttnDiv;
private Wildgrape.Aqua. Controls.Button bttnMul;
private Wildgrape.Aqua. Controls.Button bttnMinus;
private Wildgrape.Aqua. Controls.Button bttnPlus;
private Wildgrape.Aqua. Controls.Button bttnClr;
private Wildgrape.Aqua. Controls.Button bttnDot;
private Wildgrape.Aqua. Controls.Button bttnEqual;
private Wildgrape.Aqua. Controls.Button CalcBtnPwr;
private System.Windows. Forms.Label BFCDisplA;
private string BFCValue1;
// private string BFCValue2;
private ArrayList BFCArray1;
// private ArrayList BFCArray2;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components =
null;
public BFCMainForm()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
// Set the application title bar
Version ver = new
Version(Applica tion.ProductVer sion);
this.Text = String.Format(" BFC-2k4
{0:#}.{1:#}.{2: #}", ver.Major, ver.Minor,ver.B uild);
Icon = new
Icon(typeof(BFC MainForm), "DedHed.ico ");
//
// TODO: Add any constructor code after
InitializeCompo nent call
//
BFCValue1 = ""
;
BFCArray1 = new
ArrayList();
}
private void AddOperatorToAr ray(Button bttn)
{
BFCArray1.Add( BFCValue1 ) ;
BFCDisplA.Text +=
bttn.Text;
BFCValue1
= "";
BFCArray1.Add( bttn.Text );
bttnDot.Enabled = true ;
SetEnableOperat orBttns(false);
BFCDisplA.Text = "";
Invalidate();
}
private void AddToArray(Butt on bttn)
{
BFCValue1 = bttn.Text;
// somewhere in here
BFCDisplA.Text = bttn.Text;
// is the double # trouble
SetEnableOperat orBttns(true);
Invalidate();
}
private void Reset()
{
BFCValue1 = "";
BFCDisplA.Text = "";
BFCArray1.Clear () ;
bttnDot.Enabled = true;
}
private void SetEnableOperat orBttns(bool enable)
{
bttnPlus.Enable d = enable ;
bttnMinus.Enabl ed = enable ;
bttnMul.Enabled = enable ;
bttnDiv.Enabled = enable ;
bttnEqual.Enabl ed = enable ;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}
#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>
private void InitializeCompo nent()
{
System.Resource s.ResourceManag er resources =
new System.Resource s.ResourceManag er(typeof(BFCMa inForm));
this.bttnD1 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnD2 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnD3 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnD4 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnD5 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnD6 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnD7 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnD8 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnD9 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnD0 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnDiv = new
Wildgrape.Aqua. Controls.Button ();
this.bttnMul = new
Wildgrape.Aqua. Controls.Button ();
this.bttnMinus = new
Wildgrape.Aqua. Controls.Button ();
this.bttnPlus = new
Wildgrape.Aqua. Controls.Button ();
this.bttnClr = new
Wildgrape.Aqua. Controls.Button ();
this.bttnDot = new
Wildgrape.Aqua. Controls.Button ();
this.bttnEqual = new
Wildgrape.Aqua. Controls.Button ();
this.BFCDisplA = new
System.Windows. Forms.Label();
this.CalcBtnPwr = new
Wildgrape.Aqua. Controls.Button ();
this.SuspendLay out();
//
// bttnD1
//
this.bttnD1.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD1.Loc ation = new
System.Drawing. Point(48, 328);
this.bttnD1.Nam e = "bttnD1";
this.bttnD1.Pul se = true;
this.bttnD1.Tab Index = 1;
this.bttnD1.Tex t = "1";
this.bttnD1.Cli ck += new
System.EventHan dler(this.bttnD 1_Click);
//
// bttnD2
//
this.bttnD2.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD2.Loc ation = new
System.Drawing. Point(96, 328);
this.bttnD2.Nam e = "bttnD2";
this.bttnD2.Pul se = true;
this.bttnD2.Tab Index = 2;
this.bttnD2.Tex t = "2";
this.bttnD2.Cli ck += new
System.EventHan dler(this.bttnD 2_Click);
//
// bttnD3
//
this.bttnD3.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD3.Loc ation = new
System.Drawing. Point(144, 328);
this.bttnD3.Nam e = "bttnD3";
this.bttnD3.Pul se = true;
this.bttnD3.Tab Index = 3;
this.bttnD3.Tex t = "3";
this.bttnD3.Cli ck += new
System.EventHan dler(this.bttnD 3_Click);
//
// bttnD4
//
this.bttnD4.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD4.Loc ation = new
System.Drawing. Point(48, 296);
this.bttnD4.Nam e = "bttnD4";
this.bttnD4.Pul se = true;
this.bttnD4.Tab Index = 4;
this.bttnD4.Tex t = "4";
this.bttnD4.Cli ck += new
System.EventHan dler(this.bttnD 4_Click);
//
// bttnD5
//
this.bttnD5.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD5.Loc ation = new
System.Drawing. Point(96, 296);
this.bttnD5.Nam e = "bttnD5";
this.bttnD5.Pul se = true;
this.bttnD5.Tab Index = 5;
this.bttnD5.Tex t = "5";
this.bttnD5.Cli ck += new
System.EventHan dler(this.bttnD 5_Click);
//
// bttnD6
//
this.bttnD6.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD6.Loc ation = new
System.Drawing. Point(144, 296);
this.bttnD6.Nam e = "bttnD6";
this.bttnD6.Pul se = true;
this.bttnD6.Tab Index = 6;
this.bttnD6.Tex t = "6";
this.bttnD6.Cli ck += new
System.EventHan dler(this.bttnD 6_Click);
//
// bttnD7
//
this.bttnD7.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD7.Loc ation = new
System.Drawing. Point(48, 264);
this.bttnD7.Nam e = "bttnD7";
this.bttnD7.Pul se = true;
this.bttnD7.Tab Index = 7;
this.bttnD7.Tex t = "7";
this.bttnD7.Cli ck += new
System.EventHan dler(this.bttnD 7_Click);
//
// bttnD8
//
this.bttnD8.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD8.Loc ation = new
System.Drawing. Point(96, 264);
this.bttnD8.Nam e = "bttnD8";
this.bttnD8.Pul se = true;
this.bttnD8.Tab Index = 8;
this.bttnD8.Tex t = "8";
this.bttnD8.Cli ck += new
System.EventHan dler(this.bttnD 8_Click);
//
// bttnD9
//
this.bttnD9.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD9.Loc ation = new
System.Drawing. Point(144, 264);
this.bttnD9.Nam e = "bttnD9";
this.bttnD9.Pul se = true;
this.bttnD9.Tab Index = 9;
this.bttnD9.Tex t = "9";
this.bttnD9.Cli ck += new
System.EventHan dler(this.bttnD 9_Click);
//
// bttnD0
//
this.bttnD0.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD0.Loc ation = new
System.Drawing. Point(48, 360);
this.bttnD0.Nam e = "bttnD0";
this.bttnD0.Pul se = true;
this.bttnD0.Tab Index = 10;
this.bttnD0.Tex t = "0";
this.bttnD0.Cli ck += new
System.EventHan dler(this.bttnD 0_Click);
//
// bttnDiv
//
this.bttnDiv.Fo nt = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnDiv.Lo cation = new
System.Drawing. Point(200, 232);
this.bttnDiv.Na me = "bttnDiv";
this.bttnDiv.Pu lse = true;
this.bttnDiv.Ta bIndex = 11;
this.bttnDiv.Te xt = "/";
this.bttnDiv.Cl ick += new
System.EventHan dler(this.bttnD iv_Click);
//
// bttnMul
//
this.bttnMul.Fo nt = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnMul.Lo cation = new
System.Drawing. Point(200, 296);
this.bttnMul.Na me = "bttnMul";
this.bttnMul.Pu lse = true;
this.bttnMul.Ta bIndex = 12;
this.bttnMul.Te xt = "*";
this.bttnMul.Cl ick += new
System.EventHan dler(this.bttnM ul_Click);
//
// bttnMinus
//
this.bttnMinus. Font = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnMinus. Location = new
System.Drawing. Point(200, 264);
this.bttnMinus. Name = "bttnMinus" ;
this.bttnMinus. Pulse = true;
this.bttnMinus. TabIndex = 13;
this.bttnMinus. Text = "-";
this.bttnMinus. Click += new
System.EventHan dler(this.bttnM inus_Click);
//
// bttnPlus
//
this.bttnPlus.F ont = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnPlus.L ocation = new
System.Drawing. Point(200, 328);
this.bttnPlus.N ame = "bttnPlus";
this.bttnPlus.P ulse = true;
this.bttnPlus.T abIndex = 14;
this.bttnPlus.T ext = "+";
this.bttnPlus.C lick += new
System.EventHan dler(this.bttnP lus_Click);
//
// bttnClr
//
this.bttnClr.Fo nt = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnClr.Lo cation = new
System.Drawing. Point(144, 360);
this.bttnClr.Na me = "bttnClr";
this.bttnClr.Pu lse = true;
this.bttnClr.Ta bIndex = 15;
this.bttnClr.Te xt = "C";
this.bttnClr.Cl ick += new
System.EventHan dler(this.bttnC lr_Click);
//
// bttnDot
//
this.bttnDot.Fo nt = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnDot.Lo cation = new
System.Drawing. Point(96, 360);
this.bttnDot.Na me = "bttnDot";
this.bttnDot.Pu lse = true;
this.bttnDot.Ta bIndex = 16;
this.bttnDot.Te xt = ".";
this.bttnDot.Cl ick += new
System.EventHan dler(this.bttnD ot_Click);
//
// bttnEqual
//
this.bttnEqual. Font = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnEqual. Location = new
System.Drawing. Point(200, 360);
this.bttnEqual. Name = "bttnEqual" ;
this.bttnEqual. Pulse = true;
this.bttnEqual. TabIndex = 17;
this.bttnEqual. Text = "=";
this.bttnEqual. Click += new
System.EventHan dler(this.bttnE qual_Click);
//
// BFCDisplA
//
this.BFCDisplA. BackColor =
System.Drawing. Color.LightSkyB lue;
this.BFCDisplA. BorderStyle =
System.Windows. Forms.BorderSty le.FixedSingle;
this.BFCDisplA. Font = new
System.Drawing. Font("Lucida Console", 12F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.BFCDisplA. ForeColor =
System.Drawing. SystemColors.Hi ghlight;
this.BFCDisplA. Location = new
System.Drawing. Point(64, 72);
this.BFCDisplA. Name = "BFCDisplA" ;
this.BFCDisplA. Size = new
System.Drawing. Size(168, 40);
this.BFCDisplA. TabIndex = 18;
this.BFCDisplA. TextAlign =
System.Drawing. ContentAlignmen t.MiddleRight;
//
// CalcBtnPwr
//
this.CalcBtnPwr .Font = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.CalcBtnPwr .Location = new
System.Drawing. Point(200, 120);
this.CalcBtnPwr .Name = "CalcBtnPwr ";
this.CalcBtnPwr .Pulse = true;
this.CalcBtnPwr .TabIndex = 19;
this.CalcBtnPwr .Text = "Pwr";
this.CalcBtnPwr .Click += new
System.EventHan dler(this.CalcB tnPwr_Click);
//
// BFCMainForm
//
this.AutoScaleB aseSize = new
System.Drawing. Size(5, 13);
this.BackColor =
System.Drawing. SystemColors.Co ntrolText;
this.Background Image =
((System.Drawin g.Bitmap)(resou rces.GetObject( "$this.Backgrou ndImage")));
this.ClientSize = new System.Drawing. Size(304,
448);
this.Controls.A ddRange(new
System.Windows. Forms.Control[] {
this.CalcBtnPwr ,
this.bttnEqual,
this.bttnDot,
this.bttnClr,
this.bttnPlus,
this.bttnMinus,
this.bttnMul,
this.bttnDiv,
this.bttnD0,
this.bttnD9,
this.bttnD8,
this.bttnD7,
this.bttnD6,
this.bttnD5,
this.bttnD4,
this.bttnD3,
this.bttnD2,
this.bttnD1,
this.BFCDisplA} );
this.FormBorder Style =
System.Windows. Forms.FormBorde rStyle.None;
this.Icon =
((System.Drawin g.Icon)(resourc es.GetObject("$ this.Icon")));
this.MaximizeBo x = false;
this.MinimizeBo x = false;
this.Name = "BFCMainFor m";
this.StartPosit ion =
System.Windows. Forms.FormStart Position.Center Screen;
this.Text = "BFC2k4";
this.Transparen cyKey =
System.Drawing. Color.Lime;
this.Load += new
System.EventHan dler(this.BFCMa inForm_Load;
this.ResumeLayo ut(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new BFCMainForm());
}
private void bttnD0_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D0);
Invalidate();
}
private void bttnD1_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D1);
Invalidate();
}
private void bttnD2_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D2);
Invalidate();
}
private void bttnD3_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D3);
Invalidate();
}
private void bttnD4_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D4);
Invalidate();
}
private void bttnD5_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D5);
Invalidate();
}
private void bttnD6_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D6);
Invalidate();
}
private void bttnD7_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D7);
Invalidate();
}
private void bttnD8_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D8);
Invalidate();
}
private void bttnD9_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D9);
Invalidate();
}
private void bttnDiv_Click(o bject sender,
System.EventArg s e)
{
AddOperatorToAr ray(bttnDiv);
Invalidate();
}
private void bttnMul_Click(o bject sender,
System.EventArg s e)
{
AddOperatorToAr ray(bttnMul);
Invalidate();
}
private void bttnMinus_Click (object sender,
System.EventArg s e)
{
AddOperatorToAr ray(bttnMinus);
Invalidate();
}
private void bttnPlus_Click( object sender,
System.EventArg s e)
{
AddOperatorToAr ray(bttnPlus);
Invalidate();
}
private void bttnDot_Click(o bject sender,
System.EventArg s e)
{
AddToArray(bttn Dot) ;
bttnDot.Enabled = false ;
Invalidate();
}
private void bttnClr_Click(o bject sender,
System.EventArg s e)
{
Reset();
Invalidate();
}
private void bttnEqual_Click (object sender,
System.EventArg s e)
{
try
{
BFCArray1.Add(B FCValue1)
;
BFCArray1.Add( bttnEqual.Text )
;
/* m_res here take the first element
in BFCArray1 if this element is
* operator like +*-/ Exception give
us Error else it will take the
* Digits or dot point
*/
float m_res = float.Parse (
BFCArray1[0].ToString() ) ;
/* this loop extract all element in
Array then check it
* if the element is operator it will
calculate the prefix
* and postfix and give us the result
* Example 1+2/3*5
* 1) 1+2 = 3
* 2) 3/3 = 1
* 3) 1*5 = 5
* note:- no periority operator and no
brakets so it's basic calculator:)
*/
for( int i = 0 ; i<BFCArray1.Cou nt ;
i++ )
{
if( BFCArray1[i].ToString() ==
"+" )
{
BFCDisplA.Text
= "" ;
m_res += float.Parse
(BFCArray1[i+1].ToString()) ;
BFCDisplA.Text =
m_res.ToString( )
;
}
else if(
BFCArray1[i].ToString() == "-" )
{
BFCDisplA.Text
= "" ;
m_res -= float.Parse
(BFCArray1[i+1].ToString()) ;
BFCDisplA.Text
= m_res.ToString( ) ;
}
else if(
BFCArray1[i].ToString() == "*" )
{
BFCDisplA.Text
= "" ;
m_res *= float.Parse (
BFCArray1[i+1].ToString() ) ;
BFCDisplA.Text
= m_res.ToString( ) ;
}
else if(
BFCArray1[i].ToString() == "/" )
{
BFCDisplA.Text
= "" ;
m_res /= float.Parse (
BFCArray1[i+1].ToString() );
BFCDisplA.Text
= m_res.ToString( ) ;
}
}
BFCArray1.Clear ()
;
BFCValue1 = BFCDisplA.Text
;
for( int i = 0 ; i < BFCValue1.Lengt h
; i++ )
{
if( BFCValue1[i].ToString() ==
"." )
{
bttnDot.Enabled =
false
;
break
;
}
else
{
bttnDot.Enabled = true
;
}
}
bttnEqual.Enabl ed = false
;
}
catch(Exception exception)
{
MessageBox.Show (exception.Mess age,"Error") ;
}
Invalidate();
}
private void CalcBtnPwr_Clic k(object sender,
System.EventArg s e)
{
this.Close();
}
private void BFCMainForm_Loa d(object sender,
System.EventArg s e)
{
Invalidate();
}
}
}
Aqua button Class
//---------------------------------------------------------------------------------------------------------------------------------
=============== =============== =============== =============== ======
///
/// Button.cs
///
/// by Dave Peckham
/// August 2002
/// Irvine, California
///
/// A button that emulates the Apple Aqua user interface
guidelines.
/// This button grows horizontally to accomodate its label. Button
/// height is fixed.
///
using System;
using System.Reflecti on;
using System.Componen tModel;
using System.Componen tModel.Design;
using System.Windows. Forms;
using System.Drawing;
using System.Drawing. Drawing2D;
using System.Drawing. Imaging;
namespace Wildgrape.Aqua. Controls
{
[Description( "Aqua Button Control" )]
[Designer(typeof (Wildgrape.Aqua .Controls.Butto nDesigner))]
public class Button : System.Windows. Forms.Button
{
#region Class Constants
protected static int ButtonDefaultWi dth = 75;
// Set this to the height of your source bitmaps
protected static int ButtonHeight = 30;
// If your source bitmaps have shadows, set this
// to the shadow size so DrawText can position the
// label appears centered on the label
protected static int ButtonShadowOff set = 5;
// These settings approximate the pulse effect
// of buttons on Mac OS X
protected static int PulseInterval = 70;
protected static float PulseGammaMax = 2.1f;
protected static float PulseGammaMin = 0.7f;
protected static float PulseGammaShift = 0.2f;
protected static float PulseGammaReduc tionThreshold =
0.2f;
protected static float PulseGammaShift Reduction =
0.5f;
#endregion
#region Member Variables
// Appearance
protected bool pulse = false;
protected bool sizeToLabel = true;
// Pulsing
protected Timer timer;
protected float gamma, gammaShift;
// Mouse tracking
protected Point ptMousePosition ;
protected bool mousePressed;
// Images used to draw the button
protected Image imgLeft, imgFill, imgRight;
// Rectangles to position images on the button face
protected Rectangle rcLeft, rcRight;
// Matrices for transparency transformation
protected ImageAttributes iaDefault, iaNormal;
protected ColorMatrix cmDefault, cmNormal;
#endregion
#region Constructors and Initializers
public Button( )
{
InitializeCompo nent( );
SetStyle( ControlStyles.S tandardClick, true );
}
private void InitializeCompo nent( )
{
}
#endregion
#region Properties
[Description( "Determines whether the button pulses.
Note that only the default button can pulse." )]
[Category( "Appearance " )]
[DefaultValue( false )]
public bool Pulse
{
get { return pulse; }
set { pulse = value; }
}
[Description( "Determines whether the button should
automatically size to fit the label" )]
[Category( "Layout" )]
[DefaultValue( true )]
public bool SizeToLabel
{
get { return sizeToLabel; }
set
{
sizeToLabel = value;
OnTextChanged( EventArgs.Empty );
}
}
#endregion
#region Property overrides
/* AquaButton has a fixed height */
protected override Size DefaultSize
{
get {return new Size(
Button.ButtonDe faultWidth,
Button.ButtonHe ight ); }
}
/* Shadow Control.Width to make it browsable */
[Description( "See also: SizeToLabel" )]
[Category( "Layout" )]
[Browsable( true )]
public new int Width
{
get { return base.Width; }
set { base.Width = value; }
}
/* Shadow Control.Height to make it browsable and read
only */
[Description( "Aqua buttons have a fixed height" )]
[Category( "Layout" )]
[Browsable( true )]
[ReadOnly( true )]
public new int Height { get { return base.Height; }
}
#endregion
#region Method overrides
protected override void OnCreateControl ()
{
LoadImages();
InitializeGraph ics();
}
protected override void OnTextChanged( EventArgs e )
{
if (sizeToLabel)
{
Graphics g = this.CreateGrap hics( );
SizeF sizeF = g.MeasureString ( Text,
Font );
Width = imgLeft.Width +
(int)sizeF.Widt h + imgRight.Width;
g.Dispose();
}
Invalidate( );
Update( );
base.OnTextChan ged( e );
}
protected override void OnPaint( PaintEventArgs e )
{
Graphics g = e.Graphics;
g.Clear(Parent. BackColor);
Draw( g );
}
protected override void OnGotFocus( EventArgs e )
{
base.OnGotFocus ( e );
if (Pulse)
StartPulsing();
}
protected override void OnLostFocus( EventArgs e )
{
base.OnLostFocu s( e );
if (Pulse)
StopPulsing();
}
protected override void OnMouseDown( MouseEventArgs e
)
{
base.OnMouseDow n( e );
if( e.Button == MouseButtons.Le ft )
{
mousePressed = true;
ptMousePosition .X = e.X;
ptMousePosition .Y = e.Y;
StopPulsing( );
}
}
protected override void OnMouseMove( MouseEventArgs e
)
{
// Buttons receives MouseMove events when the
// mouse enters or leaves the client area.
base.OnMouseMov e( e );
if( mousePressed && ( e.Button &
MouseButtons.Le ft ) != 0 )
{
ptMousePosition .X = e.X;
ptMousePosition .Y = e.Y;
}
}
protected override void OnMouseUp( MouseEventArgs e )
{
base.OnMouseUp( e );
if( mousePressed )
{
mousePressed = false;
StartPulsing( );
Invalidate();
Update( );
}
}
protected override void OnKeyPress( KeyPressEventAr gs
e )
{
base.OnKeyPress ( e );
if( mousePressed && e.KeyChar == '\x001B' )
// Escape
{
mousePressed = false;
StartPulsing( );
Invalidate();
Update( );
}
}
#endregion
#region Implementation
protected virtual void LoadImages ()
{
imgLeft = new Bitmap( GetType(),
"Button.left.pn g" );
imgRight = new Bitmap( GetType(),
"Button.right.p ng" );
imgFill = new Bitmap( GetType(),
"Button.fill.pn g" );
}
protected virtual void InitializeGraph ics ()
{
// Rectangles for placing images relative to
the client rectangle
rcLeft = new Rectangle( 0, 0, imgLeft.Width,
imgLeft.Height );
rcRight = new Rectangle( 0, 0, imgRight.Width,
imgRight.Height );
// Image attributes used to lighten default
buttons
cmDefault = new ColorMatrix();
cmDefault.Matri x33 = 0.5f; // reduce opacity
by 50%
iaDefault = new ImageAttributes ();
iaDefault.SetCo lorMatrix( cmDefault,
ColorMatrixFlag .Default,
ColorAdjustType .Bitmap );
// Image attributes that lighten and
desaturate normal buttons
cmNormal = new ColorMatrix();
// desaturate the image
cmNormal.Matrix 00 = 1/3f;
cmNormal.Matrix 01 = 1/3f;
cmNormal.Matrix 02 = 1/3f;
cmNormal.Matrix 10 = 1/3f;
cmNormal.Matrix 11 = 1/3f;
cmNormal.Matrix 12 = 1/3f;
cmNormal.Matrix 20 = 1/3f;
cmNormal.Matrix 21 = 1/3f;
cmNormal.Matrix 22 = 1/3f;
cmNormal.Matrix 33 = 0.5f; // reduce opacity
by 50%
iaNormal = new ImageAttributes ();
iaNormal.SetCol orMatrix( cmNormal,
ColorMatrixFlag .Default,
ColorAdjustType .Bitmap );
}
protected virtual void StartPulsing ()
{
if ( Focused && Pulse &&
!this.DesignMod eDetected( ) )
{
timer = new Timer( );
timer.Interval = Button.PulseInt erval;
timer.Tick += new EventHandler(
TimerOnTick );
gamma = Button.PulseGam maMax;
gammaShift = -Button.PulseGam maShift;
timer.Start();
}
}
protected virtual void StopPulsing ()
{
if ( timer != null )
{
iaDefault.SetGa mma( 1.0f,
ColorAdjustType .Bitmap );
timer.Stop();
}
}
protected virtual void Draw( Graphics g )
{
DrawButton( g );
DrawText( g );
}
protected virtual void DrawButton( Graphics g )
{
// Update our destination rectangles
rcRight.X = this.Width - imgRight.Width;
if ( mousePressed )
{
if ( ClientRectangle .Contains(
ptMousePosition .X, ptMousePosition .Y ) )
DrawButtonState ( g, iaDefault
);
else
DrawButtonState ( g, iaNormal
);
}
else if ( IsDefault )
DrawButtonState ( g, iaDefault );
else
DrawButtonState ( g, iaNormal );
}
protected virtual void DrawButtonState (Graphics g,
ImageAttributes ia)
{
TextureBrush tb;
// Draw the left and right endcaps
g.DrawImage( imgLeft, rcLeft, 0, 0,
imgLeft.Width, imgLeft.Height,
GraphicsUnit.Pi xel, ia );
g.DrawImage( imgRight, rcRight, 0, 0,
imgRight.Width, imgRight.Height ,
GraphicsUnit.Pi xel, ia );
// Draw the middle
tb = new TextureBrush( imgFill,
new Rectangle( 0, 0, imgFill.Width,
imgFill.Height ), ia );
tb.WrapMode = WrapMode.Tile;
g.FillRectangle ( tb, imgLeft.Width, 0,
this.Width - (imgLeft.Width +
imgRight.Width) ,
imgFill.Height) ;
tb.Dispose( );
}
protected virtual void DrawText( Graphics g )
{
RectangleF layoutRect =
new RectangleF( 0, 0, this.Width,
this.Height -
Button.ButtonSh adowOffset );
int LabelShadowOffs et = 1;
StringFormat fmt = new StringFormat( );
fmt.Alignment =
StringAlignment .Center;
fmt.LineAlignme nt =
StringAlignment .Center;
// Draw the shadow below the label
layoutRect.Offs et( 0, LabelShadowOffs et );
SolidBrush textShadowBrush = new
SolidBrush( Color.Gray );
g.DrawString( Text, Font, textShadowBrush ,
layoutRect, fmt );
textShadowBrush .Dispose( );
// and the label itself
layoutRect.Offs et( 0, -LabelShadowOffs et );
SolidBrush brushFiller = new SolidBrush(
Color.Black );
g.DrawString( Text, Font, brushFiller,
layoutRect, fmt );
brushFiller.Dis pose( );
}
protected virtual void TimerOnTick( object obj,
EventArgs e)
{
// set the new gamma level
if ((gamma - Button.PulseGam maMin <
Button.PulseGam maReductionThre shold ) ||
(Button.PulseGa mmaMax - gamma <
Button.PulseGam maReductionThre shold ))
gamma += gammaShift *
Button.PulseGam maShiftReductio n;
else
gamma += gammaShift;
if ( gamma <= Button.PulseGam maMin || gamma >=
Button.PulseGam maMax )
gammaShift = -gammaShift;
iaDefault.SetGa mma( gamma,
ColorAdjustType .Bitmap );
Invalidate( );
Update( );
}
protected virtual bool DesignModeDetec ted()
{
// base.DesignMode always returns false, so
try this workaround
IDesignerHost host =
(IDesignerHost) this.GetService (
typeof( IDesignerHost ) );
return ( host != null );
}
#endregion
}
}
Thanks if you can help
characters on the display?
if you use the right mousebutton it works ok, but the buttons dont
flash??
it works fine without the aqua buttons, (using just windows forms
buttons...
Main Form cs file
//----------------------------------------------------------------------------------------------------------------------
=============== =============== =============== =============== =
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
namespace Calculator
{
/// <summary>
/// Summary description for BFCMainForm.
/// </summary>
public class BFCMainForm : System.Windows. Forms.Form
{
private Wildgrape.Aqua. Controls.Button bttnD4;
private Wildgrape.Aqua. Controls.Button bttnD7;
private Wildgrape.Aqua. Controls.Button bttnD8;
private Wildgrape.Aqua. Controls.Button bttnD9;
private Wildgrape.Aqua. Controls.Button bttnD1;
private Wildgrape.Aqua. Controls.Button bttnD2;
private Wildgrape.Aqua. Controls.Button bttnD3;
private Wildgrape.Aqua. Controls.Button bttnD5;
private Wildgrape.Aqua. Controls.Button bttnD6;
private Wildgrape.Aqua. Controls.Button bttnD0;
private Wildgrape.Aqua. Controls.Button bttnDiv;
private Wildgrape.Aqua. Controls.Button bttnMul;
private Wildgrape.Aqua. Controls.Button bttnMinus;
private Wildgrape.Aqua. Controls.Button bttnPlus;
private Wildgrape.Aqua. Controls.Button bttnClr;
private Wildgrape.Aqua. Controls.Button bttnDot;
private Wildgrape.Aqua. Controls.Button bttnEqual;
private Wildgrape.Aqua. Controls.Button CalcBtnPwr;
private System.Windows. Forms.Label BFCDisplA;
private string BFCValue1;
// private string BFCValue2;
private ArrayList BFCArray1;
// private ArrayList BFCArray2;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components =
null;
public BFCMainForm()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
// Set the application title bar
Version ver = new
Version(Applica tion.ProductVer sion);
this.Text = String.Format(" BFC-2k4
{0:#}.{1:#}.{2: #}", ver.Major, ver.Minor,ver.B uild);
Icon = new
Icon(typeof(BFC MainForm), "DedHed.ico ");
//
// TODO: Add any constructor code after
InitializeCompo nent call
//
BFCValue1 = ""
;
BFCArray1 = new
ArrayList();
}
private void AddOperatorToAr ray(Button bttn)
{
BFCArray1.Add( BFCValue1 ) ;
BFCDisplA.Text +=
bttn.Text;
BFCValue1
= "";
BFCArray1.Add( bttn.Text );
bttnDot.Enabled = true ;
SetEnableOperat orBttns(false);
BFCDisplA.Text = "";
Invalidate();
}
private void AddToArray(Butt on bttn)
{
BFCValue1 = bttn.Text;
// somewhere in here
BFCDisplA.Text = bttn.Text;
// is the double # trouble
SetEnableOperat orBttns(true);
Invalidate();
}
private void Reset()
{
BFCValue1 = "";
BFCDisplA.Text = "";
BFCArray1.Clear () ;
bttnDot.Enabled = true;
}
private void SetEnableOperat orBttns(bool enable)
{
bttnPlus.Enable d = enable ;
bttnMinus.Enabl ed = enable ;
bttnMul.Enabled = enable ;
bttnDiv.Enabled = enable ;
bttnEqual.Enabl ed = enable ;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}
#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>
private void InitializeCompo nent()
{
System.Resource s.ResourceManag er resources =
new System.Resource s.ResourceManag er(typeof(BFCMa inForm));
this.bttnD1 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnD2 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnD3 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnD4 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnD5 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnD6 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnD7 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnD8 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnD9 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnD0 = new
Wildgrape.Aqua. Controls.Button ();
this.bttnDiv = new
Wildgrape.Aqua. Controls.Button ();
this.bttnMul = new
Wildgrape.Aqua. Controls.Button ();
this.bttnMinus = new
Wildgrape.Aqua. Controls.Button ();
this.bttnPlus = new
Wildgrape.Aqua. Controls.Button ();
this.bttnClr = new
Wildgrape.Aqua. Controls.Button ();
this.bttnDot = new
Wildgrape.Aqua. Controls.Button ();
this.bttnEqual = new
Wildgrape.Aqua. Controls.Button ();
this.BFCDisplA = new
System.Windows. Forms.Label();
this.CalcBtnPwr = new
Wildgrape.Aqua. Controls.Button ();
this.SuspendLay out();
//
// bttnD1
//
this.bttnD1.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD1.Loc ation = new
System.Drawing. Point(48, 328);
this.bttnD1.Nam e = "bttnD1";
this.bttnD1.Pul se = true;
this.bttnD1.Tab Index = 1;
this.bttnD1.Tex t = "1";
this.bttnD1.Cli ck += new
System.EventHan dler(this.bttnD 1_Click);
//
// bttnD2
//
this.bttnD2.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD2.Loc ation = new
System.Drawing. Point(96, 328);
this.bttnD2.Nam e = "bttnD2";
this.bttnD2.Pul se = true;
this.bttnD2.Tab Index = 2;
this.bttnD2.Tex t = "2";
this.bttnD2.Cli ck += new
System.EventHan dler(this.bttnD 2_Click);
//
// bttnD3
//
this.bttnD3.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD3.Loc ation = new
System.Drawing. Point(144, 328);
this.bttnD3.Nam e = "bttnD3";
this.bttnD3.Pul se = true;
this.bttnD3.Tab Index = 3;
this.bttnD3.Tex t = "3";
this.bttnD3.Cli ck += new
System.EventHan dler(this.bttnD 3_Click);
//
// bttnD4
//
this.bttnD4.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD4.Loc ation = new
System.Drawing. Point(48, 296);
this.bttnD4.Nam e = "bttnD4";
this.bttnD4.Pul se = true;
this.bttnD4.Tab Index = 4;
this.bttnD4.Tex t = "4";
this.bttnD4.Cli ck += new
System.EventHan dler(this.bttnD 4_Click);
//
// bttnD5
//
this.bttnD5.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD5.Loc ation = new
System.Drawing. Point(96, 296);
this.bttnD5.Nam e = "bttnD5";
this.bttnD5.Pul se = true;
this.bttnD5.Tab Index = 5;
this.bttnD5.Tex t = "5";
this.bttnD5.Cli ck += new
System.EventHan dler(this.bttnD 5_Click);
//
// bttnD6
//
this.bttnD6.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD6.Loc ation = new
System.Drawing. Point(144, 296);
this.bttnD6.Nam e = "bttnD6";
this.bttnD6.Pul se = true;
this.bttnD6.Tab Index = 6;
this.bttnD6.Tex t = "6";
this.bttnD6.Cli ck += new
System.EventHan dler(this.bttnD 6_Click);
//
// bttnD7
//
this.bttnD7.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD7.Loc ation = new
System.Drawing. Point(48, 264);
this.bttnD7.Nam e = "bttnD7";
this.bttnD7.Pul se = true;
this.bttnD7.Tab Index = 7;
this.bttnD7.Tex t = "7";
this.bttnD7.Cli ck += new
System.EventHan dler(this.bttnD 7_Click);
//
// bttnD8
//
this.bttnD8.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD8.Loc ation = new
System.Drawing. Point(96, 264);
this.bttnD8.Nam e = "bttnD8";
this.bttnD8.Pul se = true;
this.bttnD8.Tab Index = 8;
this.bttnD8.Tex t = "8";
this.bttnD8.Cli ck += new
System.EventHan dler(this.bttnD 8_Click);
//
// bttnD9
//
this.bttnD9.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD9.Loc ation = new
System.Drawing. Point(144, 264);
this.bttnD9.Nam e = "bttnD9";
this.bttnD9.Pul se = true;
this.bttnD9.Tab Index = 9;
this.bttnD9.Tex t = "9";
this.bttnD9.Cli ck += new
System.EventHan dler(this.bttnD 9_Click);
//
// bttnD0
//
this.bttnD0.Fon t = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnD0.Loc ation = new
System.Drawing. Point(48, 360);
this.bttnD0.Nam e = "bttnD0";
this.bttnD0.Pul se = true;
this.bttnD0.Tab Index = 10;
this.bttnD0.Tex t = "0";
this.bttnD0.Cli ck += new
System.EventHan dler(this.bttnD 0_Click);
//
// bttnDiv
//
this.bttnDiv.Fo nt = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnDiv.Lo cation = new
System.Drawing. Point(200, 232);
this.bttnDiv.Na me = "bttnDiv";
this.bttnDiv.Pu lse = true;
this.bttnDiv.Ta bIndex = 11;
this.bttnDiv.Te xt = "/";
this.bttnDiv.Cl ick += new
System.EventHan dler(this.bttnD iv_Click);
//
// bttnMul
//
this.bttnMul.Fo nt = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnMul.Lo cation = new
System.Drawing. Point(200, 296);
this.bttnMul.Na me = "bttnMul";
this.bttnMul.Pu lse = true;
this.bttnMul.Ta bIndex = 12;
this.bttnMul.Te xt = "*";
this.bttnMul.Cl ick += new
System.EventHan dler(this.bttnM ul_Click);
//
// bttnMinus
//
this.bttnMinus. Font = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnMinus. Location = new
System.Drawing. Point(200, 264);
this.bttnMinus. Name = "bttnMinus" ;
this.bttnMinus. Pulse = true;
this.bttnMinus. TabIndex = 13;
this.bttnMinus. Text = "-";
this.bttnMinus. Click += new
System.EventHan dler(this.bttnM inus_Click);
//
// bttnPlus
//
this.bttnPlus.F ont = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnPlus.L ocation = new
System.Drawing. Point(200, 328);
this.bttnPlus.N ame = "bttnPlus";
this.bttnPlus.P ulse = true;
this.bttnPlus.T abIndex = 14;
this.bttnPlus.T ext = "+";
this.bttnPlus.C lick += new
System.EventHan dler(this.bttnP lus_Click);
//
// bttnClr
//
this.bttnClr.Fo nt = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnClr.Lo cation = new
System.Drawing. Point(144, 360);
this.bttnClr.Na me = "bttnClr";
this.bttnClr.Pu lse = true;
this.bttnClr.Ta bIndex = 15;
this.bttnClr.Te xt = "C";
this.bttnClr.Cl ick += new
System.EventHan dler(this.bttnC lr_Click);
//
// bttnDot
//
this.bttnDot.Fo nt = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnDot.Lo cation = new
System.Drawing. Point(96, 360);
this.bttnDot.Na me = "bttnDot";
this.bttnDot.Pu lse = true;
this.bttnDot.Ta bIndex = 16;
this.bttnDot.Te xt = ".";
this.bttnDot.Cl ick += new
System.EventHan dler(this.bttnD ot_Click);
//
// bttnEqual
//
this.bttnEqual. Font = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.bttnEqual. Location = new
System.Drawing. Point(200, 360);
this.bttnEqual. Name = "bttnEqual" ;
this.bttnEqual. Pulse = true;
this.bttnEqual. TabIndex = 17;
this.bttnEqual. Text = "=";
this.bttnEqual. Click += new
System.EventHan dler(this.bttnE qual_Click);
//
// BFCDisplA
//
this.BFCDisplA. BackColor =
System.Drawing. Color.LightSkyB lue;
this.BFCDisplA. BorderStyle =
System.Windows. Forms.BorderSty le.FixedSingle;
this.BFCDisplA. Font = new
System.Drawing. Font("Lucida Console", 12F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.BFCDisplA. ForeColor =
System.Drawing. SystemColors.Hi ghlight;
this.BFCDisplA. Location = new
System.Drawing. Point(64, 72);
this.BFCDisplA. Name = "BFCDisplA" ;
this.BFCDisplA. Size = new
System.Drawing. Size(168, 40);
this.BFCDisplA. TabIndex = 18;
this.BFCDisplA. TextAlign =
System.Drawing. ContentAlignmen t.MiddleRight;
//
// CalcBtnPwr
//
this.CalcBtnPwr .Font = new
System.Drawing. Font("Microsoft Sans Serif", 9.75F,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int,
((System.Byte)( 0)));
this.CalcBtnPwr .Location = new
System.Drawing. Point(200, 120);
this.CalcBtnPwr .Name = "CalcBtnPwr ";
this.CalcBtnPwr .Pulse = true;
this.CalcBtnPwr .TabIndex = 19;
this.CalcBtnPwr .Text = "Pwr";
this.CalcBtnPwr .Click += new
System.EventHan dler(this.CalcB tnPwr_Click);
//
// BFCMainForm
//
this.AutoScaleB aseSize = new
System.Drawing. Size(5, 13);
this.BackColor =
System.Drawing. SystemColors.Co ntrolText;
this.Background Image =
((System.Drawin g.Bitmap)(resou rces.GetObject( "$this.Backgrou ndImage")));
this.ClientSize = new System.Drawing. Size(304,
448);
this.Controls.A ddRange(new
System.Windows. Forms.Control[] {
this.CalcBtnPwr ,
this.bttnEqual,
this.bttnDot,
this.bttnClr,
this.bttnPlus,
this.bttnMinus,
this.bttnMul,
this.bttnDiv,
this.bttnD0,
this.bttnD9,
this.bttnD8,
this.bttnD7,
this.bttnD6,
this.bttnD5,
this.bttnD4,
this.bttnD3,
this.bttnD2,
this.bttnD1,
this.BFCDisplA} );
this.FormBorder Style =
System.Windows. Forms.FormBorde rStyle.None;
this.Icon =
((System.Drawin g.Icon)(resourc es.GetObject("$ this.Icon")));
this.MaximizeBo x = false;
this.MinimizeBo x = false;
this.Name = "BFCMainFor m";
this.StartPosit ion =
System.Windows. Forms.FormStart Position.Center Screen;
this.Text = "BFC2k4";
this.Transparen cyKey =
System.Drawing. Color.Lime;
this.Load += new
System.EventHan dler(this.BFCMa inForm_Load;
this.ResumeLayo ut(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new BFCMainForm());
}
private void bttnD0_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D0);
Invalidate();
}
private void bttnD1_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D1);
Invalidate();
}
private void bttnD2_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D2);
Invalidate();
}
private void bttnD3_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D3);
Invalidate();
}
private void bttnD4_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D4);
Invalidate();
}
private void bttnD5_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D5);
Invalidate();
}
private void bttnD6_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D6);
Invalidate();
}
private void bttnD7_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D7);
Invalidate();
}
private void bttnD8_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D8);
Invalidate();
}
private void bttnD9_Click(ob ject sender,
System.EventArg s e)
{
AddToArray(bttn D9);
Invalidate();
}
private void bttnDiv_Click(o bject sender,
System.EventArg s e)
{
AddOperatorToAr ray(bttnDiv);
Invalidate();
}
private void bttnMul_Click(o bject sender,
System.EventArg s e)
{
AddOperatorToAr ray(bttnMul);
Invalidate();
}
private void bttnMinus_Click (object sender,
System.EventArg s e)
{
AddOperatorToAr ray(bttnMinus);
Invalidate();
}
private void bttnPlus_Click( object sender,
System.EventArg s e)
{
AddOperatorToAr ray(bttnPlus);
Invalidate();
}
private void bttnDot_Click(o bject sender,
System.EventArg s e)
{
AddToArray(bttn Dot) ;
bttnDot.Enabled = false ;
Invalidate();
}
private void bttnClr_Click(o bject sender,
System.EventArg s e)
{
Reset();
Invalidate();
}
private void bttnEqual_Click (object sender,
System.EventArg s e)
{
try
{
BFCArray1.Add(B FCValue1)
;
BFCArray1.Add( bttnEqual.Text )
;
/* m_res here take the first element
in BFCArray1 if this element is
* operator like +*-/ Exception give
us Error else it will take the
* Digits or dot point
*/
float m_res = float.Parse (
BFCArray1[0].ToString() ) ;
/* this loop extract all element in
Array then check it
* if the element is operator it will
calculate the prefix
* and postfix and give us the result
* Example 1+2/3*5
* 1) 1+2 = 3
* 2) 3/3 = 1
* 3) 1*5 = 5
* note:- no periority operator and no
brakets so it's basic calculator:)
*/
for( int i = 0 ; i<BFCArray1.Cou nt ;
i++ )
{
if( BFCArray1[i].ToString() ==
"+" )
{
BFCDisplA.Text
= "" ;
m_res += float.Parse
(BFCArray1[i+1].ToString()) ;
BFCDisplA.Text =
m_res.ToString( )
;
}
else if(
BFCArray1[i].ToString() == "-" )
{
BFCDisplA.Text
= "" ;
m_res -= float.Parse
(BFCArray1[i+1].ToString()) ;
BFCDisplA.Text
= m_res.ToString( ) ;
}
else if(
BFCArray1[i].ToString() == "*" )
{
BFCDisplA.Text
= "" ;
m_res *= float.Parse (
BFCArray1[i+1].ToString() ) ;
BFCDisplA.Text
= m_res.ToString( ) ;
}
else if(
BFCArray1[i].ToString() == "/" )
{
BFCDisplA.Text
= "" ;
m_res /= float.Parse (
BFCArray1[i+1].ToString() );
BFCDisplA.Text
= m_res.ToString( ) ;
}
}
BFCArray1.Clear ()
;
BFCValue1 = BFCDisplA.Text
;
for( int i = 0 ; i < BFCValue1.Lengt h
; i++ )
{
if( BFCValue1[i].ToString() ==
"." )
{
bttnDot.Enabled =
false
;
break
;
}
else
{
bttnDot.Enabled = true
;
}
}
bttnEqual.Enabl ed = false
;
}
catch(Exception exception)
{
MessageBox.Show (exception.Mess age,"Error") ;
}
Invalidate();
}
private void CalcBtnPwr_Clic k(object sender,
System.EventArg s e)
{
this.Close();
}
private void BFCMainForm_Loa d(object sender,
System.EventArg s e)
{
Invalidate();
}
}
}
Aqua button Class
//---------------------------------------------------------------------------------------------------------------------------------
=============== =============== =============== =============== ======
///
/// Button.cs
///
/// by Dave Peckham
/// August 2002
/// Irvine, California
///
/// A button that emulates the Apple Aqua user interface
guidelines.
/// This button grows horizontally to accomodate its label. Button
/// height is fixed.
///
using System;
using System.Reflecti on;
using System.Componen tModel;
using System.Componen tModel.Design;
using System.Windows. Forms;
using System.Drawing;
using System.Drawing. Drawing2D;
using System.Drawing. Imaging;
namespace Wildgrape.Aqua. Controls
{
[Description( "Aqua Button Control" )]
[Designer(typeof (Wildgrape.Aqua .Controls.Butto nDesigner))]
public class Button : System.Windows. Forms.Button
{
#region Class Constants
protected static int ButtonDefaultWi dth = 75;
// Set this to the height of your source bitmaps
protected static int ButtonHeight = 30;
// If your source bitmaps have shadows, set this
// to the shadow size so DrawText can position the
// label appears centered on the label
protected static int ButtonShadowOff set = 5;
// These settings approximate the pulse effect
// of buttons on Mac OS X
protected static int PulseInterval = 70;
protected static float PulseGammaMax = 2.1f;
protected static float PulseGammaMin = 0.7f;
protected static float PulseGammaShift = 0.2f;
protected static float PulseGammaReduc tionThreshold =
0.2f;
protected static float PulseGammaShift Reduction =
0.5f;
#endregion
#region Member Variables
// Appearance
protected bool pulse = false;
protected bool sizeToLabel = true;
// Pulsing
protected Timer timer;
protected float gamma, gammaShift;
// Mouse tracking
protected Point ptMousePosition ;
protected bool mousePressed;
// Images used to draw the button
protected Image imgLeft, imgFill, imgRight;
// Rectangles to position images on the button face
protected Rectangle rcLeft, rcRight;
// Matrices for transparency transformation
protected ImageAttributes iaDefault, iaNormal;
protected ColorMatrix cmDefault, cmNormal;
#endregion
#region Constructors and Initializers
public Button( )
{
InitializeCompo nent( );
SetStyle( ControlStyles.S tandardClick, true );
}
private void InitializeCompo nent( )
{
}
#endregion
#region Properties
[Description( "Determines whether the button pulses.
Note that only the default button can pulse." )]
[Category( "Appearance " )]
[DefaultValue( false )]
public bool Pulse
{
get { return pulse; }
set { pulse = value; }
}
[Description( "Determines whether the button should
automatically size to fit the label" )]
[Category( "Layout" )]
[DefaultValue( true )]
public bool SizeToLabel
{
get { return sizeToLabel; }
set
{
sizeToLabel = value;
OnTextChanged( EventArgs.Empty );
}
}
#endregion
#region Property overrides
/* AquaButton has a fixed height */
protected override Size DefaultSize
{
get {return new Size(
Button.ButtonDe faultWidth,
Button.ButtonHe ight ); }
}
/* Shadow Control.Width to make it browsable */
[Description( "See also: SizeToLabel" )]
[Category( "Layout" )]
[Browsable( true )]
public new int Width
{
get { return base.Width; }
set { base.Width = value; }
}
/* Shadow Control.Height to make it browsable and read
only */
[Description( "Aqua buttons have a fixed height" )]
[Category( "Layout" )]
[Browsable( true )]
[ReadOnly( true )]
public new int Height { get { return base.Height; }
}
#endregion
#region Method overrides
protected override void OnCreateControl ()
{
LoadImages();
InitializeGraph ics();
}
protected override void OnTextChanged( EventArgs e )
{
if (sizeToLabel)
{
Graphics g = this.CreateGrap hics( );
SizeF sizeF = g.MeasureString ( Text,
Font );
Width = imgLeft.Width +
(int)sizeF.Widt h + imgRight.Width;
g.Dispose();
}
Invalidate( );
Update( );
base.OnTextChan ged( e );
}
protected override void OnPaint( PaintEventArgs e )
{
Graphics g = e.Graphics;
g.Clear(Parent. BackColor);
Draw( g );
}
protected override void OnGotFocus( EventArgs e )
{
base.OnGotFocus ( e );
if (Pulse)
StartPulsing();
}
protected override void OnLostFocus( EventArgs e )
{
base.OnLostFocu s( e );
if (Pulse)
StopPulsing();
}
protected override void OnMouseDown( MouseEventArgs e
)
{
base.OnMouseDow n( e );
if( e.Button == MouseButtons.Le ft )
{
mousePressed = true;
ptMousePosition .X = e.X;
ptMousePosition .Y = e.Y;
StopPulsing( );
}
}
protected override void OnMouseMove( MouseEventArgs e
)
{
// Buttons receives MouseMove events when the
// mouse enters or leaves the client area.
base.OnMouseMov e( e );
if( mousePressed && ( e.Button &
MouseButtons.Le ft ) != 0 )
{
ptMousePosition .X = e.X;
ptMousePosition .Y = e.Y;
}
}
protected override void OnMouseUp( MouseEventArgs e )
{
base.OnMouseUp( e );
if( mousePressed )
{
mousePressed = false;
StartPulsing( );
Invalidate();
Update( );
}
}
protected override void OnKeyPress( KeyPressEventAr gs
e )
{
base.OnKeyPress ( e );
if( mousePressed && e.KeyChar == '\x001B' )
// Escape
{
mousePressed = false;
StartPulsing( );
Invalidate();
Update( );
}
}
#endregion
#region Implementation
protected virtual void LoadImages ()
{
imgLeft = new Bitmap( GetType(),
"Button.left.pn g" );
imgRight = new Bitmap( GetType(),
"Button.right.p ng" );
imgFill = new Bitmap( GetType(),
"Button.fill.pn g" );
}
protected virtual void InitializeGraph ics ()
{
// Rectangles for placing images relative to
the client rectangle
rcLeft = new Rectangle( 0, 0, imgLeft.Width,
imgLeft.Height );
rcRight = new Rectangle( 0, 0, imgRight.Width,
imgRight.Height );
// Image attributes used to lighten default
buttons
cmDefault = new ColorMatrix();
cmDefault.Matri x33 = 0.5f; // reduce opacity
by 50%
iaDefault = new ImageAttributes ();
iaDefault.SetCo lorMatrix( cmDefault,
ColorMatrixFlag .Default,
ColorAdjustType .Bitmap );
// Image attributes that lighten and
desaturate normal buttons
cmNormal = new ColorMatrix();
// desaturate the image
cmNormal.Matrix 00 = 1/3f;
cmNormal.Matrix 01 = 1/3f;
cmNormal.Matrix 02 = 1/3f;
cmNormal.Matrix 10 = 1/3f;
cmNormal.Matrix 11 = 1/3f;
cmNormal.Matrix 12 = 1/3f;
cmNormal.Matrix 20 = 1/3f;
cmNormal.Matrix 21 = 1/3f;
cmNormal.Matrix 22 = 1/3f;
cmNormal.Matrix 33 = 0.5f; // reduce opacity
by 50%
iaNormal = new ImageAttributes ();
iaNormal.SetCol orMatrix( cmNormal,
ColorMatrixFlag .Default,
ColorAdjustType .Bitmap );
}
protected virtual void StartPulsing ()
{
if ( Focused && Pulse &&
!this.DesignMod eDetected( ) )
{
timer = new Timer( );
timer.Interval = Button.PulseInt erval;
timer.Tick += new EventHandler(
TimerOnTick );
gamma = Button.PulseGam maMax;
gammaShift = -Button.PulseGam maShift;
timer.Start();
}
}
protected virtual void StopPulsing ()
{
if ( timer != null )
{
iaDefault.SetGa mma( 1.0f,
ColorAdjustType .Bitmap );
timer.Stop();
}
}
protected virtual void Draw( Graphics g )
{
DrawButton( g );
DrawText( g );
}
protected virtual void DrawButton( Graphics g )
{
// Update our destination rectangles
rcRight.X = this.Width - imgRight.Width;
if ( mousePressed )
{
if ( ClientRectangle .Contains(
ptMousePosition .X, ptMousePosition .Y ) )
DrawButtonState ( g, iaDefault
);
else
DrawButtonState ( g, iaNormal
);
}
else if ( IsDefault )
DrawButtonState ( g, iaDefault );
else
DrawButtonState ( g, iaNormal );
}
protected virtual void DrawButtonState (Graphics g,
ImageAttributes ia)
{
TextureBrush tb;
// Draw the left and right endcaps
g.DrawImage( imgLeft, rcLeft, 0, 0,
imgLeft.Width, imgLeft.Height,
GraphicsUnit.Pi xel, ia );
g.DrawImage( imgRight, rcRight, 0, 0,
imgRight.Width, imgRight.Height ,
GraphicsUnit.Pi xel, ia );
// Draw the middle
tb = new TextureBrush( imgFill,
new Rectangle( 0, 0, imgFill.Width,
imgFill.Height ), ia );
tb.WrapMode = WrapMode.Tile;
g.FillRectangle ( tb, imgLeft.Width, 0,
this.Width - (imgLeft.Width +
imgRight.Width) ,
imgFill.Height) ;
tb.Dispose( );
}
protected virtual void DrawText( Graphics g )
{
RectangleF layoutRect =
new RectangleF( 0, 0, this.Width,
this.Height -
Button.ButtonSh adowOffset );
int LabelShadowOffs et = 1;
StringFormat fmt = new StringFormat( );
fmt.Alignment =
StringAlignment .Center;
fmt.LineAlignme nt =
StringAlignment .Center;
// Draw the shadow below the label
layoutRect.Offs et( 0, LabelShadowOffs et );
SolidBrush textShadowBrush = new
SolidBrush( Color.Gray );
g.DrawString( Text, Font, textShadowBrush ,
layoutRect, fmt );
textShadowBrush .Dispose( );
// and the label itself
layoutRect.Offs et( 0, -LabelShadowOffs et );
SolidBrush brushFiller = new SolidBrush(
Color.Black );
g.DrawString( Text, Font, brushFiller,
layoutRect, fmt );
brushFiller.Dis pose( );
}
protected virtual void TimerOnTick( object obj,
EventArgs e)
{
// set the new gamma level
if ((gamma - Button.PulseGam maMin <
Button.PulseGam maReductionThre shold ) ||
(Button.PulseGa mmaMax - gamma <
Button.PulseGam maReductionThre shold ))
gamma += gammaShift *
Button.PulseGam maShiftReductio n;
else
gamma += gammaShift;
if ( gamma <= Button.PulseGam maMin || gamma >=
Button.PulseGam maMax )
gammaShift = -gammaShift;
iaDefault.SetGa mma( gamma,
ColorAdjustType .Bitmap );
Invalidate( );
Update( );
}
protected virtual bool DesignModeDetec ted()
{
// base.DesignMode always returns false, so
try this workaround
IDesignerHost host =
(IDesignerHost) this.GetService (
typeof( IDesignerHost ) );
return ( host != null );
}
#endregion
}
}
Thanks if you can help
Comment