// ***********************************************************************
// Assembly : HZH_Controls
// Created : 2019-09-06
//
// ***********************************************************************
//
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
//
//
// Blog: https://www.cnblogs.com/bfyx
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
//
// If you use this code, please keep this note.
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
namespace HZH_Controls.Controls
{
///
/// Class UCPond.
/// Implements the
///
///
public class UCPond : UserControl
{
///
/// The maximum value
///
private decimal maxValue = 100;
///
/// Gets or sets the maximum value.
///
/// The maximum value.
[Description("最大值"), Category("自定义")]
public decimal MaxValue
{
get { return maxValue; }
set
{
if (value < m_value)
return;
maxValue = value;
Refresh();
}
}
///
/// The m value
///
private decimal m_value = 0;
///
/// Gets or sets the value.
///
/// The value.
[Description("值"), Category("自定义")]
public decimal Value
{
get { return m_value; }
set
{
if (value < 0)
return;
if (value > maxValue)
m_value = maxValue;
else
m_value = value;
Refresh();
}
}
///
/// The wall color
///
private Color wallColor = Color.FromArgb(255, 77, 59);
///
/// Gets or sets the color of the wall.
///
/// The color of the wall.
[Description("池壁颜色"), Category("自定义")]
public Color WallColor
{
get { return wallColor; }
set
{
wallColor = value;
Refresh();
}
}
///
/// The wall width
///
private int wallWidth = 2;
///
/// Gets or sets the width of the wall.
///
/// The width of the wall.
[Description("池壁宽度"), Category("自定义")]
public int WallWidth
{
get { return wallWidth; }
set
{
if (value <= 0)
return;
wallWidth = value;
Refresh();
}
}
///
/// The liquid color
///
private Color liquidColor = Color.FromArgb(3, 169, 243);
///
/// Gets or sets the color of the liquid.
///
/// The color of the liquid.
[Description("液体颜色"), Category("自定义")]
public Color LiquidColor
{
get { return liquidColor; }
set { liquidColor = value; }
}
///
/// Initializes a new instance of the class.
///
public UCPond()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.Selectable, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.Size = new Size(150, 50);
}
///
/// 引发 事件。
///
/// 包含事件数据的 。
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (Height <= 0)
return;
var g = e.Graphics;
g.SetGDIHigh();
int intHeight = (int)(m_value / maxValue * this.Height);
if (intHeight != 0)
{
g.FillRectangle(new SolidBrush(liquidColor), new Rectangle(0, this.Height - intHeight, this.Width, intHeight));
}
//划边
g.FillRectangle(new SolidBrush(wallColor), 0, 0, wallWidth, this.Height);
g.FillRectangle(new SolidBrush(wallColor), 0, this.Height - wallWidth, this.Width, wallWidth);
g.FillRectangle(new SolidBrush(wallColor), this.Width - wallWidth-1, 0, wallWidth, this.Height);
}
}
}