using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D;
namespace AquaControls
{ /// <summary> /// Aqua Gauge Control - A Windows User Control. /// Author : Ambalavanar Thirugnanam /// Date : 24th August 2007 /// email : ambalavanar.thiru@gmail.com /// This is control is for free. You can use for any commercial or non-commercial purposes. /// [Please do no remove this header when using this control in your application.] /// </summary> publicpartialclass AquaGauge : UserControl
{ #regionPrivate Attributes privatefloat minValue; privatefloat maxValue; privatefloat threshold; privatefloat currentValue; privatefloat recommendedValue; privateint noOfDivisions; privateint noOfSubDivisions; privatestring dialText; private Color dialColor = Color.Lavender; privatefloat glossinessAlpha = 25; privateint oldWidth, oldHeight; int x, y, width, height; float fromAngle = 135F; float toAngle = 405F; privatebool enableTransparentBackground; privatebool requiresRedraw; private Image backgroundImg; private Rectangle rectImg; #endregion
#regionPublic Properties /// <summary> /// Mininum value on the scale /// </summary>
[DefaultValue(0)]
[Description("Mininum value on the scale")] publicfloat MinValue
{ get { return minValue; } set
{ if (value < maxValue)
{
minValue = value; if (currentValue < minValue)
currentValue = minValue; if (recommendedValue < minValue)
recommendedValue = minValue;
requiresRedraw = true; this.Invalidate();
}
}
}
/// <summary> /// Maximum value on the scale /// </summary>
[DefaultValue(100)]
[Description("Maximum value on the scale")] publicfloat MaxValue
{ get { return maxValue; } set
{ if (value > minValue)
{
maxValue = value; if (currentValue > maxValue)
currentValue = maxValue; if (recommendedValue > maxValue)
recommendedValue = maxValue;
requiresRedraw = true; this.Invalidate();
}
}
}
/// <summary> /// Gets or Sets the Threshold area from the Recommended Value. (1-99%) /// </summary>
[DefaultValue(25)]
[Description("Gets or Sets the Threshold area from the Recommended Value. (1-99%)")] publicfloat ThresholdPercent
{ get { return threshold; } set
{ if (value > 0 && value < 100)
{
threshold = value;
requiresRedraw = true; this.Invalidate();
}
}
}
/// <summary> /// Threshold value from which green area will be marked. /// </summary>
[DefaultValue(25)]
[Description("Threshold value from which green area will be marked.")] publicfloat RecommendedValue
{ get { return recommendedValue; } set
{ if (value > minValue && value < maxValue)
{
recommendedValue = value;
requiresRedraw = true; this.Invalidate();
}
}
}
/// <summary> /// Value where the pointer will point to. /// </summary>
[DefaultValue(0)]
[Description("Value where the pointer will point to.")] publicfloat Value
{ get { return currentValue; } set
{ if (value >= minValue && value <= maxValue)
{
currentValue = value; this.Refresh();
}
}
}
/// <summary> /// Background color of the dial /// </summary>
[Description("Background color of the dial")] public Color DialColor
{ get { return dialColor; } set
{
dialColor = value;
requiresRedraw = true; this.Invalidate();
}
}
/// <summary> /// Get or Sets the number of Divisions in the dial scale. /// </summary>
[DefaultValue(10)]
[Description("Get or Sets the number of Divisions in the dial scale.")] publicint NoOfDivisions
{ get { returnthis.noOfDivisions; } set
{ if (value > 1 && value < 25)
{ this.noOfDivisions = value;
requiresRedraw = true; this.Invalidate();
}
}
}
/// <summary> /// Gets or Sets the number of Sub Divisions in the scale per Division. /// </summary>
[DefaultValue(3)]
[Description("Gets or Sets the number of Sub Divisions in the scale per Division.")] publicint NoOfSubDivisions
{ get { returnthis.noOfSubDivisions; } set
{ if (value > 0 && value <= 10)
{ this.noOfSubDivisions = value;
requiresRedraw = true; this.Invalidate();
}
}
}
/// <summary> /// Gets or Sets the Text to be displayed in the dial /// </summary>
[Description("Gets or Sets the Text to be displayed in the dial")] publicstring DialText
{ get { returnthis.dialText; } set
{ this.dialText = value;
requiresRedraw = true; this.Invalidate();
}
}
/// <summary> /// Enables or Disables Transparent Background color. /// Note: Enabling this will reduce the performance and may make the control flicker. /// </summary>
[DefaultValue(false)]
[Description("Enables or Disables Transparent Background color. Note: Enabling this will reduce the performance and may make the control flicker.")] publicbool EnableTransparentBackground
{ get { returnthis.enableTransparentBackground; } set
{ this.enableTransparentBackground = value; this.SetStyle(ControlStyles.OptimizedDoubleBuffer, !enableTransparentBackground);
requiresRedraw = true; this.Refresh();
}
} #endregion
//Draw decimal point if (dp)
{
g.FillEllipse(fillPen.Brush, new RectangleF(
position.X + GetX(10F, width),
position.Y + GetY(12F, height),
width/7,
width/7));
}
}
/// <summary> /// Gets Relative X for the given width to draw digit /// </summary> /// <param name="x"></param> /// <param name="width"></param> /// <returns></returns> privatefloat GetX(float x, float width)
{ return x * width / 12;
}
/// <summary> /// Gets relative Y for the given height to draw digit /// </summary> /// <param name="y"></param> /// <param name="height"></param> /// <returns></returns> privatefloat GetY(float y, float height)
{ return y * height / 15;
}
/// <summary> /// Returns true if a given number is available in the given list. /// </summary> /// <param name="number"></param> /// <param name="listOfNumbers"></param> /// <returns></returns> privatebool IsNumberAvailable(int number, paramsint[] listOfNumbers)
{ if (listOfNumbers.Length > 0)
{ foreach (int i in listOfNumbers)
{ if (i == number) returntrue;
}
} returnfalse;
}
/// <summary> /// Restricts the size to make sure the height and width are always same. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> privatevoid AquaGauge_Resize(object sender, EventArgs e)
{ if (this.Width < 136)
{ this.Width = 136;
} if (oldWidth != this.Width)
{ this.Height = this.Width;
oldHeight = this.Width;
} if (oldHeight != this.Height)
{ this.Width = this.Height;
oldWidth = this.Width;
}
} #endregion
}
}
¤ Dauer der Verarbeitung: 0.19 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.