By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

A Little Help??

P: n/a
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.Collections;
using System.ComponentModel;
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.ComponentModel.Container components =
null;

public BFCMainForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

// Set the application title bar
Version ver = new
Version(Application.ProductVersion);
this.Text = String.Format("BFC-2k4
{0:#}.{1:#}.{2:#}", ver.Major, ver.Minor,ver.Build);
Icon = new
Icon(typeof(BFCMainForm), "DedHed.ico");

//
// TODO: Add any constructor code after
InitializeComponent call
//
BFCValue1 = ""
;
BFCArray1 = new
ArrayList();
}
private void AddOperatorToArray(Button bttn)
{
BFCArray1.Add( BFCValue1 ) ;
BFCDisplA.Text +=
bttn.Text;
BFCValue1
= "";
BFCArray1.Add( bttn.Text );
bttnDot.Enabled = true ;
SetEnableOperatorBttns(false);
BFCDisplA.Text = "";
Invalidate();

}
private void AddToArray(Button bttn)
{
BFCValue1 = bttn.Text;
// somewhere in here
BFCDisplA.Text = bttn.Text;
// is the double # trouble
SetEnableOperatorBttns(true);
Invalidate();
}

private void Reset()
{
BFCValue1 = "";
BFCDisplA.Text = "";
BFCArray1.Clear() ;
bttnDot.Enabled = true;
}

private void SetEnableOperatorBttns(bool enable)
{
bttnPlus.Enabled = enable ;
bttnMinus.Enabled = enable ;
bttnMul.Enabled = enable ;
bttnDiv.Enabled = enable ;
bttnEqual.Enabled = enable ;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
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 InitializeComponent()
{
System.Resources.ResourceManager resources =
new System.Resources.ResourceManager(typeof(BFCMainFor m));
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.SuspendLayout();
//
// bttnD1
//
this.bttnD1.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD1.Location = new
System.Drawing.Point(48, 328);
this.bttnD1.Name = "bttnD1";
this.bttnD1.Pulse = true;
this.bttnD1.TabIndex = 1;
this.bttnD1.Text = "1";
this.bttnD1.Click += new
System.EventHandler(this.bttnD1_Click);
//
// bttnD2
//
this.bttnD2.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD2.Location = new
System.Drawing.Point(96, 328);
this.bttnD2.Name = "bttnD2";
this.bttnD2.Pulse = true;
this.bttnD2.TabIndex = 2;
this.bttnD2.Text = "2";
this.bttnD2.Click += new
System.EventHandler(this.bttnD2_Click);
//
// bttnD3
//
this.bttnD3.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD3.Location = new
System.Drawing.Point(144, 328);
this.bttnD3.Name = "bttnD3";
this.bttnD3.Pulse = true;
this.bttnD3.TabIndex = 3;
this.bttnD3.Text = "3";
this.bttnD3.Click += new
System.EventHandler(this.bttnD3_Click);
//
// bttnD4
//
this.bttnD4.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD4.Location = new
System.Drawing.Point(48, 296);
this.bttnD4.Name = "bttnD4";
this.bttnD4.Pulse = true;
this.bttnD4.TabIndex = 4;
this.bttnD4.Text = "4";
this.bttnD4.Click += new
System.EventHandler(this.bttnD4_Click);
//
// bttnD5
//
this.bttnD5.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD5.Location = new
System.Drawing.Point(96, 296);
this.bttnD5.Name = "bttnD5";
this.bttnD5.Pulse = true;
this.bttnD5.TabIndex = 5;
this.bttnD5.Text = "5";
this.bttnD5.Click += new
System.EventHandler(this.bttnD5_Click);
//
// bttnD6
//
this.bttnD6.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD6.Location = new
System.Drawing.Point(144, 296);
this.bttnD6.Name = "bttnD6";
this.bttnD6.Pulse = true;
this.bttnD6.TabIndex = 6;
this.bttnD6.Text = "6";
this.bttnD6.Click += new
System.EventHandler(this.bttnD6_Click);
//
// bttnD7
//
this.bttnD7.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD7.Location = new
System.Drawing.Point(48, 264);
this.bttnD7.Name = "bttnD7";
this.bttnD7.Pulse = true;
this.bttnD7.TabIndex = 7;
this.bttnD7.Text = "7";
this.bttnD7.Click += new
System.EventHandler(this.bttnD7_Click);
//
// bttnD8
//
this.bttnD8.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD8.Location = new
System.Drawing.Point(96, 264);
this.bttnD8.Name = "bttnD8";
this.bttnD8.Pulse = true;
this.bttnD8.TabIndex = 8;
this.bttnD8.Text = "8";
this.bttnD8.Click += new
System.EventHandler(this.bttnD8_Click);
//
// bttnD9
//
this.bttnD9.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD9.Location = new
System.Drawing.Point(144, 264);
this.bttnD9.Name = "bttnD9";
this.bttnD9.Pulse = true;
this.bttnD9.TabIndex = 9;
this.bttnD9.Text = "9";
this.bttnD9.Click += new
System.EventHandler(this.bttnD9_Click);
//
// bttnD0
//
this.bttnD0.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD0.Location = new
System.Drawing.Point(48, 360);
this.bttnD0.Name = "bttnD0";
this.bttnD0.Pulse = true;
this.bttnD0.TabIndex = 10;
this.bttnD0.Text = "0";
this.bttnD0.Click += new
System.EventHandler(this.bttnD0_Click);
//
// bttnDiv
//
this.bttnDiv.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnDiv.Location = new
System.Drawing.Point(200, 232);
this.bttnDiv.Name = "bttnDiv";
this.bttnDiv.Pulse = true;
this.bttnDiv.TabIndex = 11;
this.bttnDiv.Text = "/";
this.bttnDiv.Click += new
System.EventHandler(this.bttnDiv_Click);
//
// bttnMul
//
this.bttnMul.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnMul.Location = new
System.Drawing.Point(200, 296);
this.bttnMul.Name = "bttnMul";
this.bttnMul.Pulse = true;
this.bttnMul.TabIndex = 12;
this.bttnMul.Text = "*";
this.bttnMul.Click += new
System.EventHandler(this.bttnMul_Click);
//
// bttnMinus
//
this.bttnMinus.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((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.EventHandler(this.bttnMinus_Click);
//
// bttnPlus
//
this.bttnPlus.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnPlus.Location = new
System.Drawing.Point(200, 328);
this.bttnPlus.Name = "bttnPlus";
this.bttnPlus.Pulse = true;
this.bttnPlus.TabIndex = 14;
this.bttnPlus.Text = "+";
this.bttnPlus.Click += new
System.EventHandler(this.bttnPlus_Click);
//
// bttnClr
//
this.bttnClr.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnClr.Location = new
System.Drawing.Point(144, 360);
this.bttnClr.Name = "bttnClr";
this.bttnClr.Pulse = true;
this.bttnClr.TabIndex = 15;
this.bttnClr.Text = "C";
this.bttnClr.Click += new
System.EventHandler(this.bttnClr_Click);
//
// bttnDot
//
this.bttnDot.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnDot.Location = new
System.Drawing.Point(96, 360);
this.bttnDot.Name = "bttnDot";
this.bttnDot.Pulse = true;
this.bttnDot.TabIndex = 16;
this.bttnDot.Text = ".";
this.bttnDot.Click += new
System.EventHandler(this.bttnDot_Click);
//
// bttnEqual
//
this.bttnEqual.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((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.EventHandler(this.bttnEqual_Click);
//
// BFCDisplA
//
this.BFCDisplA.BackColor =
System.Drawing.Color.LightSkyBlue;
this.BFCDisplA.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.BFCDisplA.Font = new
System.Drawing.Font("Lucida Console", 12F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.BFCDisplA.ForeColor =
System.Drawing.SystemColors.Highlight;
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.ContentAlignment.MiddleRight;
//
// CalcBtnPwr
//
this.CalcBtnPwr.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((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.EventHandler(this.CalcBtnPwr_Click);
//
// BFCMainForm
//
this.AutoScaleBaseSize = new
System.Drawing.Size(5, 13);
this.BackColor =
System.Drawing.SystemColors.ControlText;
this.BackgroundImage =
((System.Drawing.Bitmap)(resources.GetObject("$thi s.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(304,
448);
this.Controls.AddRange(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.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.None;
this.Icon =
((System.Drawing.Icon)(resources.GetObject("$this. Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "BFCMainForm";
this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScree n;
this.Text = "BFC2k4";
this.TransparencyKey =
System.Drawing.Color.Lime;
this.Load += new
System.EventHandler(this.BFCMainForm_Load;
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new BFCMainForm());

}

private void bttnD0_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD0);
Invalidate();
}

private void bttnD1_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD1);
Invalidate();

}

private void bttnD2_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD2);
Invalidate();
}

private void bttnD3_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD3);
Invalidate();
}

private void bttnD4_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD4);
Invalidate();
}

private void bttnD5_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD5);
Invalidate();
}

private void bttnD6_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD6);
Invalidate();
}

private void bttnD7_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD7);
Invalidate();
}

