C# User Controls for Indicators
How do you do in reflecting the communication status, operation status, etc. with a nice eye-catching indicator?
Ideas (GDI)
- The outer ring is drawn with a pen (Pen) and the inner circle with a brush (SolidBrush); the
Two methods (drawing a circle with a pen and filling the inside of the circle with a brush):
- Draw ellipse/circle defined by boundary RectangleF
DrawEllipse(Pen pen,RectangleF rect)
- Fill the interior of the ellipse that defines the border of RectangleF
FillEllipse(Brush brush,RectangleF rect)
Defining Properties
- Indicator color, gap between outer ring and boundary, gap between inner circle and boundary, width of outer ring, current color
//Outer ring width
private float outWidth = 4.0f;
[Browsable(true)]
[Category("opening (chess jargon)_G")]
[Description("Width of outer ring")]
public float OutWidth
{
get { return outWidth; }
set
{
if (value <=0||value<0.1* ) return;
outWidth = value; ();
}
}
//Color (Color) - Remarks: Write 5 color attributes (Gray=Gray, Brown=DarkGoldenrod, Red=Red, Blue=Blue, Green=limeGreen<better looking than Green>)
private Color zcolor1 = ; //Gray ....... Write 5 types
[Browsable(true)]
[Category("Layout_G")]
[Description("Color1")]
public Color ZColor1
{
get { return zcolor1; }
set { zcolor1 = value; (); }
}
// Current color get (define a private method) (Int)
private Color GetCurColor()
{
List<Color> colors = new List<Color>();
(zcolor1);
(zcolor2); (zcolor2);
(zcolor4); (zcolor5).
return colors[curValue]; }
}
// Gap (float), the properties are all the same knock down is
Note: the gap sets the range of values (the outer ring gap should be less than the inner circle gap)
GDI plotting graphics: (outer ring, inner circle)
Color getCurColor = GetCurColor(); //get the current color
// draw the outer ring (DrawEllipse - draw an ellipse with a pen)
p = new Pen(getCurColor, outWidth);
RectangleF rec = new RectangleF(, , - 2 * , - 2 * gapOut);
(p, rec);
// Draw the inner circle (FillEllipse - fill the inside of the ellipse)
sb = new SolidBrush(getCurColor);
(sb, rec);
final generation(Wouldn't it be more user friendly if it blinked)
Two flashing methods
The key is in the use of the timer timer, where the variable turnover is defined in the timer's Tick method
[1] Inner circle blinking only (define inner circle brush color Transparent<transparent color>, GetCurColor<current color> two brushes)
if ( == true)
{
if ( == true) // invert the blink flag bit in the Tick method of the timer (blink=!blink)
{
sb = new SolidBrush(zcolor6); // zcolor6 is transparent color
}
else
{
sb = new SolidBrush(getCurColor); //getCurColor is the current color
}
}
else
{
sb = new SolidBrush(getCurColor); //define the current color brush if it doesn't flash
}
rec = new RectangleF(gapIn, gapIn, - 2 * , - 2 * gapIn); //Create the current color brush without blinking; //Create the current color brush without blinking }
(sb, rec).
[2] The whole thing blinks (define the Visible of the control).
private void MyTimer_Tick(object sender, EventArgs e) //Timer Tick event method
{
if ( == true)
{
// Show and hide the control
=! ; //Overall blinking can just define Visible
=false; }
}
else
{
//Inner circle blinking flag
= ! ;
}
();
}
[3] Frequency adjustable (Timer Interval)
private bool flickerAct = false;
[Browsable(true)]
[Category("Layout_G")]
[Description("Whether to blink")]
public bool FlickerAct
{
get { return flickerAct; }
set
{
if (value == true)
{
= ; // Just pass an int (milliseconds refresh rate) value to the timer Interval
(); //Blink timer start
}
else
{
(); //No blinking timer stops; also set flags and display to default values.
= false; //Flicker timer start
= true; }
}
flickerAct = value; ();
}
}
Cover your face.
Wanted binary usage example
private void led1_Load(object sender, EventArgs e)
EventArgs e) {
EventArgs e { bool b = false; bool b = false; bool b = false; bool b = false
// Just define two colors for the ternary operation.
this. = b ? 2 : 3; }
}
End