private void bttnD8_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD8);
Invalidate();
}

private void bttnD9_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD9);
Invalidate();
}

private void bttnDiv_Click(object sender,
System.EventArgs e)
{
AddOperatorToArray(bttnDiv);
Invalidate();
}

private void bttnMul_Click(object sender,
System.EventArgs e)
{
AddOperatorToArray(bttnMul);
Invalidate();
}

private void bttnMinus_Click(object sender,
System.EventArgs e)
{
AddOperatorToArray(bttnMinus);
Invalidate();
}

private void bttnPlus_Click(object sender,
System.EventArgs e)
{
AddOperatorToArray(bttnPlus);
Invalidate();
}

private void bttnDot_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnDot) ;
bttnDot.Enabled = false ;
Invalidate();
}

private void bttnClr_Click(object sender,
System.EventArgs e)
{
Reset();
Invalidate();
}

private void bttnEqual_Click(object sender,
System.EventArgs e)
{
try
{
BFCArray1.Add(BFCValue1)
;
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.Count ;
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.Length
; i++ )
{
if( BFCValue1[i].ToString() ==
"." )
{
bttnDot.Enabled =
false
;
break
;
}
else
{
bttnDot.Enabled = true
;
}
}

bttnEqual.Enabled = false
;
}
catch(Exception exception)
{

MessageBox.Show(exception.Message,"Error") ;
}
Invalidate();
}

private void CalcBtnPwr_Click(object sender,
System.EventArgs e)
{
this.Close();
}

private void BFCMainForm_Load(object sender,
System.EventArgs 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.Reflection;
using System.ComponentModel;
using System.ComponentModel.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.ButtonDesigner))]
public class Button : System.Windows.Forms.Button
{
#region Class Constants

protected static int ButtonDefaultWidth = 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 ButtonShadowOffset = 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 PulseGammaReductionThreshold =
0.2f;
protected static float PulseGammaShiftReduction =
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( )
{
InitializeComponent( );
SetStyle( ControlStyles.StandardClick, true );
}

private void InitializeComponent( )
{
}

#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.ButtonDefaultWidth,
Button.ButtonHeight ); }
}

/* 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();
InitializeGraphics();
}

protected override void OnTextChanged( EventArgs e )
{
if (sizeToLabel)
{
Graphics g = this.CreateGraphics( );
SizeF sizeF = g.MeasureString( Text,
Font );
Width = imgLeft.Width +
(int)sizeF.Width + imgRight.Width;
g.Dispose();
}
Invalidate( );
Update( );
base.OnTextChanged( 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.OnLostFocus( e );

if (Pulse)
StopPulsing();
}

protected override void OnMouseDown( MouseEventArgs e
)
{
base.OnMouseDown( e );

if( e.Button == MouseButtons.Left )
{
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.OnMouseMove( e );

if( mousePressed && ( e.Button &
MouseButtons.Left ) != 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( KeyPressEventArgs
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.png" );
imgRight = new Bitmap( GetType(),
"Button.right.png" );
imgFill = new Bitmap( GetType(),
"Button.fill.png" );
}

protected virtual void InitializeGraphics ()
{
// 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.Matrix33 = 0.5f; // reduce opacity
by 50%

iaDefault = new ImageAttributes();
iaDefault.SetColorMatrix( cmDefault,
ColorMatrixFlag.Default,
ColorAdjustType.Bitmap );

// Image attributes that lighten and
desaturate normal buttons

cmNormal = new ColorMatrix();

// desaturate the image
cmNormal.Matrix00 = 1/3f;
cmNormal.Matrix01 = 1/3f;
cmNormal.Matrix02 = 1/3f;
cmNormal.Matrix10 = 1/3f;
cmNormal.Matrix11 = 1/3f;
cmNormal.Matrix12 = 1/3f;
cmNormal.Matrix20 = 1/3f;
cmNormal.Matrix21 = 1/3f;
cmNormal.Matrix22 = 1/3f;
cmNormal.Matrix33 = 0.5f; // reduce opacity
by 50%

iaNormal = new ImageAttributes();
iaNormal.SetColorMatrix( cmNormal,
ColorMatrixFlag.Default,
ColorAdjustType.Bitmap );
}

protected virtual void StartPulsing ()
{
if ( Focused && Pulse &&
!this.DesignModeDetected( ) )
{
timer = new Timer( );
timer.Interval = Button.PulseInterval;
timer.Tick += new EventHandler(
TimerOnTick );
gamma = Button.PulseGammaMax;
gammaShift = -Button.PulseGammaShift;
timer.Start();
}
}

protected virtual void StopPulsing ()
{
if ( timer != null )
{
iaDefault.SetGamma( 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.Pixel, ia );

g.DrawImage( imgRight, rcRight, 0, 0,
imgRight.Width, imgRight.Height,
GraphicsUnit.Pixel, 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.ButtonShadowOffset );

int LabelShadowOffset = 1;

StringFormat fmt = new StringFormat( );
fmt.Alignment =
StringAlignment.Center;
fmt.LineAlignment =
StringAlignment.Center;

// Draw the shadow below the label
layoutRect.Offset( 0, LabelShadowOffset );
SolidBrush textShadowBrush = new
SolidBrush( Color.Gray );
g.DrawString( Text, Font, textShadowBrush,
layoutRect, fmt );
textShadowBrush.Dispose( );

// and the label itself
layoutRect.Offset( 0, -LabelShadowOffset );
SolidBrush brushFiller = new SolidBrush(
Color.Black );
g.DrawString( Text, Font, brushFiller,
layoutRect, fmt );
brushFiller.Dispose( );
}

protected virtual void TimerOnTick( object obj,
EventArgs e)
{
// set the new gamma level
if ((gamma - Button.PulseGammaMin <
Button.PulseGammaReductionThreshold ) ||
(Button.PulseGammaMax - gamma <
Button.PulseGammaReductionThreshold ))
gamma += gammaShift *
Button.PulseGammaShiftReduction;
else
gamma += gammaShift;

if ( gamma <= Button.PulseGammaMin || gamma >=
Button.PulseGammaMax )
gammaShift = -gammaShift;

iaDefault.SetGamma( gamma,
ColorAdjustType.Bitmap );

Invalidate( );
Update( );
}

protected virtual bool DesignModeDetected()
{
// 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
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
MyNameIsnt,

Without knowing what Wildgrape is (or having access to it), it is hard
to tell. Can you give some more information on it?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"MyNameIsnt" <no*@here.com> wrote in message
news:6h********************************@4ax.com...
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.Collections;
using System.ComponentModel;
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.ComponentModel.Container components =
null;

public BFCMainForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

// Set the application title bar
Version ver = new
Version(Application.ProductVersion);
this.Text = String.Format("BFC-2k4
{0:#}.{1:#}.{2:#}", ver.Major, ver.Minor,ver.Build);
Icon = new
Icon(typeof(BFCMainForm), "DedHed.ico");

//
// TODO: Add any constructor code after
InitializeComponent call
//
BFCValue1 = ""
;
BFCArray1 = new
ArrayList();
}
private void AddOperatorToArray(Button bttn)
{
BFCArray1.Add( BFCValue1 ) ;
BFCDisplA.Text +=
bttn.Text;
BFCValue1
= "";
BFCArray1.Add( bttn.Text );
bttnDot.Enabled = true ;
SetEnableOperatorBttns(false);
BFCDisplA.Text = "";
Invalidate();

}
private void AddToArray(Button bttn)
{
BFCValue1 = bttn.Text;
// somewhere in here
BFCDisplA.Text = bttn.Text;
// is the double # trouble
SetEnableOperatorBttns(true);
Invalidate();
}

private void Reset()
{
BFCValue1 = "";
BFCDisplA.Text = "";
BFCArray1.Clear() ;
bttnDot.Enabled = true;
}

private void SetEnableOperatorBttns(bool enable)
{
bttnPlus.Enabled = enable ;
bttnMinus.Enabled = enable ;
bttnMul.Enabled = enable ;
bttnDiv.Enabled = enable ;
bttnEqual.Enabled = enable ;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
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 InitializeComponent()
{
System.Resources.ResourceManager resources =
new System.Resources.ResourceManager(typeof(BFCMainFor m));
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.SuspendLayout();
//
// bttnD1
//
this.bttnD1.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD1.Location = new
System.Drawing.Point(48, 328);
this.bttnD1.Name = "bttnD1";
this.bttnD1.Pulse = true;
this.bttnD1.TabIndex = 1;
this.bttnD1.Text = "1";
this.bttnD1.Click += new
System.EventHandler(this.bttnD1_Click);
//
// bttnD2
//
this.bttnD2.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD2.Location = new
System.Drawing.Point(96, 328);
this.bttnD2.Name = "bttnD2";
this.bttnD2.Pulse = true;
this.bttnD2.TabIndex = 2;
this.bttnD2.Text = "2";
this.bttnD2.Click += new
System.EventHandler(this.bttnD2_Click);
//
// bttnD3
//
this.bttnD3.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD3.Location = new
System.Drawing.Point(144, 328);
this.bttnD3.Name = "bttnD3";
this.bttnD3.Pulse = true;
this.bttnD3.TabIndex = 3;
this.bttnD3.Text = "3";
this.bttnD3.Click += new
System.EventHandler(this.bttnD3_Click);
//
// bttnD4
//
this.bttnD4.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD4.Location = new
System.Drawing.Point(48, 296);
this.bttnD4.Name = "bttnD4";
this.bttnD4.Pulse = true;
this.bttnD4.TabIndex = 4;
this.bttnD4.Text = "4";
this.bttnD4.Click += new
System.EventHandler(this.bttnD4_Click);
//
// bttnD5
//
this.bttnD5.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD5.Location = new
System.Drawing.Point(96, 296);
this.bttnD5.Name = "bttnD5";
this.bttnD5.Pulse = true;
this.bttnD5.TabIndex = 5;
this.bttnD5.Text = "5";
this.bttnD5.Click += new
System.EventHandler(this.bttnD5_Click);
//
// bttnD6
//
this.bttnD6.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD6.Location = new
System.Drawing.Point(144, 296);
this.bttnD6.Name = "bttnD6";
this.bttnD6.Pulse = true;
this.bttnD6.TabIndex = 6;
this.bttnD6.Text = "6";
this.bttnD6.Click += new
System.EventHandler(this.bttnD6_Click);
//
// bttnD7
//
this.bttnD7.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD7.Location = new
System.Drawing.Point(48, 264);
this.bttnD7.Name = "bttnD7";
this.bttnD7.Pulse = true;
this.bttnD7.TabIndex = 7;
this.bttnD7.Text = "7";
this.bttnD7.Click += new
System.EventHandler(this.bttnD7_Click);
//
// bttnD8
//
this.bttnD8.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD8.Location = new
System.Drawing.Point(96, 264);
this.bttnD8.Name = "bttnD8";
this.bttnD8.Pulse = true;
this.bttnD8.TabIndex = 8;
this.bttnD8.Text = "8";
this.bttnD8.Click += new
System.EventHandler(this.bttnD8_Click);
//
// bttnD9
//
this.bttnD9.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD9.Location = new
System.Drawing.Point(144, 264);
this.bttnD9.Name = "bttnD9";
this.bttnD9.Pulse = true;
this.bttnD9.TabIndex = 9;
this.bttnD9.Text = "9";
this.bttnD9.Click += new
System.EventHandler(this.bttnD9_Click);
//
// bttnD0
//
this.bttnD0.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnD0.Location = new
System.Drawing.Point(48, 360);
this.bttnD0.Name = "bttnD0";
this.bttnD0.Pulse = true;
this.bttnD0.TabIndex = 10;
this.bttnD0.Text = "0";
this.bttnD0.Click += new
System.EventHandler(this.bttnD0_Click);
//
// bttnDiv
//
this.bttnDiv.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnDiv.Location = new
System.Drawing.Point(200, 232);
this.bttnDiv.Name = "bttnDiv";
this.bttnDiv.Pulse = true;
this.bttnDiv.TabIndex = 11;
this.bttnDiv.Text = "/";
this.bttnDiv.Click += new
System.EventHandler(this.bttnDiv_Click);
//
// bttnMul
//
this.bttnMul.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnMul.Location = new
System.Drawing.Point(200, 296);
this.bttnMul.Name = "bttnMul";
this.bttnMul.Pulse = true;
this.bttnMul.TabIndex = 12;
this.bttnMul.Text = "*";
this.bttnMul.Click += new
System.EventHandler(this.bttnMul_Click);
//
// bttnMinus
//
this.bttnMinus.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((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.EventHandler(this.bttnMinus_Click);
//
// bttnPlus
//
this.bttnPlus.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnPlus.Location = new
System.Drawing.Point(200, 328);
this.bttnPlus.Name = "bttnPlus";
this.bttnPlus.Pulse = true;
this.bttnPlus.TabIndex = 14;
this.bttnPlus.Text = "+";
this.bttnPlus.Click += new
System.EventHandler(this.bttnPlus_Click);
//
// bttnClr
//
this.bttnClr.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnClr.Location = new
System.Drawing.Point(144, 360);
this.bttnClr.Name = "bttnClr";
this.bttnClr.Pulse = true;
this.bttnClr.TabIndex = 15;
this.bttnClr.Text = "C";
this.bttnClr.Click += new
System.EventHandler(this.bttnClr_Click);
//
// bttnDot
//
this.bttnDot.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.bttnDot.Location = new
System.Drawing.Point(96, 360);
this.bttnDot.Name = "bttnDot";
this.bttnDot.Pulse = true;
this.bttnDot.TabIndex = 16;
this.bttnDot.Text = ".";
this.bttnDot.Click += new
System.EventHandler(this.bttnDot_Click);
//
// bttnEqual
//
this.bttnEqual.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((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.EventHandler(this.bttnEqual_Click);
//
// BFCDisplA
//
this.BFCDisplA.BackColor =
System.Drawing.Color.LightSkyBlue;
this.BFCDisplA.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.BFCDisplA.Font = new
System.Drawing.Font("Lucida Console", 12F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.BFCDisplA.ForeColor =
System.Drawing.SystemColors.Highlight;
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.ContentAlignment.MiddleRight;
//
// CalcBtnPwr
//
this.CalcBtnPwr.Font = new
System.Drawing.Font("Microsoft Sans Serif", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((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.EventHandler(this.CalcBtnPwr_Click);
//
// BFCMainForm
//
this.AutoScaleBaseSize = new
System.Drawing.Size(5, 13);
this.BackColor =
System.Drawing.SystemColors.ControlText;
this.BackgroundImage =
((System.Drawing.Bitmap)(resources.GetObject("$thi s.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(304,
448);
this.Controls.AddRange(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.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.None;
this.Icon =
((System.Drawing.Icon)(resources.GetObject("$this. Icon")));
this.MaximizeBox = false;
this.MnimizeBox = false;
this.Name = "BFCMainForm";
this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScree n;
this.Text = "BFC2k4";
this.TransparencyKey =
System.Drawing.Color.Lime;
this.Load += new
System.EventHandler(this.BFCMainForm_Load);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new BFCMainForm());

}

private void bttnD0_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD0);
Invalidate();
}

private void bttnD1_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD1);
Invalidate();

}

private void bttnD2_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD2);
Invalidate();
}

private void bttnD3_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD3);
Invalidate();
}

private void bttnD4_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD4);
Invalidate();
}

private void bttnD5_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD5);
Invalidate();
}

private void bttnD6_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD6);
Invalidate();
}

private void bttnD7_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD7);
Invalidate();
}

private void bttnD8_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD8);
Invalidate();
}

private void bttnD9_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnD9);
Invalidate();
}

private void bttnDiv_Click(object sender,
System.EventArgs e)
{
AddOperatorToArray(bttnDiv);
Invalidate();
}

private void bttnMul_Click(object sender,
System.EventArgs e)
{
AddOperatorToArray(bttnMul);
Invalidate();
}

private void bttnMinus_Click(object sender,
System.EventArgs e)
{
AddOperatorToArray(bttnMinus);
Invalidate();
}

private void bttnPlus_Click(object sender,
System.EventArgs e)
{
AddOperatorToArray(bttnPlus);
Invalidate();
}

private void bttnDot_Click(object sender,
System.EventArgs e)
{
AddToArray(bttnDot) ;
bttnDot.Enabled = false ;
Invalidate();
}

private void bttnClr_Click(object sender,
System.EventArgs e)
{
Reset();
Invalidate();
}

private void bttnEqual_Click(object sender,
System.EventArgs e)
{
try
{
BFCArray1.Add(BFCValue1)
;
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.Count ;
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.Length
; i++ )
{
if( BFCValue1[i].ToString() ==
"." )
{
bttnDot.Enabled =
false
;
break
;
}
else
{
bttnDot.Enabled = true
;
}
}

bttnEqual.Enabled = false
;
}
catch(Exception exception)
{

MessageBox.Show(exception.Message,"Error") ;
}
Invalidate();
}

private void CalcBtnPwr_Click(object sender,
System.EventArgs e)
{
this.Close();
}

private void BFCMainForm_Load(object sender,
System.EventArgs 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.Reflection;
using System.ComponentModel;
using System.ComponentModel.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.ButtonDesigner))]
public class Button : System.Windows.Forms.Button
{
#region Class Constants

protected static int ButtonDefaultWidth = 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 ButtonShadowOffset = 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 PulseGammaReductionThreshold =
0.2f;
protected static float PulseGammaShiftReduction =
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( )
{
InitializeComponent( );
SetStyle( ControlStyles.StandardClick, true );
}

private void InitializeComponent( )
{
}

#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.ButtonDefaultWidth,
Button.ButtonHeight ); }
}

/* 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();
InitializeGraphics();
}

protected override void OnTextChanged( EventArgs e )
{
if (sizeToLabel)
{
Graphics g = this.CreateGraphics( );
SizeF sizeF = g.MeasureString( Text,
Font );
Width = imgLeft.Width +
(int)sizeF.Width + imgRight.Width;
g.Dispose();
}
Invalidate( );
Update( );
base.OnTextChanged( 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.OnLostFocus( e );

if (Pulse)
StopPulsing();
}

protected override void OnMouseDown( MouseEventArgs e
)
{
base.OnMouseDown( e );

if( e.Button == MouseButtons.Left )
{
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.OnMouseMove( e );

if( mousePressed && ( e.Button &
MouseButtons.Left ) != 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( KeyPressEventArgs
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.png" );
imgRight = new Bitmap( GetType(),
"Button.right.png" );
imgFill = new Bitmap( GetType(),
"Button.fill.png" );
}

protected virtual void InitializeGraphics ()
{
// 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.Matrix33 = 0.5f; // reduce opacity
by 50%

iaDefault = new ImageAttributes();
iaDefault.SetColorMatrix( cmDefault,
ColorMatrixFlag.Default,
ColorAdjustType.Bitmap );

// Image attributes that lighten and
desaturate normal buttons

cmNormal = new ColorMatrix();

// desaturate the image
cmNormal.Matrix00 = 1/3f;
cmNormal.Matrix01 = 1/3f;
cmNormal.Matrix02 = 1/3f;
cmNormal.Matrix10 = 1/3f;
cmNormal.Matrix11 = 1/3f;
cmNormal.Matrix12 = 1/3f;
cmNormal.Matrix20 = 1/3f;
cmNormal.Matrix21 = 1/3f;
cmNormal.Matrix22 = 1/3f;
cmNormal.Matrix33 = 0.5f; // reduce opacity
by 50%

iaNormal = new ImageAttributes();
iaNormal.SetColorMatrix( cmNormal,
ColorMatrixFlag.Default,
ColorAdjustType.Bitmap );
}

protected virtual void StartPulsing ()
{
if ( Focused && Pulse &&
!this.DesignModeDetected( ) )
{
timer = new Timer( );
timer.Interval = Button.PulseInterval;
timer.Tick += new EventHandler(
TimerOnTick );
gamma = Button.PulseGammaMax;
gammaShift = -Button.PulseGammaShift;
timer.Start();
}
}

protected virtual void StopPulsing ()
{
if ( timer != null )
{
iaDefault.SetGamma( 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.Pixel, ia );

g.DrawImage( imgRight, rcRight, 0, 0,
imgRight.Width, imgRight.Height,
GraphicsUnit.Pixel, 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.ButtonShadowOffset );

int LabelShadowOffset = 1;

StringFormat fmt = new StringFormat( );
fmt.Alignment =
StringAlignment.Center;
fmt.LineAlignment =
StringAlignment.Center;

// Draw the shadow below the label
layoutRect.Offset( 0, LabelShadowOffset );
SolidBrush textShadowBrush = new
SolidBrush( Color.Gray );
g.DrawString( Text, Font, textShadowBrush,
layoutRect, fmt );
textShadowBrush.Dispose( );

// and the label itself
layoutRect.Offset( 0, -LabelShadowOffset );
SolidBrush brushFiller = new SolidBrush(
Color.Black );
g.DrawString( Text, Font, brushFiller,
layoutRect, fmt );
brushFiller.Dispose( );
}

protected virtual void TimerOnTick( object obj,
EventArgs e)
{
// set the new gamma level
if ((gamma - Button.PulseGammaMin <
Button.PulseGammaReductionThreshold ) ||
(Button.PulseGammaMax - gamma <
Button.PulseGammaReductionThreshold ))
gamma += gammaShift *
Button.PulseGammaShiftReduction;
else
gamma += gammaShift;

if ( gamma <= Button.PulseGammaMin || gamma >=
Button.PulseGammaMax )
gammaShift = -gammaShift;

iaDefault.SetGamma( gamma,
ColorAdjustType.Bitmap );

Invalidate( );
Update( );
}

protected virtual bool DesignModeDetected()
{
// 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

Nov 15 '05 #2

P: n/a
Wildgrape is an XP style button I attatched the .cs file to the end. I
did figure out this problem already tho. the mousedown event was
firing twice.

I would like to know how to drag a borderless form if you have any
suggestions tho :)

thanks for replying
Sean

On Wed, 19 Nov 2003 10:57:56 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
MyNameIsnt,

Without knowing what Wildgrape is (or having access to it), it is hard
to tell. Can you give some more information on it?


Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.