添加项目文件。

This commit is contained in:
liming 蔡
2026-07-14 13:55:17 +08:00
parent 63759495f2
commit 8bbdf78731
335 changed files with 81415 additions and 0 deletions
+260
View File
@@ -0,0 +1,260 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JYControl
{
/// <summary>
/// Base class for the button renderers
/// </summary>
public class LBButtonRenderer : LBRendererBase
{
#region (* Variables *)
protected RectangleF rectCtrl;
protected RectangleF rectBody;
protected RectangleF rectText;
protected float drawRatio = 1.0F;
#endregion
#region (* Constructor *)
public LBButtonRenderer()
{
this.rectCtrl = new RectangleF(0, 0, 0, 0);
}
#endregion
#region (* Overrided methods *)
/// <summary>
/// Update the rectangles for drawing
/// </summary>
/// <returns></returns>
public override bool Update()
{
// Check Button object
if (this.Button == null)
throw new NullReferenceException("Invalid 'Button' object");
// Control rectangle
this.rectCtrl.X = 0;
this.rectCtrl.Y = 0;
this.rectCtrl.Width = this.Button.Width;
this.rectCtrl.Height = this.Button.Height;
if (this.Button.Style == LBButton.ButtonStyle.Circular)
{
if (rectCtrl.Width < rectCtrl.Height)
rectCtrl.Height = rectCtrl.Width;
else if (rectCtrl.Width > rectCtrl.Height)
rectCtrl.Width = rectCtrl.Height;
if (rectCtrl.Width < 10)
rectCtrl.Width = 10;
if (rectCtrl.Height < 10)
rectCtrl.Height = 10;
}
this.rectBody = this.rectCtrl;
this.rectBody.Width -= 1;
this.rectBody.Height -= 1;
this.rectText = this.rectCtrl;
this.rectText.Width -= 2;
this.rectText.Height -= 2;
// Calculate ratio
drawRatio = (Math.Min(rectCtrl.Width, rectCtrl.Height)) / 200;
if (drawRatio == 0.0)
drawRatio = 1;
return true;
}
/// <summary>
/// Draw the button object
/// </summary>
/// <param name="Gr"></param>
public override void Draw(Graphics Gr)
{
if (Gr == null)
throw new ArgumentNullException("Gr", "Invalid Graphics object");
if (this.Button == null)
throw new NullReferenceException("Invalid 'Button' object");
this.DrawBackground(Gr, this.rectCtrl);
this.DrawBody(Gr, this.rectBody);
this.DrawText(Gr, this.rectText);
}
#endregion
#region (* Properies *)
/// <summary>
/// Get the associated button object
/// </summary>
public LBButton Button
{
get { return this.Control as LBButton; }
}
#endregion
#region (* Virtual method *)
/// <summary>
/// Draw the background of the control
/// </summary>
/// <param name="Gr"></param>
/// <param name="rc"></param>
/// <returns></returns>
public virtual bool DrawBackground(Graphics Gr, RectangleF rc)
{
if (this.Button == null)
return false;
Color c = this.Button.BackColor;
SolidBrush br = new SolidBrush(c);
Pen pen = new Pen(c);
Rectangle _rcTmp = new Rectangle(0, 0, this.Button.Width, this.Button.Height);
Gr.DrawRectangle(pen, _rcTmp);
Gr.FillRectangle(br, rc);
br.Dispose();
pen.Dispose();
return true;
}
/// <summary>
/// Draw the body of the control
/// </summary>
/// <param name="Gr"></param>
/// <param name="rc"></param>
/// <returns></returns>
public virtual bool DrawBody(Graphics Gr, RectangleF rc)
{
if (this.Button == null)
return false;
Color bodyColor = this.Button.ButtonColor;
Color cDark = LBColorManager.StepColor(bodyColor, 20);
LinearGradientBrush br1 = new LinearGradientBrush(rc,
bodyColor,
cDark,
45);
if ((this.Button.Style == LBButton.ButtonStyle.Circular) ||
(this.Button.Style == LBButton.ButtonStyle.Elliptical))
{
Gr.FillEllipse(br1, rc);
}
else
{
GraphicsPath path = this.RoundedRect(rc, 15F);
Gr.FillPath(br1, path);
path.Dispose();
}
if (this.Button.State == LBButton.ButtonState.Pressed)
{
RectangleF _rc = rc;
_rc.Inflate(-15F * this.drawRatio, -15F * drawRatio);
LinearGradientBrush br2 = new LinearGradientBrush(_rc,
cDark,
bodyColor,
45);
if ((this.Button.Style == LBButton.ButtonStyle.Circular) ||
(this.Button.Style == LBButton.ButtonStyle.Elliptical))
{
Gr.FillEllipse(br2, _rc);
}
else
{
GraphicsPath path = this.RoundedRect(_rc, 10F);
Gr.FillPath(br2, path);
path.Dispose();
}
br2.Dispose();
}
br1.Dispose();
return true;
}
/// <summary>
/// Draw the text of the control
/// </summary>
/// <param name="Gr"></param>
/// <param name="rc"></param>
/// <returns></returns>
public virtual bool DrawText(Graphics Gr, RectangleF rc)
{
if (this.Button == null)
return false;
//Draw Strings
Font font = new Font(this.Button.Font.FontFamily,
this.Button.Font.Size * this.drawRatio,
this.Button.Font.Style);
String str = this.Button.Label;
Color bodyColor = this.Button.ButtonColor;
Color cDark = LBColorManager.StepColor(bodyColor, 20);
SizeF size = Gr.MeasureString(str, font);
SolidBrush br1 = new SolidBrush(bodyColor);
SolidBrush br2 = new SolidBrush(cDark);
Gr.DrawString(str,
font,
br1,
rc.Left + ((rc.Width * 0.5F) - (float)(size.Width * 0.5F)) + (float)(1 * this.drawRatio),
rc.Top + ((rc.Height * 0.5F) - (float)(size.Height * 0.5)) + (float)(1 * this.drawRatio));
Gr.DrawString(str,
font,
br2,
rc.Left + ((rc.Width * 0.5F) - (float)(size.Width * 0.5F)),
rc.Top + ((rc.Height * 0.5F) - (float)(size.Height * 0.5)));
br1.Dispose();
br2.Dispose();
font.Dispose();
return false;
}
#endregion
#region (* Protected Methods *)
protected GraphicsPath RoundedRect(RectangleF rect, float radius)
{
RectangleF baseRect = rect;
float diameter = (radius * this.drawRatio) * 2.0f;
SizeF sizeF = new SizeF(diameter, diameter);
RectangleF arc = new RectangleF(baseRect.Location, sizeF);
GraphicsPath path = new GraphicsPath();
// top left arc
path.AddArc(arc, 180, 90);
// top right arc
arc.X = baseRect.Right - diameter;
path.AddArc(arc, 270, 90);
// bottom right arc
arc.Y = baseRect.Bottom - diameter;
path.AddArc(arc, 0, 90);
// bottom left arc
arc.X = baseRect.Left;
path.AddArc(arc, 90, 90);
path.CloseFigure();
return path;
}
#endregion
}
}
+60
View File
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JYControl
{
/// <summary>
/// Manager for color
/// </summary>
public class LBColorManager : Object
{
public static double BlendColour(double fg, double bg, double alpha)
{
double result = bg + (alpha * (fg - bg));
if (result < 0.0)
result = 0.0;
if (result > 255)
result = 255;
return result;
}
public static Color StepColor(Color clr, int alpha)
{
if (alpha == 100)
return clr;
byte a = clr.A;
byte r = clr.R;
byte g = clr.G;
byte b = clr.B;
float bg = 0;
int _alpha = Math.Min(alpha, 200);
_alpha = Math.Max(alpha, 0);
double ialpha = ((double)(_alpha - 100.0)) / 100.0;
if (ialpha > 100)
{
// blend with white
bg = 255.0F;
ialpha = 1.0F - ialpha; // 0 = transparent fg; 1 = opaque fg
}
else
{
// blend with black
bg = 0.0F;
ialpha = 1.0F + ialpha; // 0 = transparent fg; 1 = opaque fg
}
r = (byte)(LBColorManager.BlendColour(r, bg, ialpha));
g = (byte)(LBColorManager.BlendColour(g, bg, ialpha));
b = (byte)(LBColorManager.BlendColour(b, bg, ialpha));
return Color.FromArgb(a, r, g, b);
}
};
}
+82
View File
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace JYControl
{
public static class ControlHelper
{
/// <summary>
/// The m LST freeze control
/// </summary>
static Dictionary<Control, bool> m_lstFreezeControl = new Dictionary<Control, bool>();
public static void FreezeControl(Control control, bool blnToFreeze)
{
if (blnToFreeze && control.IsHandleCreated && control.Visible && !control.IsDisposed && (!m_lstFreezeControl.ContainsKey(control) || (m_lstFreezeControl.ContainsKey(control) && m_lstFreezeControl[control] == false)))
{
m_lstFreezeControl[control] = true;
control.Disposed += control_Disposed;
NativeMethods.SendMessage(control.Handle, 11, 0, 0);
}
else if (!blnToFreeze && !control.IsDisposed && m_lstFreezeControl.ContainsKey(control) && m_lstFreezeControl[control] == true)
{
m_lstFreezeControl.Remove(control);
NativeMethods.SendMessage(control.Handle, 11, 1, 0);
control.Invalidate(true);
}
}
/// <summary>
/// Handles the Disposed event of the control control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
static void control_Disposed(object sender, EventArgs e)
{
try
{
if (m_lstFreezeControl.ContainsKey((Control)sender))
m_lstFreezeControl.Remove((Control)sender);
}
catch { }
}
/// <summary>
/// 设置GDI高质量模式抗锯齿
/// </summary>
/// <param name="g">The g.</param>
public static void SetGDIHigh(this Graphics g)
{
g.SmoothingMode = SmoothingMode.AntiAlias; //使绘图质量最高,即消除锯齿
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.CompositingQuality = CompositingQuality.HighQuality;
}
/// <summary>
/// 根据矩形和圆得到一个圆角矩形Path
/// </summary>
/// <param name="rect">The rect.</param>
/// <param name="cornerRadius">The corner radius.</param>
/// <returns>GraphicsPath.</returns>
public static GraphicsPath CreateRoundedRectanglePath(this Rectangle rect, int cornerRadius)
{
GraphicsPath roundedRect = new GraphicsPath();
roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);
roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);
roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
roundedRect.CloseFigure();
return roundedRect;
}
}
}
+37
View File
@@ -0,0 +1,37 @@
namespace JYControl
{
partial class LBIndustrialCtrlBase
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
}
#endregion
}
}
+249
View File
@@ -0,0 +1,249 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace JYControl
{
/// <summary>
/// Base class for the IndustrialCtrls
/// </summary>
public partial class LBIndustrialCtrlBase : UserControl
{
#region (* Constructor *)
public LBIndustrialCtrlBase()
{
InitializeComponent();
// Set the styles for drawing
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.ResizeRedraw |
ControlStyles.DoubleBuffer |
ControlStyles.SupportsTransparentBackColor,
true);
// Transparent background
this.BackColor = Color.Transparent;
// Creation of the default renderer
this._defaultRenderer = CreateDefaultRenderer();
if (this._defaultRenderer != null)
this._defaultRenderer.Control = this;
}
#endregion
#region (* Properties *)
/// <summary>
/// Default renderer of the control
/// </summary>
private ILBRenderer _defaultRenderer = null;
[Browsable(false)]
public ILBRenderer DefaultRenderer
{
get { return this._defaultRenderer; }
}
/// <summary>
/// User defined renderer
/// </summary>
private ILBRenderer _renderer = null;
[Browsable(false)]
public ILBRenderer Renderer
{
set
{
// set the renderer
this._renderer = value;
if (this._renderer != null)
{
// Set the control tu the renderer
this._renderer.Control = this;
// Update the renderer
this._renderer.Update();
}
// Redraw the renderer
Invalidate();
}
get { return this._renderer; }
}
#endregion
#region (* Events delegates *)
/// <summary>
/// Font change event
/// </summary>
/// <param name="e"></param>
[System.ComponentModel.EditorBrowsableAttribute()]
protected override void OnFontChanged(EventArgs e)
{
// Calculate dimensions
this.CalculateDimensions();
}
/// <summary>
/// SizeChanged event
/// </summary>
/// <param name="e"></param>
[System.ComponentModel.EditorBrowsableAttribute()]
protected override void OnSizeChanged(EventArgs e)
{
// Default
base.OnSizeChanged(e);
// Calculate al the data for
// drawing the control
this.CalculateDimensions();
// Redraw
this.Invalidate();
}
/// <summary>
/// Resize event
/// </summary>
/// <param name="e"></param>
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
// Calculate al the data for
// drawing the control
this.CalculateDimensions();
// Redraw
this.Invalidate();
}
/// <summary>
/// Paint event
/// </summary>
/// <param name="e"></param>
[System.ComponentModel.EditorBrowsableAttribute()]
protected override void OnPaint(PaintEventArgs e)
{
// Rectangle of the control
RectangleF _rc = new RectangleF(0, 0, this.Width, this.Height);
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
// Call the default renderer if the user
// rendere is null
if (this.Renderer == null)
{
this.DefaultRenderer.Draw(e.Graphics);
return;
}
// Draw with the user renderer
this.Renderer.Draw(e.Graphics);
}
#endregion
#region (* Virtual method *)
/// <summary>
/// Call from the constructor to create the default renderer
/// </summary>
/// <returns></returns>
protected virtual ILBRenderer CreateDefaultRenderer()
{
return new LBRendererBase();
}
/// <summary>
/// Calculate the dimensions of the control
/// </summary>
protected virtual void CalculateDimensions()
{
this.DefaultRenderer.Update();
// Update the data in the renderer
if (this.Renderer != null)
this.Renderer.Update();
this.Invalidate();
}
#endregion
}
/// <summary>
/// Base class for the controls renderer
/// </summary>
public class LBRendererBase : ILBRenderer
{
#region (* Constructor *)
public LBRendererBase()
{
}
#endregion
#region (* IDisposable implementation *)
public void Dispose()
{
this.OnDispose();
}
#endregion
#region (* Properties *)
/// <summary>
/// Associated control
/// </summary>
protected object _control = null;
public object Control
{
set { this._control = value; }
get { return this._control; }
}
#endregion
#region (* Virtual methods *)
/// <summary>
/// Dispose the resource of the object
/// </summary>
public virtual void OnDispose()
{
}
/// <summary>
/// Update the renderer
/// </summary>
/// <returns></returns>
public virtual bool Update()
{
return false;
}
/// <summary>
/// Drawing method
/// </summary>
/// <param name="Gr"></param>
public virtual void Draw(Graphics Gr)
{
// Check the graphics
if (Gr == null)
throw new ArgumentNullException("Gr");
// Check the control
Control ctrl = this.Control as Control;
if (ctrl == null)
throw new NullReferenceException("Associated control is not valid");
// Default drawing
Rectangle rc = ctrl.Bounds;
Gr.FillRectangle(Brushes.White, ctrl.Bounds);
Gr.DrawRectangle(Pens.Black, ctrl.Bounds);
Gr.DrawLine(Pens.Red,
ctrl.Left,
ctrl.Top,
ctrl.Right,
ctrl.Bottom);
Gr.DrawLine(Pens.Red,
ctrl.Right,
ctrl.Top,
ctrl.Left,
ctrl.Bottom);
}
#endregion
}
}
+271
View File
@@ -0,0 +1,271 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JYControl
{
/// <summary>
/// Base class for the led renderers
/// </summary>
public class LBLedRenderer : LBRendererBase
{
#region (* Variables *)
private RectangleF drawRect;
private RectangleF rectLed;
private RectangleF rectLabel;
#endregion
#region (* Properies *)
/// <summary>
/// Get the associated led object
/// </summary>
public LBLed Led
{
get { return this.Control as LBLed; }
}
#endregion
#region (* Overrided method *)
/// <summary>
/// Update the rectangles for drawing
/// </summary>
/// <returns></returns>
public override bool Update()
{
// Check Led object
if (this.Led == null)
throw new NullReferenceException("Invalid 'Led' object");
// Dati del rettangolo
float x, y, w, h;
x = 0;
y = 0;
w = this.Led.Size.Width;
h = this.Led.Size.Height;
// Rettangolo di disegno
drawRect.X = x;
drawRect.Y = y;
drawRect.Width = w - 2;
drawRect.Height = h - 2;
if (drawRect.Width <= 0)
drawRect.Width = 20;
if (drawRect.Height <= 0)
drawRect.Height = 20;
this.rectLed = drawRect;
this.rectLabel = drawRect;
if (this.Led.LabelPosition == LBLed.LedLabelPosition.Bottom)
{
this.rectLed.X = (this.rectLed.Width * 0.5F) - (this.Led.LedSize.Width * 0.5F);
this.rectLed.Width = this.Led.LedSize.Width;
this.rectLed.Height = this.Led.LedSize.Height;
this.rectLabel.Y = this.rectLed.Bottom;
}
else if (this.Led.LabelPosition == LBLed.LedLabelPosition.Top)
{
this.rectLed.X = (this.rectLed.Width * 0.5F) - (this.Led.LedSize.Width * 0.5F);
this.rectLed.Y = this.rectLed.Height - this.Led.LedSize.Height;
this.rectLed.Width = this.Led.LedSize.Width;
this.rectLed.Height = this.Led.LedSize.Height;
this.rectLabel.Height = this.rectLed.Top;
}
else if (this.Led.LabelPosition == LBLed.LedLabelPosition.Left)
{
this.rectLed.X = this.rectLed.Width - this.Led.LedSize.Width;
this.rectLed.Width = this.Led.LedSize.Width;
this.rectLed.Height = this.Led.LedSize.Height;
this.rectLabel.Width = this.rectLabel.Width - this.rectLed.Width;
}
else if (this.Led.LabelPosition == LBLed.LedLabelPosition.Right)
{
this.rectLed.Width = this.Led.LedSize.Width;
this.rectLed.Height = this.Led.LedSize.Height;
this.rectLabel.X = this.rectLed.Right;
}
return true;
}
/// <summary>
/// Draw the led object
/// </summary>
/// <param name="Gr"></param>
public override void Draw(Graphics Gr)
{
if (Gr == null)
throw new ArgumentNullException("Gr");
LBLed ctrl = this.Led;
if (ctrl == null)
throw new NullReferenceException("Associated control is not valid");
Rectangle rc = ctrl.Bounds;
this.DrawBackground(Gr, rc);
if (this.rectLed.Width <= 0)
this.rectLed.Width = rectLabel.Width;
if (this.rectLed.Height <= 0)
this.rectLed.Height = ctrl.LedSize.Height;
this.DrawLed(Gr, this.rectLed);
this.DrawLabel(Gr, this.rectLabel);
}
#endregion
#region (* Virtual method *)
/// <summary>
/// Draw the background of the control
/// </summary>
/// <param name="Gr"></param>
/// <param name="rc"></param>
/// <returns></returns>
public virtual bool DrawBackground(Graphics Gr, RectangleF rc)
{
if (this.Led == null)
return false;
Color c = this.Led.BackColor;
SolidBrush br = new SolidBrush(c);
Pen pen = new Pen(c);
Rectangle _rcTmp = new Rectangle(0, 0, this.Led.Width, this.Led.Height);
Gr.DrawRectangle(pen, _rcTmp);
Gr.FillRectangle(br, rc);
br.Dispose();
pen.Dispose();
return true;
}
/// <summary>
/// Draw the body of the control
/// </summary>
/// <param name="Gr"></param>
/// <param name="rc"></param>
/// <returns></returns>
public virtual bool DrawLed(Graphics Gr, RectangleF rc)
{
if (this.Led == null)
return false;
Color cDarkOff = LBColorManager.StepColor(Color.LightGray, 20);
Color cDarkOn = LBColorManager.StepColor(this.Led.LedColor, 60);
LinearGradientBrush brOff = new LinearGradientBrush(rc,
Color.Gray,
cDarkOff,
45);
LinearGradientBrush brOn = new LinearGradientBrush(rc,
this.Led.LedColor,
cDarkOn,
45);
if (this.Led.State == LBLed.LedState.Blink)
{
if (this.Led.BlinkIsOn == false)
{
if (this.Led.Style == LBLed.LedStyle.Circular)
Gr.FillEllipse(brOff, rc);
else if (this.Led.Style == LBLed.LedStyle.Rectangular)
Gr.FillRectangle(brOff, rc);
}
else
{
if (this.Led.Style == LBLed.LedStyle.Circular)
Gr.FillEllipse(brOn, rc);
else if (this.Led.Style == LBLed.LedStyle.Rectangular)
Gr.FillRectangle(brOn, rc);
}
}
else
{
if (this.Led.State == LBLed.LedState.Off)
{
if (this.Led.Style == LBLed.LedStyle.Circular)
Gr.FillEllipse(brOff, rc);
else if (this.Led.Style == LBLed.LedStyle.Rectangular)
Gr.FillRectangle(brOff, rc);
}
else
{
if (this.Led.Style == LBLed.LedStyle.Circular)
Gr.FillEllipse(brOn, rc);
else if (this.Led.Style == LBLed.LedStyle.Rectangular)
Gr.FillRectangle(brOn, rc);
}
}
brOff.Dispose();
brOn.Dispose();
return true;
}
/// <summary>
/// Draw the text of the control
/// </summary>
/// <param name="Gr"></param>
/// <param name="rc"></param>
/// <returns></returns>
public virtual bool DrawLabel(Graphics Gr, RectangleF rc)
{
if (this.Led == null)
return false;
if (this.Led.Label == String.Empty)
return false;
SizeF size = Gr.MeasureString(this.Led.Label, this.Led.Font);
SolidBrush br1 = new SolidBrush(this.Led.ForeColor);
float hPos = 0;
float vPos = 0;
switch (this.Led.LabelPosition)
{
case LBLed.LedLabelPosition.Top:
hPos = (float)(rc.Width * 0.5F) - (float)(size.Width * 0.5F);
vPos = rc.Bottom - size.Height;
break;
case LBLed.LedLabelPosition.Bottom:
hPos = (float)(rc.Width * 0.5F) - (float)(size.Width * 0.5F);
break;
case LBLed.LedLabelPosition.Left:
hPos = rc.Width - size.Width;
vPos = (float)(rc.Height * 0.5F) - (float)(size.Height * 0.5F);
break;
case LBLed.LedLabelPosition.Right:
vPos = (float)(rc.Height * 0.5F) - (float)(size.Height * 0.5F);
break;
}
Gr.DrawString(this.Led.Label,
this.Led.Font,
br1,
rc.Left + hPos,
rc.Top + vPos);
return true;
}
#endregion
}
}
+310
View File
@@ -0,0 +1,310 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace JYControl
{
internal class NativeMethods
{
/// <summary>
/// Enum ComboBoxButtonState
/// </summary>
public enum ComboBoxButtonState
{
/// <summary>
/// The state system none
/// </summary>
STATE_SYSTEM_NONE,
/// <summary>
/// The state system invisible
/// </summary>
STATE_SYSTEM_INVISIBLE = 32768,
/// <summary>
/// The state system pressed
/// </summary>
STATE_SYSTEM_PRESSED = 8
}
/// <summary>
/// Struct RECT
/// </summary>
public struct RECT
{
/// <summary>
/// The left
/// </summary>
public int Left;
/// <summary>
/// The top
/// </summary>
public int Top;
/// <summary>
/// The right
/// </summary>
public int Right;
/// <summary>
/// The bottom
/// </summary>
public int Bottom;
/// <summary>
/// Gets the rect.
/// </summary>
/// <value>The rect.</value>
public Rectangle Rect
{
get
{
return new Rectangle(this.Left, this.Top, this.Right - this.Left, this.Bottom - this.Top);
}
}
/// <summary>
/// Gets the size.
/// </summary>
/// <value>The size.</value>
public Size Size
{
get
{
return new Size(this.Right - this.Left, this.Bottom - this.Top);
}
}
/// <summary>
/// Initializes a new instance of the <see cref="RECT" /> struct.
/// </summary>
/// <param name="left">The left.</param>
/// <param name="top">The top.</param>
/// <param name="right">The right.</param>
/// <param name="bottom">The bottom.</param>
public RECT(int left, int top, int right, int bottom)
{
this.Left = left;
this.Top = top;
this.Right = right;
this.Bottom = bottom;
}
/// <summary>
/// Initializes a new instance of the <see cref="RECT" /> struct.
/// </summary>
/// <param name="rect">The rect.</param>
public RECT(Rectangle rect)
{
this.Left = rect.Left;
this.Top = rect.Top;
this.Right = rect.Right;
this.Bottom = rect.Bottom;
}
/// <summary>
/// Froms the xywh.
/// </summary>
/// <param name="x">The x.</param>
/// <param name="y">The y.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <returns>NativeMethods.RECT.</returns>
public static NativeMethods.RECT FromXYWH(int x, int y, int width, int height)
{
return new NativeMethods.RECT(x, y, x + width, y + height);
}
/// <summary>
/// Froms the rectangle.
/// </summary>
/// <param name="rect">The rect.</param>
/// <returns>NativeMethods.RECT.</returns>
public static NativeMethods.RECT FromRectangle(Rectangle rect)
{
return new NativeMethods.RECT(rect.Left, rect.Top, rect.Right, rect.Bottom);
}
}
/// <summary>
/// Struct PAINTSTRUCT
/// </summary>
public struct PAINTSTRUCT
{
/// <summary>
/// The HDC
/// </summary>
public IntPtr hdc;
/// <summary>
/// The f erase
/// </summary>
public int fErase;
/// <summary>
/// The rc paint
/// </summary>
public NativeMethods.RECT rcPaint;
/// <summary>
/// The f restore
/// </summary>
public int fRestore;
/// <summary>
/// The f inc update
/// </summary>
public int fIncUpdate;
/// <summary>
/// The reserved1
/// </summary>
public int Reserved1;
/// <summary>
/// The reserved2
/// </summary>
public int Reserved2;
/// <summary>
/// The reserved3
/// </summary>
public int Reserved3;
/// <summary>
/// The reserved4
/// </summary>
public int Reserved4;
/// <summary>
/// The reserved5
/// </summary>
public int Reserved5;
/// <summary>
/// The reserved6
/// </summary>
public int Reserved6;
/// <summary>
/// The reserved7
/// </summary>
public int Reserved7;
/// <summary>
/// The reserved8
/// </summary>
public int Reserved8;
}
/// <summary>
/// Struct ComboBoxInfo
/// </summary>
public struct ComboBoxInfo
{
/// <summary>
/// The cb size
/// </summary>
public int cbSize;
/// <summary>
/// The rc item
/// </summary>
public NativeMethods.RECT rcItem;
/// <summary>
/// The rc button
/// </summary>
public NativeMethods.RECT rcButton;
/// <summary>
/// The state button
/// </summary>
public NativeMethods.ComboBoxButtonState stateButton;
/// <summary>
/// The HWND combo
/// </summary>
public IntPtr hwndCombo;
/// <summary>
/// The HWND edit
/// </summary>
public IntPtr hwndEdit;
/// <summary>
/// The HWND list
/// </summary>
public IntPtr hwndList;
}
/// <summary>
/// The wm paint
/// </summary>
public const int WM_PAINT = 15;
/// <summary>
/// The wm setredraw
/// </summary>
public const int WM_SETREDRAW = 11;
/// <summary>
/// The false
/// </summary>
public static readonly IntPtr FALSE = IntPtr.Zero;
/// <summary>
/// The true
/// </summary>
public static readonly IntPtr TRUE = new IntPtr(1);
/// <summary>
/// Gets the ComboBox information.
/// </summary>
/// <param name="hwndCombo">The HWND combo.</param>
/// <param name="info">The information.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
[DllImport("user32.dll")]
public static extern bool GetComboBoxInfo(IntPtr hwndCombo, ref NativeMethods.ComboBoxInfo info);
/// <summary>
/// Gets the window rect.
/// </summary>
/// <param name="hwnd">The HWND.</param>
/// <param name="lpRect">The lp rect.</param>
/// <returns>System.Int32.</returns>
[DllImport("user32.dll")]
public static extern int GetWindowRect(IntPtr hwnd, ref NativeMethods.RECT lpRect);
/// <summary>
/// Begins the paint.
/// </summary>
/// <param name="hWnd">The h WND.</param>
/// <param name="ps">The ps.</param>
/// <returns>IntPtr.</returns>
[DllImport("user32.dll")]
public static extern IntPtr BeginPaint(IntPtr hWnd, ref NativeMethods.PAINTSTRUCT ps);
/// <summary>
/// Ends the paint.
/// </summary>
/// <param name="hWnd">The h WND.</param>
/// <param name="ps">The ps.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
[DllImport("user32.dll")]
public static extern bool EndPaint(IntPtr hWnd, ref NativeMethods.PAINTSTRUCT ps);
/// <summary>
/// Sends the message.
/// </summary>
/// <param name="hWnd">The h WND.</param>
/// <param name="msg">The MSG.</param>
/// <param name="wParam">The w parameter.</param>
/// <param name="lParam">The l parameter.</param>
[DllImport("user32.dll")]
public static extern void SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
}
}
+24
View File
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JYControl
{
/// <summary>
/// Renderer interface for all
/// LBSoft.IndustrialCtrls renderer
/// </summary>
public interface ILBRenderer : IDisposable
{
object Control
{
set;
get;
}
bool Update();
void Draw(Graphics Gr);
}
}
+402
View File
@@ -0,0 +1,402 @@
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 JYControl
{
/// <summary>
/// Class UCBlower.
/// Implements the <see cref="System.Windows.Forms.UserControl" />
/// </summary>
/// <seealso cref="System.Windows.Forms.UserControl" />
public class Blower : UserControl
{
/// <summary>
/// The entrance direction
/// </summary>
private BlowerEntranceDirection entranceDirection = BlowerEntranceDirection.None;
/// <summary>
/// Gets or sets the entrance direction.
/// </summary>
/// <value>The entrance direction.</value>
[Description("入口方向"), Category("自定义")]
public BlowerEntranceDirection EntranceDirection
{
get { return entranceDirection; }
set
{
entranceDirection = value;
Refresh();
}
}
/// <summary>
/// The exit direction
/// </summary>
private BlowerExitDirection exitDirection = BlowerExitDirection.Right;
/// <summary>
/// Gets or sets the exit direction.
/// </summary>
/// <value>The exit direction.</value>
[Description("出口方向"), Category("自定义")]
public BlowerExitDirection ExitDirection
{
get { return exitDirection; }
set
{
exitDirection = value;
Refresh();
}
}
/// <summary>
/// The blower color
/// </summary>
private Color blowerColor = Color.FromArgb(255, 77, 59);
/// <summary>
/// Gets or sets the color of the blower.
/// </summary>
/// <value>The color of the blower.</value>
[Description("风机颜色"), Category("自定义")]
public Color BlowerColor
{
get { return blowerColor; }
set
{
blowerColor = value;
Refresh();
}
}
/// <summary>
/// The fan color
/// </summary>
private Color fanColor = Color.FromArgb(3, 169, 243);
/// <summary>
/// Gets or sets the color of the fan.
/// </summary>
/// <value>The color of the fan.</value>
[Description("风叶颜色"), Category("自定义")]
public Color FanColor
{
get { return fanColor; }
set
{
fanColor = value;
Refresh();
}
}
TurnAround turnAround = JYControl.TurnAround.None;
[Description("风叶旋转方向,None表示不旋转"), Category("自定义")]
public TurnAround TurnAround
{
get { return turnAround; }
set
{
turnAround = value;
if (value == JYControl.TurnAround.None)
{
timer1.Enabled = false;
jiaodu = 0;
Refresh();
}
else
timer1.Enabled = true;
}
}
private int turnSpeed = 100;
private int jiaodu = 0;
private Timer timer1;
private IContainer components;
[Description("风叶旋转速度,100-1000,值越小 速度越快"), Category("自定义")]
public int TurnSpeed
{
get { return turnSpeed; }
set
{
if (value < 0 || value > 1000)
return;
turnSpeed = value;
timer1.Interval = value;
}
}
/// <summary>
/// 是否显示底座
/// </summary>
private bool isDZ = false;
/// <summary>
/// 是否显示底座
/// </summary>
/// <value>是否显示底座</value>
[Description("是否显示底座"), Category("自定义")]
public bool IsDZ
{
get { return isDZ; }
set
{
isDZ = value;
Refresh();
}
}
/// <summary>
/// The m rect working
/// </summary>
Rectangle m_rectWorking;
/// <summary>
/// Initializes a new instance of the <see cref="Blower" /> class.
/// </summary>
public Blower()
{
InitializeComponent();
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.SizeChanged += UCBlower_SizeChanged;
this.Size = new Size(120, 120);
}
/// <summary>
/// Handles the SizeChanged event of the UCBlower control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
void UCBlower_SizeChanged(object sender, EventArgs e)
{
int intMin = Math.Min(this.Width, this.Height);
m_rectWorking = new Rectangle((this.Width - (intMin / 2 * 2)) / 2, (this.Height - (intMin / 2 * 2)) / 2, (intMin / 2 * 2), (intMin / 2 * 2));
}
/// <summary>
/// 引发 <see cref="E:System.Windows.Forms.Control.Paint" /> 事件。
/// </summary>
/// <param name="e">包含事件数据的 <see cref="T:System.Windows.Forms.PaintEventArgs" />。</param>
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
var g = e.Graphics;
g.SetGDIHigh();
GraphicsPath pathLineIn = new GraphicsPath();
GraphicsPath pathLineOut = new GraphicsPath();
int intLinePenWidth = 0;
switch (exitDirection)
{
case BlowerExitDirection.Left:
g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(0, m_rectWorking.Top, this.Width / 2, m_rectWorking.Height / 2 - 5));
intLinePenWidth = m_rectWorking.Height / 2 - 5;
pathLineOut.AddLine(new Point(-10, m_rectWorking.Top + (m_rectWorking.Height / 2 - 5) / 2), new Point(m_rectWorking.Left + m_rectWorking.Width / 2, m_rectWorking.Top + (m_rectWorking.Height / 2 - 5) / 2));
g.DrawLine(new Pen(new SolidBrush(blowerColor), 3), new Point(1, m_rectWorking.Top - 2), new Point(1, m_rectWorking.Top + (m_rectWorking.Height / 2 - 5) + 2));
break;
case BlowerExitDirection.Right:
g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(this.Width / 2, m_rectWorking.Top, this.Width / 2, m_rectWorking.Height / 2 - 5));
intLinePenWidth = m_rectWorking.Height / 2 - 5;
pathLineOut.AddLine(new Point(this.Width + 10, m_rectWorking.Top + (m_rectWorking.Height / 2 - 5) / 2), new Point(m_rectWorking.Left + m_rectWorking.Width / 2, m_rectWorking.Top + (m_rectWorking.Height / 2 - 5) / 2));
g.DrawLine(new Pen(new SolidBrush(blowerColor), 3), new Point(this.Width - 2, m_rectWorking.Top - 2), new Point(this.Width - 2, m_rectWorking.Top + (m_rectWorking.Height / 2 - 5) + 2));
break;
case BlowerExitDirection.Up:
g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(m_rectWorking.Right - (m_rectWorking.Width / 2 - 5), 0, m_rectWorking.Width / 2 - 5, this.Height / 2));
intLinePenWidth = m_rectWorking.Width / 2 - 5;
pathLineOut.AddLine(new Point(m_rectWorking.Right - (m_rectWorking.Width / 2 - 5) / 2, -10), new Point(m_rectWorking.Right - (m_rectWorking.Width / 2 - 5) / 2, m_rectWorking.Top + m_rectWorking.Height / 2));
g.DrawLine(new Pen(new SolidBrush(blowerColor), 3), new Point(m_rectWorking.Right + 2, 1), new Point(m_rectWorking.Right - (m_rectWorking.Width / 2 - 5) - 2, 1));
break;
}
switch (entranceDirection)
{
case BlowerEntranceDirection.Left:
g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(0, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5, this.Width / 2, m_rectWorking.Height / 2 - 5));
pathLineIn.AddLine(new Point(-10, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5 + (m_rectWorking.Height / 2 - 5) / 2), new Point(m_rectWorking.Left + m_rectWorking.Width / 2, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5 + (m_rectWorking.Height / 2 - 5) / 2));
g.DrawLine(new Pen(new SolidBrush(blowerColor), 3), new Point(1, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5 - 2), new Point(1, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5 + (m_rectWorking.Height / 2 - 5) + 2));
break;
case BlowerEntranceDirection.Right:
g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(this.Width / 2, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5, this.Width / 2, m_rectWorking.Height / 2 - 5));
pathLineIn.AddLine(new Point(this.Width + 10, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5 + (m_rectWorking.Height / 2 - 5) / 2), new Point(m_rectWorking.Left + m_rectWorking.Width / 2, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5 + (m_rectWorking.Height / 2 - 5) / 2));
g.DrawLine(new Pen(new SolidBrush(blowerColor), 3), new Point(this.Width - 2, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5 - 2), new Point(this.Width - 2, m_rectWorking.Bottom - m_rectWorking.Height / 2 + 5 + (m_rectWorking.Height / 2 - 5) + 2));
break;
case BlowerEntranceDirection.Up:
g.FillRectangle(new SolidBrush(blowerColor), new Rectangle(m_rectWorking.Left, 0, m_rectWorking.Width / 2 - 5, this.Height / 2));
pathLineIn.AddLine(new Point(m_rectWorking.Left + (m_rectWorking.Width / 2 - 5) / 2, -10), new Point(m_rectWorking.Left + (m_rectWorking.Width / 2 - 5) / 2, m_rectWorking.Top + m_rectWorking.Height / 2));
g.DrawLine(new Pen(new SolidBrush(blowerColor), 3), new Point(m_rectWorking.Left - 2, 1), new Point(m_rectWorking.Left + (m_rectWorking.Width / 2 - 5) + 2, 1));
break;
}
//渐变色
int _intPenWidth = intLinePenWidth;
int intCount = _intPenWidth / 2 / 4;
for (int i = 0; i < intCount; i++)
{
int _penWidth = _intPenWidth / 2 - 4 * i;
if (_penWidth <= 0)
_penWidth = 1;
if (entranceDirection != BlowerEntranceDirection.None)
g.DrawPath(new Pen(new SolidBrush(Color.FromArgb(40, Color.White.R, Color.White.G, Color.White.B)), _penWidth), pathLineIn);
g.DrawPath(new Pen(new SolidBrush(Color.FromArgb(40, Color.White.R, Color.White.G, Color.White.B)), _penWidth), pathLineOut);
if (_penWidth == 1)
break;
}
//底座
if (isDZ)
{
GraphicsPath gpDZ = new GraphicsPath();
gpDZ.AddLines(new Point[]
{
new Point( m_rectWorking.Left+m_rectWorking.Width/2,m_rectWorking.Top+m_rectWorking.Height/2),
new Point(m_rectWorking.Left+2,this.Height),
new Point(m_rectWorking.Right-2,this.Height)
});
gpDZ.CloseAllFigures();
g.FillPath(new SolidBrush(blowerColor), gpDZ);
g.FillPath(new SolidBrush(Color.FromArgb(50, Color.White)), gpDZ);
g.DrawLine(new Pen(new SolidBrush(blowerColor), 3), new Point(m_rectWorking.Left, this.Height - 2), new Point(m_rectWorking.Right, this.Height - 2));
}
//中心
g.FillEllipse(new SolidBrush(blowerColor), m_rectWorking);
g.FillEllipse(new SolidBrush(Color.FromArgb(20, Color.White)), m_rectWorking);
//扇叶
Rectangle _rect = new Rectangle(m_rectWorking.Left + (m_rectWorking.Width - (m_rectWorking.Width / 3 * 2)) / 2, m_rectWorking.Top + (m_rectWorking.Height - (m_rectWorking.Width / 3 * 2)) / 2, (m_rectWorking.Width / 3 * 2), (m_rectWorking.Width / 3 * 2));
int _splitCount = 8;
float fltSplitValue = 360F / (float)_splitCount;
for (int i = 0; i <= _splitCount; i++)
{
float fltAngle = (fltSplitValue * i - 180) % 360 + jiaodu;
float fltY1 = (float)(_rect.Top + _rect.Width / 2 - ((_rect.Width / 2) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
float fltX1 = (float)(_rect.Left + (_rect.Width / 2 - ((_rect.Width / 2) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
float fltY2 = 0;
float fltX2 = 0;
fltY2 = (float)(_rect.Top + _rect.Width / 2 - ((_rect.Width / 4) * Math.Sin(Math.PI * (fltAngle / 180.00F))));
fltX2 = (float)(_rect.Left + (_rect.Width / 2 - ((_rect.Width / 4) * Math.Cos(Math.PI * (fltAngle / 180.00F)))));
g.DrawLine(new Pen(new SolidBrush(fanColor), 2), new PointF(fltX1, fltY1), new PointF(fltX2, fltY2));
}
g.FillEllipse(new SolidBrush(fanColor), new Rectangle(_rect.Left + _rect.Width / 2 - _rect.Width / 4 + 2, _rect.Top + _rect.Width / 2 - _rect.Width / 4 + 2, _rect.Width / 2 - 4, _rect.Width / 2 - 4));
g.FillEllipse(new SolidBrush(Color.FromArgb(50, Color.White)), new Rectangle(_rect.Left - 5, _rect.Top - 5, _rect.Width + 10, _rect.Height + 10));
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// timer1
//
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// UCBlower
//
this.Name = "Blower";
this.ResumeLayout(false);
}
private void timer1_Tick(object sender, EventArgs e)
{
if (turnAround == JYControl.TurnAround.Clockwise)
{
jiaodu += 15;
if (jiaodu == 45)
jiaodu = 0;
}
else if (turnAround == JYControl.TurnAround.Counterclockwise)
{
jiaodu -= 15;
if (jiaodu == -45)
jiaodu = 0;
}
Refresh();
}
}
/// <summary>
/// Enum BlowerEntranceDirection
/// </summary>
public enum BlowerEntranceDirection
{
/// <summary>
/// The none
/// </summary>
None,
/// <summary>
/// The left
/// </summary>
Left,
/// <summary>
/// The right
/// </summary>
Right,
/// <summary>
/// Up
/// </summary>
Up
}
/// <summary>
/// Enum BlowerExitDirection
/// </summary>
public enum BlowerExitDirection
{
/// <summary>
/// The none
/// </summary>
None,
/// <summary>
/// The left
/// </summary>
Left,
/// <summary>
/// The right
/// </summary>
Right,
/// <summary>
/// Up
/// </summary>
Up
}
/// <summary>
/// 旋转方向
/// </summary>
public enum TurnAround
{
/// <summary>
/// 不旋转
/// </summary>
None,
/// <summary>
/// 顺时针
/// </summary>
Clockwise,
/// <summary>
/// 逆时针
/// </summary>
Counterclockwise
}
}
+123
View File
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
+37
View File
@@ -0,0 +1,37 @@
namespace JYControl
{
partial class CircleCountValue
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}
+144
View File
@@ -0,0 +1,144 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace JYControl
{
public partial class CircleCountValue : Control
{
//这个写最上面是因为我自己也不懂是啥意思,只知道界面控件重绘容易产生闪烁的问题,这个加了就不会有
//解决控件批量更新时带来的闪烁
protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; return cp; } }
//-------------------颜色
private Color bgColor = Color.FromArgb(224, 224, 224); //背景边框颜色
private Color sectorColor = Color.FromArgb(109, 179, 63); //扇形颜色
[Category("控件属性")]
[Description("背景边框颜色")]
public Color BgColor
{
get { return this.bgColor; }
set
{
this.bgColor = value;
this.Invalidate();
}
}
[Category("控件属性")]
[Description("扇形颜色")]
public Color SectorColor
{
get { return this.sectorColor; }
set
{
this.sectorColor = value;
this.Invalidate();
}
}
private int borderWidth = 2;//边框宽度
[Category("控件属性")]
[Description("边框宽度")]
public int BorderWidth
{
get { return this.borderWidth; }
set
{
this.borderWidth = value;
this.Invalidate();
}
}
/// <summary>
/// 圆形进度条实心
/// </summary>
public CircleCountValue()
{
InitControl();
this.SizeChanged += delegate
{
this.Invalidate(); //重绘控件
};
}
int maxValue = 500000; //进度最大值
private int countValue = 0;
/// <summary>
/// 进度值
/// </summary>
///
[Category("控件属性")]
[Description("进度值,最大值500000")]
public int CountValue
{
get { return this.countValue; }
set
{
if (value > this.maxValue)
{
return;
}
this.countValue = value;
this.Invalidate();
}
}
/// <summary>
/// 初始化控件参数
/// </summary>
private void InitControl()
{
this.Width = 200;
this.Height = 200;
}
//对Control进行绘制
protected override void OnPaint(PaintEventArgs e)
{
DrawShape(e.Graphics); //绘制控件样式
}
/// <summary>
/// 画图
/// </summary>
/// <param name="g">画图工具类</param>
private void DrawShape(Graphics g)
{
if (this.Width < borderWidth * 4 || this.Height < borderWidth * 4)
{
return;
}
g.SmoothingMode = SmoothingMode.AntiAlias; //消除锯齿,也就是抗锯齿什么鬼东西
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.CompositingQuality = CompositingQuality.HighQuality;
RectangleF bg_rectangle = new RectangleF(0 + borderWidth, 0 + borderWidth, Width - borderWidth * 2, Height - borderWidth * 2); //控件整体坐标
g.DrawEllipse(new Pen(bgColor, borderWidth), bg_rectangle); //画背景圆
Rectangle rl = new Rectangle(0 + borderWidth * 2, 0 + borderWidth * 2, this.Width - borderWidth * 4, this.Height - borderWidth * 4);
decimal topAngle = (this.countValue * 1.0M / this.maxValue) * 360M;//计算进度条划过的度数
g.FillPie(new SolidBrush(sectorColor), rl, 0, (float)topAngle); //填充扇形
//SizeF proValSize = g.MeasureString(this.progress.ToString() + "%", this.Font);//计算文字的范围
SizeF proValSize = g.MeasureString(this.countValue.ToString(), this.Font);//计算文字的范围
//g.DrawString(this.progress.ToString() + "%", this.Font, new SolidBrush(this.ForeColor),
g.DrawString(this.countValue.ToString(), this.Font, new SolidBrush(this.ForeColor),
bg_rectangle.X + bg_rectangle.Width / 2 - proValSize.Width / 2, bg_rectangle.Y + bg_rectangle.Height / 2 - proValSize.Height / 2);
}
}
}
+141
View File
@@ -0,0 +1,141 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace JYControl
{
public class CircleProgramBar : Control
{
//这个写最上面是因为我自己也不懂是啥意思,只知道界面控件重绘容易产生闪烁的问题,这个加了就不会有
//解决控件批量更新时带来的闪烁
protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; return cp; } }
//-------------------颜色
private Color bgColor = Color.FromArgb(224, 224, 224); //背景边框颜色
private Color sectorColor = Color.FromArgb(109, 179, 63); //扇形颜色
[Category("控件属性")]
[Description("背景边框颜色")]
public Color BgColor
{
get { return this.bgColor; }
set
{
this.bgColor = value;
this.Invalidate();
}
}
[Category("控件属性")]
[Description("扇形颜色")]
public Color SectorColor
{
get { return this.sectorColor; }
set
{
this.sectorColor = value;
this.Invalidate();
}
}
private int borderWidth = 2;//边框宽度
[Category("控件属性")]
[Description("边框宽度")]
public int BorderWidth {
get { return this.borderWidth; }
set {
this.borderWidth = value;
this.Invalidate();
}
}
/// <summary>
/// 圆形进度条实心
/// </summary>
public CircleProgramBar()
{
InitControl();
this.SizeChanged += delegate
{
this.Invalidate(); //重绘控件
};
}
int maxValue = 1000; //进度最大值
private int progress = 0;
/// <summary>
/// 进度值
/// </summary>
///
[Category("控件属性")]
[Description("进度值,最大值1000")]
public int Progress
{
get { return this.progress; }
set
{
if (value > this.maxValue)
{
return;
}
this.progress = value;
this.Invalidate();
}
}
/// <summary>
/// 初始化控件参数
/// </summary>
private void InitControl()
{
this.Width = 200;
this.Height = 200;
}
//对Control进行绘制
protected override void OnPaint(PaintEventArgs e)
{
DrawShape(e.Graphics); //绘制控件样式
}
/// <summary>
/// 画图
/// </summary>
/// <param name="g">画图工具类</param>
private void DrawShape(Graphics g)
{
if (this.Width < borderWidth*4 || this.Height < borderWidth*4)
{
return;
}
g.SmoothingMode = SmoothingMode.AntiAlias; //消除锯齿,也就是抗锯齿什么鬼东西
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.CompositingQuality = CompositingQuality.HighQuality;
RectangleF bg_rectangle = new RectangleF(0+ borderWidth, 0+ borderWidth, Width- borderWidth*2, Height- borderWidth*2); //控件整体坐标
g.DrawEllipse(new Pen(bgColor,borderWidth), bg_rectangle); //画背景圆
Rectangle rl = new Rectangle(0+ borderWidth*2, 0 + borderWidth*2, this.Width- borderWidth*4, this.Height- borderWidth*4);
decimal topAngle = (this.progress * 1.0M / this.maxValue) * 360M;//计算进度条划过的度数
g.FillPie(new SolidBrush(sectorColor), rl, 0, (float)topAngle); //填充扇形
//SizeF proValSize = g.MeasureString(this.progress.ToString() + "%", this.Font);//计算文字的范围
SizeF proValSize = g.MeasureString(this.progress.ToString(), this.Font);//计算文字的范围
//g.DrawString(this.progress.ToString() + "%", this.Font, new SolidBrush(this.ForeColor),
g.DrawString(this.progress.ToString(), this.Font, new SolidBrush(this.ForeColor),
bg_rectangle.X + bg_rectangle.Width / 2 - proValSize.Width / 2, bg_rectangle.Y + bg_rectangle.Height / 2 - proValSize.Height / 2);
}
}
}
+83
View File
@@ -0,0 +1,83 @@
namespace JYControl
{
partial class IO_Instructions
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ledControl = new JYControl.LedControl();
this.LabelX = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// ledControl
//
this.ledControl.BorderWidth = 5;
this.ledControl.CenterColor = System.Drawing.Color.White;
this.ledControl.FlashInterval = 500;
this.ledControl.GapWidth = 5;
this.ledControl.IsBorder = false;
this.ledControl.IsFlash = false;
this.ledControl.IsHighLight = false;
this.ledControl.LampColor = new System.Drawing.Color[] {
System.Drawing.Color.Green,
System.Drawing.Color.Yellow};
this.ledControl.LedColor = System.Drawing.Color.Green;
this.ledControl.LedFalseColor = System.Drawing.Color.Red;
this.ledControl.LedStatus = true;
this.ledControl.LedTrueColor = System.Drawing.Color.Green;
this.ledControl.Location = new System.Drawing.Point(0, 0);
this.ledControl.Name = "ledControl";
this.ledControl.Size = new System.Drawing.Size(16, 16);
this.ledControl.TabIndex = 0;
//
// LabelX
//
this.LabelX.AutoSize = true;
this.LabelX.Location = new System.Drawing.Point(29, 3);
this.LabelX.Name = "LabelX";
this.LabelX.Size = new System.Drawing.Size(29, 12);
this.LabelX.TabIndex = 2;
this.LabelX.Text = "描述";
//
// IO_Instructions
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.LabelX);
this.Controls.Add(this.ledControl);
this.Name = "IO_Instructions";
this.Size = new System.Drawing.Size(72, 18);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private LedControl ledControl;
private System.Windows.Forms.Label LabelX;
}
}
+136
View File
@@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace JYControl
{
public partial class IO_Instructions : UserControl
{
public IO_Instructions()
{
InitializeComponent();
}
public int IO_Value;
public string mstrCaption = "";
public string mstrText = "输入描述";
public bool Reversal, GreenOrRed;
[Category("jason控件属性")]
[Description("是否开启反转")]
public bool AAReversal
{
get
{
return Reversal;
}
set
{
Reversal = value;
}
}
[Category("jason控件属性")]
[Description("颜色变更绿色或者红色")]
public bool AAGreenOrRed
{
get
{
return GreenOrRed;
}
set
{
GreenOrRed = value;
}
}
[Category("jason控件属性")]
[Description("控件名称")]
public string AAName
{
get
{
return mstrCaption;
}
set
{
mstrCaption = value;
}
}
[Category("jason控件属性")]
[Description("控件描述")]
public string AAText
{
get
{
return mstrText;
}
set
{
mstrText = value;
LabelX.Text = AAText;
}
}
[Category("jason控件属性")]
[Description("控件IO值")]
public int AAValue
{
get
{
return IO_Value;
}
set
{
IO_Value = value;
if (value == 1)
{
if (Reversal)
{
if (GreenOrRed)
{ ledControl.LedTrueColor = Color.Red; }
else
{ ledControl.LedTrueColor = Color.Green; }
}
else
{
if (GreenOrRed)
{ ledControl.LedTrueColor = Color.Transparent; }
else
{ ledControl.LedTrueColor = Color.Lime; }
}
}
else
{
if (Reversal)
{
if (GreenOrRed)
{ ledControl.LedTrueColor = Color.Lime; }
else
{ ledControl.LedTrueColor = Color.Red; }
}
else
{
if (GreenOrRed)
{ ledControl.LedTrueColor = Color.Red; }
else
{ ledControl.LedTrueColor = Color.Transparent; }
}
}
}
}
}
}
+120
View File
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1009 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 878 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 494 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

+167
View File
@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{01A2AA2C-9B80-41AA-9F47-3CB67E60AF24}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>JYControl</RootNamespace>
<AssemblyName>JY.Control</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\..\JY.Inspection\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Base\ButtonRenderer.cs" />
<Compile Include="Base\ColorMng.cs" />
<Compile Include="Base\ControlHelper.cs" />
<Compile Include="Base\LBIndustrialCtrlBase.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Base\LBIndustrialCtrlBase.Designer.cs">
<DependentUpon>LBIndustrialCtrlBase.cs</DependentUpon>
</Compile>
<Compile Include="Base\LedRenderer.cs" />
<Compile Include="Base\NativeMethods.cs" />
<Compile Include="Base\Renderer.cs" />
<Compile Include="Blower.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="CircleProgramBar.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="CircleCountValue.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="CircleCountValue.Designer.cs">
<DependentUpon>CircleCountValue.cs</DependentUpon>
</Compile>
<Compile Include="IO_Instructions.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="IO_Instructions.Designer.cs">
<DependentUpon>IO_Instructions.cs</DependentUpon>
</Compile>
<Compile Include="LBButton.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="LBButton.Designer.cs">
<DependentUpon>LBButton.cs</DependentUpon>
</Compile>
<Compile Include="LBLed.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="LBLed.Designer.cs">
<DependentUpon>LBLed.cs</DependentUpon>
</Compile>
<Compile Include="LedControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="LedControl.Designer.cs">
<DependentUpon>LedControl.cs</DependentUpon>
</Compile>
<Compile Include="LogManagerControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="LogManagerControl.Designer.cs">
<DependentUpon>LogManagerControl.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="PulseButton.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="PulseButton.Designer.cs">
<DependentUpon>PulseButton.cs</DependentUpon>
</Compile>
<Compile Include="RingProgramBar.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="RoundButton.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="RoundButton.Designer.cs">
<DependentUpon>RoundButton.cs</DependentUpon>
</Compile>
<Compile Include="TextBoxWatermark.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="TreeViewEx.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="TreeViewEx.Designer.cs">
<DependentUpon>TreeViewEx.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Blower.resx">
<DependentUpon>Blower.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="IO_Instructions.resx">
<DependentUpon>IO_Instructions.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="LBLed.resx">
<DependentUpon>LBLed.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="LedControl.resx">
<DependentUpon>LedControl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="LogManagerControl.resx">
<DependentUpon>LogManagerControl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="TreeViewEx.resx">
<DependentUpon>TreeViewEx.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Content Include="Image\list_add.png" />
<Content Include="Image\list_subtract.png" />
<Content Include="Image\tips.png" />
<Content Include="Image\下载.png" />
<Content Include="Image\增加.png" />
<Content Include="Image\查询.png" />
<Content Include="Image\设置.png" />
<Content Include="Image\运行中.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>
+37
View File
@@ -0,0 +1,37 @@
namespace JYControl
{
partial class LBButton
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
}
#endregion
}
}
+294
View File
@@ -0,0 +1,294 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace JYControl
{
/// <summary>
/// Description of LBButton.
/// </summary>
public partial class LBButton : LBIndustrialCtrlBase
{
#region (* Enumeratives *)
/// <summary>
/// Button styles
/// </summary>
public enum ButtonStyle
{
Circular = 0,
Rectangular = 1,
Elliptical = 2,
}
/// <summary>
/// Button states
/// </summary>
public enum ButtonState
{
Normal = 0,
Pressed,
}
#endregion
#region (* Properties variables *)
private ButtonStyle buttonStyle = ButtonStyle.Circular;
private ButtonState buttonState = ButtonState.Normal;
private Color buttonColor = Color.Red;
private string label = String.Empty;
private bool enableRepeatState = false;
private int startRepeatInterval = 500;
private int repeatInterval = 100;
#endregion
#region (* Variables *)
private Timer tmrRepeat = null;
#endregion
#region (* Constructor *)
public LBButton()
{
// Initialization
InitializeComponent();
// Properties initialization
this.buttonColor = Color.Red;
this.Size = new Size(50, 50);
// Timer
this.tmrRepeat = new Timer();
this.tmrRepeat.Enabled = false;
this.tmrRepeat.Interval = this.startRepeatInterval;
this.tmrRepeat.Tick += this.Timer_Tick;
}
#endregion
#region (* Overrided methods *)
protected override ILBRenderer CreateDefaultRenderer()
{
return new LBButtonRenderer();
}
#endregion
#region (* Properties *)
[
Category("Button"),
Description("Style of the button")
]
public ButtonStyle Style
{
set
{
this.buttonStyle = value;
this.CalculateDimensions();
}
get { return this.buttonStyle; }
}
[
Category("Button"),
Description("Color of the body of the button")
]
public Color ButtonColor
{
get { return buttonColor; }
set
{
buttonColor = value;
Invalidate();
}
}
[
Category("Button"),
Description("Label of the button"),
]
public string Label
{
get { return this.label; }
set
{
this.label = value;
Invalidate();
}
}
[
Category("Button"),
Description("State of the button")
]
public ButtonState State
{
set
{
this.buttonState = value;
this.Invalidate();
}
get { return this.buttonState; }
}
[
Category("Button"),
Description("Enable/Disable the repetition of the event if the button is pressed")
]
public bool RepeatState
{
set { this.enableRepeatState = value; }
get { return this.enableRepeatState; }
}
[
Category("Button"),
Description("Interval to wait in ms for start the repetition")
]
public int StartRepeatInterval
{
set { this.startRepeatInterval = value; }
get { return this.startRepeatInterval; }
}
[
Category("Button"),
Description("Interva in ms for the repetition")
]
public int RepeatInterval
{
set { this.repeatInterval = value; }
get { return this.repeatInterval; }
}
#endregion
#region (* Events delegates *)
/// <summary>
/// Timer event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void Timer_Tick(object sender, EventArgs e)
{
this.tmrRepeat.Enabled = false;
// Update the interval
if (tmrRepeat.Interval == this.startRepeatInterval)
this.tmrRepeat.Interval = this.repeatInterval;
// Call the delagate
LBButtonEventArgs ev = new LBButtonEventArgs();
ev.State = this.State;
this.OnButtonRepeatState(ev);
this.tmrRepeat.Enabled = true;
}
/// <summary>
/// Mouse down event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void OnMouseDown(object sender, MouseEventArgs e)
{
// Change the state
this.State = ButtonState.Pressed;
this.Invalidate();
// Call the delagates
LBButtonEventArgs ev = new LBButtonEventArgs();
ev.State = this.State;
this.OnButtonChangeState(ev);
// Enable the repeat timer
if (this.RepeatState != false)
{
this.tmrRepeat.Interval = this.StartRepeatInterval;
this.tmrRepeat.Enabled = true;
}
}
/// <summary>
/// Mouse up event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void OnMuoseUp(object sender, MouseEventArgs e)
{
// Change the state
this.State = ButtonState.Normal;
this.Invalidate();
// Call the delagates
LBButtonEventArgs ev = new LBButtonEventArgs();
ev.State = this.State;
this.OnButtonChangeState(ev);
// Disable the timer
this.tmrRepeat.Enabled = false;
}
#endregion
#region (* Fire events *)
/// <summary>
/// Event for the state changed
/// </summary>
public event ButtonChangeState ButtonChangeState;
/// <summary>
/// Method for call the delagetes
/// </summary>
/// <param name="e"></param>
protected virtual void OnButtonChangeState(LBButtonEventArgs e)
{
if (this.ButtonChangeState != null)
this.ButtonChangeState(this, e);
}
/// <summary>
/// Event for the repetition of state
/// </summary>
public event ButtonRepeatState ButtonRepeatState;
/// <summary>
/// Method for call the delagetes
/// </summary>
/// <param name="e"></param>
protected virtual void OnButtonRepeatState(LBButtonEventArgs e)
{
if (this.ButtonRepeatState != null)
this.ButtonRepeatState(this, e);
}
#endregion
}
#region (* Classes for event and event delagates args *)
#region (* Event args class *)
/// <summary>
/// Class for events delegates
/// </summary>
public class LBButtonEventArgs : EventArgs
{
private LBButton.ButtonState state;
public LBButtonEventArgs()
{
}
public LBButton.ButtonState State
{
get { return this.state; }
set { this.state = value; }
}
}
#endregion
#region (* Delegates *)
public delegate void ButtonChangeState(object sender, LBButtonEventArgs e);
public delegate void ButtonRepeatState(object sender, LBButtonEventArgs e);
#endregion
#endregion
}
+53
View File
@@ -0,0 +1,53 @@
namespace JYControl
{
partial class LBLed
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.tmrBlink = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// tmrBlink
//
this.tmrBlink.Interval = 500;
this.tmrBlink.Tick += new System.EventHandler(this.OnBlink);
//
// LBLed
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Name = "LBLed";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Timer tmrBlink;
}
}
+214
View File
@@ -0,0 +1,214 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace JYControl
{
/// <summary>
/// Class for the Led control.
/// </summary>
public partial class LBLed : LBIndustrialCtrlBase
{
#region (* Enumeratives *)
public enum LedState
{
Off = 0,
On,
Blink,
}
public enum LedLabelPosition
{
Left = 0,
Top,
Right,
Bottom,
}
public enum LedStyle
{
Circular = 0,
Rectangular,
}
#endregion
#region (* Properties variables *)
private Color ledColor;
private LedState state;
private LedStyle style;
private LedLabelPosition labelPosition;
private String label = "Led";
private SizeF ledSize;
private int blinkInterval = 500;
#endregion
#region (* Class variables *)
//private Timer tmrBlink;
private bool blinkIsOn = false;
#endregion
#region (* Constructor *)
public LBLed()
{
InitializeComponent();
this.Size = new Size(20, 20);
this.ledColor = Color.Red;
this.state = LBLed.LedState.Off;
this.style = LBLed.LedStyle.Circular;
this.blinkIsOn = false;
this.ledSize = new SizeF(10F, 10F);
this.labelPosition = LedLabelPosition.Top;
}
#endregion
#region (* Properties *)
[
Category("Led"),
Description("改变LED灯样式")
]
public LedStyle Style
{
get { return style; }
set
{
style = value;
this.CalculateDimensions();
}
}
[
Category("Led"),
Description("改变LED灯颜色")
]
public Color LedColor
{
get { return ledColor; }
set
{
ledColor = value;
Invalidate();
}
}
[
Category("Led"),
Description("改变LED灯状态")
]
public LedState State
{
get { return state; }
set
{
state = value;
if (state == LedState.Blink)
{
this.blinkIsOn = true;
this.tmrBlink.Interval = this.BlinkInterval;
this.tmrBlink.Start();
}
else
{
this.blinkIsOn = true;
this.tmrBlink.Stop();
}
Invalidate();
}
}
[
Category("Led"),
Description("Size of the led")
]
public SizeF LedSize
{
get { return this.ledSize; }
set
{
this.ledSize = value;
this.CalculateDimensions();
Invalidate();
}
}
[
Category("Led"),
Description("Label of the led")
]
public String Label
{
get { return this.label; }
set
{
this.label = value;
Invalidate();
}
}
[
Category("Led"),
Description("Position of the label of the led")
]
public LedLabelPosition LabelPosition
{
get { return this.labelPosition; }
set
{
this.labelPosition = value;
this.CalculateDimensions();
Invalidate();
}
}
[
Category("Led"),
Description("Interval for the blink state of the led")
]
public int BlinkInterval
{
get { return this.blinkInterval; }
set { this.blinkInterval = value; }
}
[Browsable(false)]
public bool BlinkIsOn
{
get { return this.blinkIsOn; }
}
#endregion
#region (* Events delegates *)
void OnBlink(object sender, EventArgs e)
{
if (this.State == LedState.Blink)
{
if (this.blinkIsOn == false)
this.blinkIsOn = true;
else
this.blinkIsOn = false;
this.Invalidate();
}
}
#endregion
#region (* Overrided methods *)
protected override ILBRenderer CreateDefaultRenderer()
{
return new LBLedRenderer();
}
#endregion
}
}
+123
View File
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="tmrBlink.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
+44
View File
@@ -0,0 +1,44 @@
namespace JYControl
{
partial class LedControl
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// LedControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Name = "LedControl";
this.ResumeLayout(false);
}
#endregion
}
}
+426
View File
@@ -0,0 +1,426 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace JYControl
{
public partial class LedControl : UserControl
{
public LedControl()
{
InitializeComponent();
#region 【1】设置双缓冲等属性
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);
timer.Enabled = true;
timer.Tick += Timer_Tick;
#endregion
}
private void Timer_Tick(object sender, EventArgs e)
{
intColorIndex++;
if (intColorIndex >= lampColor.Length)
{
intColorIndex = 0;
}
this.Invalidate();
}
#region 【2】定义三个字段
private Graphics g;
private Pen p;
private SolidBrush sb;
Timer timer = new Timer();
private int intColorIndex = 0;
#endregion
#region 【3】添加一个设置Graphics的方法
private void SetGraphics(Graphics g)
{
//设置画布的属性
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
}
#endregion
#region 【4】根据实际控件分析的结果,创建属性
private Color ledTrueColor = Color.Green;
[Category("jason控件属性")]
[Description("TRUE的时候LED指示灯颜色")]
public Color LedTrueColor
{
get { return ledTrueColor; }
set
{
ledTrueColor = value;
this.Invalidate();
}
}
#endregion
private Color ledFalseColor = Color.Red;
[Category("jason控件属性")]
[Description("False的时候LED指示灯颜色")]
public Color LedFalseColor
{
get { return ledFalseColor; }
set
{
ledFalseColor = value;
this.Invalidate();
}
}
private bool ledStatus = true;
[Category("jason控件属性")]
[Description("当前的状态")]
public bool LedStatus
{
get { return ledStatus; }
set
{
ledStatus = value;
this.Invalidate();
}
}
private Color ledColor = Color.Green;
[Category("jason控件属性")]
[Description("LED指示灯演示")]
public Color LedColor
{
get { return ledColor; }
set
{
ledColor = value;
this.Invalidate();
}
}
private bool isBorder = true;
[Category("jason控件属性")]
[Description("是否有边框")]
public bool IsBorder
{
get { return isBorder; }
set
{
isBorder = value;
this.Invalidate();
}
}
private int borderWidth = 5;
[Category("jason控件属性")]
[Description("圆环的宽度")]
public int BorderWidth
{
get { return borderWidth; }
set
{
borderWidth = value;
this.Invalidate();
}
}
private int gapWidth = 5;
[Category("jason控件属性")]
[Description("间隙的宽度")]
public int GapWidth
{
get { return gapWidth; }
set
{
gapWidth = value;
this.Invalidate();
}
}
private bool isHighLight = true;
[Category("jason控件属性")]
[Description("是否高亮")]
public bool IsHighLight
{
get { return isHighLight; }
set
{
isHighLight = value;
this.Invalidate();
}
}
private Color centerColor = Color.White;
[Category("jason控件属性")]
[Description("渐变中心的颜色")]
public Color CenterColor
{
get { return centerColor; }
set
{
centerColor = value;
this.Invalidate();
}
}
private bool isFlash = true;
[Category("jason控件属性")]
[Description("是否闪烁")]
public bool IsFlash
{
get { return isFlash; }
set
{
isFlash = value;
this.Invalidate();
}
}
private int flashInterval = 500;
[Category("jason控件属性")]
[Description("闪烁的频率")]
public int FlashInterval
{
get { return flashInterval; }
set
{
flashInterval = value;
timer.Interval = flashInterval;//timer的时间间隔要放在这里
this.Invalidate();
}
}
private Color[] lampColor = new Color[] { };
[Category("jason控件属性")]
[Description("闪烁灯的几种颜色,当需要闪烁时,至少需要2个及以上颜色,不需要闪烁则至少需要1个颜色")]
public Color[] LampColor
{
get { return lampColor; }
set
{
if (value == null || value.Length <= 0)
return;
lampColor = value;
this.Invalidate();
}
}
#region 【5】创建重绘的事件
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
g = e.Graphics;//获取画布
SetGraphics(g);//设置画布
#region 1,画一个圆
int LEDWidth = Math.Min(this.Width, this.Height);
Color color = ledStatus ? ledTrueColor : ledFalseColor;
if (isFlash)
{
lampColor = new Color[] { color, Color.Yellow };
color = lampColor[intColorIndex];
}
sb = new SolidBrush(color);
RectangleF rec = new RectangleF(1, 1, LEDWidth - 2, LEDWidth - 2);//创建矩形
g.FillEllipse(sb, rec);//画圆
#endregion
#region 2,在圆里面画一个圆环
//如果有边框,那就画一个圆环
if (isBorder)//参数这里用字段或属性都可以,如果用属性,程序要都走一些判断的代码
{
p = new Pen(this.BackColor, borderWidth);//使用背景色
//p = new Pen(Color.Red, borderWidth);
float x = 1 + gapWidth + borderWidth * 0.5f;
rec = new RectangleF(x, x, LEDWidth - 2 * x, LEDWidth - 2 * x);
g.DrawEllipse(p, rec);//画圆环
}
#endregion
#region 3,渐变色绘制,是否高亮
if (isHighLight)
{
GraphicsPath gp = new GraphicsPath();
float x = isBorder ? 1 + gapWidth + borderWidth : 1;//使用三元运算来判断,优化代码
rec = new RectangleF(x, x, LEDWidth - 2 * x, LEDWidth - 2 * x);
gp.AddEllipse(rec);//把矩形添加到路径
//渐变色画刷,高亮
PathGradientBrush pgb = new PathGradientBrush(gp);//把路径传入
Color[] surroundColor = new Color[] { color };
pgb.CenterColor = this.centerColor;
//设置有多少组颜色来渐变
pgb.SurroundColors = surroundColor;
g.FillPath(pgb, gp);
}
#endregion
}
#endregion
}
}
+120
View File
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
+78
View File
@@ -0,0 +1,78 @@
namespace JYControl
{
partial class LogManagerControl
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.listView1 = new System.Windows.Forms.ListView();
this.time = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.message = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.SuspendLayout();
//
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.time,
this.message});
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.listView1.HideSelection = false;
this.listView1.Location = new System.Drawing.Point(0, 0);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(1103, 235);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;
//
// time
//
this.time.Text = "时间";
this.time.Width = 120;
//
// message
//
this.message.Text = "信息";
this.message.Width = 2000;
//
// LogManagerControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.listView1);
this.Name = "LogManagerControl";
this.Size = new System.Drawing.Size(1103, 235);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader time;
private System.Windows.Forms.ColumnHeader message;
}
}
+182
View File
@@ -0,0 +1,182 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace JYControl
{
public enum Logtype//枚举类型
{
Message,
Warning,
Error
}
public enum LogAddtype//枚举类型
{
MES,
local,
}
public partial class LogManagerControl : UserControl
{
static bool _newErrorInfo = false;
static int _ErrorCount = 0;
public LogManagerControl()
{
InitializeComponent();
this.DoubleBuffered = true;
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint,
true);
this.UpdateStyles();
}
private static readonly string logMesPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs", "MESLogs");
private static readonly string loglocalPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs", "localLogs");
private static LogManagerControl _manager = new LogManagerControl();
delegate void DoAddMessage(string message, LogAddtype logAddtype, Logtype logType = Logtype.Message);
//delegate void DoDelete();
public static void AddLog(string strLog, LogAddtype logAddtype, Logtype logType = Logtype.Message)
{
if (_manager.listView1.InvokeRequired)
{
DoAddMessage dam = new DoAddMessage(AddLog);
_manager.listView1.Invoke(dam, strLog,logAddtype, logType);
}
else
{
string strDate = DateTime.Now.ToString("HH:mm:ss:ff");
ListViewItem item = new ListViewItem();
switch (logType)
{
case Logtype.Message:
if (strLog.Contains("接收到客户端连接") || strLog.Contains("TCP服务器启动监听成功"))
{
item.ForeColor = Color.White;
item.BackColor = Color.SeaGreen;
}
break;
case Logtype.Warning:
item.BackColor = Color.Yellow;
strLog = "警告:" + strLog;
break;
case Logtype.Error:
item.BackColor = Color.Red;
item.ForeColor = Color.White;
strLog = "错误:" + strLog;
_newErrorInfo = true;
_ErrorCount++;
break;
default:
break;
}
item.Text = strDate;
item.SubItems.Add(strLog);
_manager.listView1.BeginUpdate();
_manager.listView1.Items.Insert(0, item);//添加在第一行
//_manager.listView1.Items.Add(item);//添加在最后一行
int ff = _manager.listView1.Items.Count - 1;
if (_manager.listView1.Items.Count > 150)
{
_manager.listView1.Items.RemoveAt(ff);
}
//_manager.listView1.Items[_manager.listView1.Items.Count - 1].EnsureVisible();
_manager.listView1.EndUpdate();
switch (logAddtype)
{
case LogAddtype.MES:
if (!Directory.Exists(logMesPath))
{
Directory.CreateDirectory(logMesPath);
}
using (StreamWriter sw = new StreamWriter(logMesPath+DateTime.Now.ToString("yyyyMMdd") + ".txt", true))
{
sw.WriteLine(strDate + " " + logType.ToString() + " " + strLog);
}
break;
case LogAddtype.local:
if (!Directory.Exists(loglocalPath))
{
Directory.CreateDirectory(loglocalPath);
}
using (StreamWriter sw = new StreamWriter(loglocalPath+DateTime.Now.ToString("yyyyMMdd") + ".txt", true))
{
sw.WriteLine(strDate + " " + logType.ToString() + " " + strLog);
}
break;
default:
break;
}
//添加日志到log文件中
}
}
public static void ClearLog()
{
//if (_manager.listView1.InvokeRequired)
//{
// DoDelete dam = new DoDelete(ClearLog);
// _manager.listView1.Invoke(dam);
//}
//else
//{
//if (_manager.listView1.Items.Count > 200)
//{
// _manager.listView1.Items.RemoveAt(item);
//}
_manager.listView1.Items.Clear();
//}
}
/// <summary>
/// 双缓冲ListView ,解决闪烁
/// </summary>
public class DoubleBufferListView : System.Windows.Forms.ListView
{
public DoubleBufferListView()
{
SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint, true);
UpdateStyles();
}
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0014) // 禁掉清除背景消息
return;
base.WndProc(ref m);
}
public static bool HasNewErrorInfo
{
get { return _newErrorInfo; }
set { _newErrorInfo = value; }
}
public static int ErrorInfoCount
{
get { return _ErrorCount; }
set { _ErrorCount = 0; }
}
public static LogManagerControl Manager
{
get { return LogManagerControl._manager; }
set { LogManagerControl._manager = value; }
}
}
}
+120
View File
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
+36
View File
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("JY.Control")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("JY.Control")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("01a2aa2c-9b80-41aa-9f47-3cb67e60af24")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
+143
View File
@@ -0,0 +1,143 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace JYControl.Properties {
using System;
/// <summary>
/// 一个强类型的资源类,用于查找本地化的字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// 返回此类使用的缓存的 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("JYControl.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 重写当前线程的 CurrentUICulture 属性,对
/// 使用此强类型资源类的所有资源查找执行重写。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap list_add {
get {
object obj = ResourceManager.GetObject("list_add", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap list_subtract {
get {
object obj = ResourceManager.GetObject("list_subtract", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap tips {
get {
object obj = ResourceManager.GetObject("tips", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap 下载 {
get {
object obj = ResourceManager.GetObject("下载", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap 增加 {
get {
object obj = ResourceManager.GetObject("增加", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap 查询 {
get {
object obj = ResourceManager.GetObject("查询", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap 设置 {
get {
object obj = ResourceManager.GetObject("设置", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap 运行中 {
get {
object obj = ResourceManager.GetObject("运行中", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}
+145
View File
@@ -0,0 +1,145 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="list_add" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Image\list_add.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="list_subtract" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Image\list_subtract.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="tips" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Image\tips.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="下载" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Image\下载.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="增加" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Image\增加.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="查询" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Image\查询.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="设置" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Image\设置.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="运行中" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Image\运行中.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
+36
View File
@@ -0,0 +1,36 @@
namespace JYControl
{
partial class PulseButton
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}
+554
View File
@@ -0,0 +1,554 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
namespace JYControl
{
public partial class PulseButton : Button
{
#region -- Members --
private readonly Timer pulseTimer;
private RectangleF[] pulses;
private RectangleF centerRect;
private Color[] pulseColors;
private int pulseWidth;
private bool mouseOver;
private bool pressed;
private float pulseSpeed;
public enum Shape
{
Round,
Rectangle
}
#endregion
#region -- Properties --
/// <summary>
/// Gets or sets the top button color.
/// </summary>
/// <value>The top button color.</value>
[Browsable(true), DefaultValue(typeof(Color), "CornflowerBlue")]
[Category("Appearance")]
public Color ButtonColorTop { get; set; }
/// <summary>
/// Gets or sets the bottom button color.
/// </summary>
/// <value>The bottom button color.</value>
[Browsable(true), DefaultValue(typeof(Color), "DodgerBlue")]
[Category("Appearance")]
public Color ButtonColorBottom { get; set; }
/// <summary>
/// Gets or sets the color of the pulse.
/// </summary>
/// <value>The color of the pulse.</value>
[Browsable(true), DefaultValue(typeof(Color), "Black")]
[Category("Appearance")]
public Color PulseColor { get; set; }
/// <summary>
/// Gets or sets the type of the shape.
/// </summary>
/// <value>The type of the shape.</value>
[Browsable(true), DefaultValue(typeof(Shape), "Round")]
[Category("Appearance")]
public Shape ShapeType { get; set; }
/// <summary>
/// Gets or sets the corner radius.
/// </summary>
/// <value>The corner radius.</value>
[Browsable(true), DefaultValue(10)]
[Category("Appearance")]
public int CornerRadius { get; set; }
/// <summary>
/// Gets or sets the color of the focus.
/// </summary>
/// <value>The color of the focus.</value>
[Browsable(true), DefaultValue(typeof(Color), "Orange")]
[Category("Appearance")]
public Color FocusColor { get; set; }
/// <summary>
/// Gets or sets the foreground color of the control.
/// </summary>
/// <value></value>
/// <returns>
/// The foreground <see cref="T:System.Drawing.Color"/> of the control. The default is the value of the <see cref="P:System.Windows.Forms.Control.DefaultForeColor"/> property.
/// </returns>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/>
/// </PermissionSet>
[Browsable(true), DefaultValue(typeof(Color), "White")]
[Category("Appearance")]
public new Color ForeColor
{
get { return base.ForeColor; }
set { base.ForeColor = value; }
}
/// <summary>
/// Gets or sets the number of pulses.
/// </summary>
/// <value>The number of pulses.</value>
[Browsable(true), DefaultValue(3)]
[Category("Appearance")]
public int NumberOfPulses
{
get { return pulses.Length; }
set
{
if (value <= 0) return;
pulses = new RectangleF[value];
pulseColors = new Color[value];
ArrangePulses();
}
}
/// <summary>
/// Gets or sets the width of the pulse.
/// </summary>
/// <value>The width of the pulse.</value>
[Browsable(true), DefaultValue(10)]
[Category("Appearance")]
public int PulseWidth
{
get { return pulseWidth; }
set { pulseWidth = value; ArrangePulses(); }
}
/// <summary>
/// Gets or sets the wave speed.
/// </summary>
/// <value>The speed of the pulses.</value>
[Browsable(true), DefaultValue(typeof(float), "0.3f")]
[Category("Appearance")]
public float PulseSpeed
{
get { return pulseSpeed; }
set
{
if (value <= 0) return;
pulseSpeed = value;
}
}
/// <summary>
/// Gets or sets the interval.
/// </summary>
/// <value>The interval.</value>
[Browsable(false), DefaultValue(50)]
public int Interval
{
get { return pulseTimer.Interval; }
set { pulseTimer.Interval = value; }
}
#endregion
#region -- Constructor --
/// <summary>
/// Initializes a new instance of the <see cref="PulseButton"/> class.
/// </summary>
public PulseButton()
{
// Control styles
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.UserPaint, true);
InitializeComponent();
// Layout & initialization
SuspendLayout();
pulseWidth = 10;
PulseSpeed = .3f;
ButtonColorTop = Color.CornflowerBlue;
ButtonColorBottom = Color.DodgerBlue;
FocusColor = Color.Orange;
PulseColor = Color.Black;
ShapeType = Shape.Round;
CornerRadius = 10;
Image = null;
base.TextAlign = ContentAlignment.MiddleCenter;
Size = new Size(40, 40);
// Timer
pulseTimer = new Timer { Interval = 50 };
pulseTimer.Tick += PulseTimerTick;
pulses = new RectangleF[3];
pulseColors = new Color[3];
ArrangePulses();
pulseTimer.Enabled = true;
ResumeLayout(true);
}
#endregion
#region -- EventHandlers --
/// <summary>
/// Handles the pulse timer tick.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void PulseTimerTick(object sender, EventArgs e)
{
pulseTimer.Enabled = false;
InflatePulses();
Invalidate();
pulseTimer.Enabled = true;
}
#endregion
#region -- Protected overrides --
#region - Mouse -
/// <summary>
/// Raises the <see cref="E:System.Windows.Forms.Control.MouseUp"/> event.
/// </summary>
/// <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs"/> that contains the event data.</param>
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
if (e.Button != MouseButtons.Left) return;
pressed = false;
}
/// <summary>
/// Raises the <see cref="E:System.Windows.Forms.Control.MouseDown"/> event.
/// </summary>
/// <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs"/> that contains the event data.</param>
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button != MouseButtons.Left) return;
pressed = true;
}
/// <summary>
/// Raises the <see cref="M:System.Windows.Forms.Control.OnMouseMove(System.Windows.Forms.MouseEventArgs)"/> event.
/// </summary>
/// <param name="mevent">A <see cref="T:System.Windows.Forms.MouseEventArgs"/> that contains the event data.</param>
protected override void OnMouseMove(MouseEventArgs mevent)
{
base.OnMouseMove(mevent);
mouseOver = centerRect.Contains(mevent.Location);
}
/// <summary>
/// Raises the <see cref="JYControl.OnMouseLeave"/> event.
/// </summary>
/// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param>
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
mouseOver = false;
pressed = false;
}
#endregion
/// <summary>
/// Raises the <see cref="E:System.Windows.Forms.Control.EnabledChanged"/> event.
/// </summary>
/// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
protected override void OnEnabledChanged(EventArgs e)
{
base.OnEnabledChanged(e);
pulseTimer.Enabled = Enabled;
}
/// <summary>
/// Raises the <see cref="E:System.Windows.Forms.Control.Resize"/> event.
/// </summary>
/// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
if (pulses == null || pulses.Length == 0) return;
ArrangePulses();
}
/// <summary>
/// Raises the <see cref="E:System.Windows.Forms.Control.Paint"/> event.
/// </summary>
/// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"/> that contains the event data.</param>
protected override void OnPaint(PaintEventArgs e)
{
//base.OnPaint(e);
base.OnPaintBackground(e);
// Set Graphics interpolation and smoothing
Graphics g = e.Graphics;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.AntiAlias;
// Draw pulses
DrawPulses(g);
if (centerRect.IsEmpty) return;
// Draw center
DrawCenter(g);
// Draw border
DrawBorder(g);
// Image
if (Image != null)
g.DrawImage(Image, centerRect);
// Draw highlight
if (mouseOver)
DrawHighLight(g);
// Reflex
if (!pressed) DrawReflex(g);
// Text
DrawText(g);
}
#endregion
#region -- Protected virtual methods --
/// <summary>
/// Draws the border.
/// </summary>
/// <param name="g">The graphics object</param>
protected virtual void DrawBorder(Graphics g)
{
using (var pen = new Pen(!Focused ? Color.FromArgb(60, Color.Black) : FocusColor, 2))
PaintShape(g, pen, centerRect);
}
/// <summary>
/// Draws the center.
/// </summary>
/// <param name="g">The graphics object</param>
protected virtual void DrawCenter(Graphics g)
{
if (Enabled)
{
using (var lgb = new LinearGradientBrush(centerRect, ButtonColorTop, ButtonColorBottom,
LinearGradientMode.Vertical))
{
PaintShape(g, lgb, centerRect);
}
}
else
{
using (var lgb = new SolidBrush(Color.Gray))
PaintShape(g, lgb, centerRect);
}
}
/// <summary>
/// Draws the pulses.
/// </summary>
/// <param name="g">The graphics object</param>
protected virtual void DrawPulses(Graphics g)
{
if (!Enabled) return;
for (var i = 0; i < pulses.Length; i++)
{
using (var sb = new SolidBrush(pulseColors[i]))
{
PaintShape(g, sb, pulses[i]);
}
}
}
/// <summary>
/// Draws the text.
/// </summary>
/// <param name="g">The graphics object</param>
protected virtual void DrawText(Graphics g)
{
var format = new StringFormat(StringFormat.GenericDefault) { Trimming = StringTrimming.EllipsisCharacter };
format.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
format.FormatFlags ^= StringFormatFlags.LineLimit;
format.HotkeyPrefix = HotkeyPrefix.Show;
SizeF size = g.MeasureString(Text, Font, new SizeF(centerRect.Width, centerRect.Height), format);
RectangleF textRect = GetAlignPlacement(TextAlign, centerRect, size);
using (var sb = new SolidBrush(ForeColor))
g.DrawString(Text, Font, sb, textRect, format);
}
/// <summary>
/// Draws the reflex.
/// </summary>
/// <param name="g">The graphics object</param>
protected virtual void DrawReflex(Graphics g)
{
using (var path = new GraphicsPath())
{
RectangleF rect = centerRect;
rect.Height = rect.Height / 2;
if (ShapeType == Shape.Round)
{
path.AddArc(centerRect, -180, 180);
RectangleF reflexRectangle = rect;
reflexRectangle.Offset(0, rect.Height);
reflexRectangle.Height /= 6;
path.AddArc(reflexRectangle, 0, 180);
path.CloseFigure();
}
else
{
rect.Height += rect.Height / 6;
path.AddRectangle(rect);
}
RectangleF area = path.GetBounds();
using (var lgb = new LinearGradientBrush(area, Color.FromArgb(30, Color.White),
Color.FromArgb(60, Color.White), -90))
{
g.FillPath(lgb, path);
}
}
}
/// <summary>
/// Draws the high light.
/// </summary>
/// <param name="g">The graphics object</param>
protected virtual void DrawHighLight(Graphics g)
{
RectangleF highlightRect = centerRect;
highlightRect.Inflate(-2, -2);
using (var pen = new Pen(Color.FromArgb(60, Color.White), 4))
{
if (ShapeType == Shape.Round)
g.DrawEllipse(pen, highlightRect);
else
g.DrawPath(pen, GetRoundRect(g, highlightRect, CornerRadius));
}
}
/// <summary>
/// Paints the shape.
/// </summary>
/// <param name="g">The graphics object</param>
/// <param name="p">The pen</param>
/// <param name="rectangle">The rectangle.</param>
protected virtual void PaintShape(Graphics g, Pen p, RectangleF rectangle)
{
if (ShapeType == Shape.Round)
g.DrawEllipse(p, rectangle);
else
using (var path = GetRoundRect(g, rectangle, CornerRadius))
g.DrawPath(p, path);
}
/// <summary>
/// Paints the shape.
/// </summary>
/// <param name="g">The graphics object</param>
/// <param name="b">The brush</param>
/// <param name="rectangle">The rectangle.</param>
protected virtual void PaintShape(Graphics g, Brush b, RectangleF rectangle)
{
if (ShapeType == Shape.Round)
g.FillEllipse(b, rectangle);
else
using (var path = GetRoundRect(g, rectangle, CornerRadius))
g.FillPath(b, path);
}
#endregion
#region -- Public static methods --
/// <summary>
/// Gets a path of a rectangle with round corners.
/// </summary>
/// <param name="g">The graphics object</param>
/// <param name="rect">The rectangle</param>
/// <param name="radius">The corner radius</param>
/// <returns></returns>
public static GraphicsPath GetRoundRect(Graphics g, RectangleF rect, float radius)
{
var gp = new GraphicsPath();
var diameter = radius * 2;
gp.AddArc(rect.X + rect.Width - diameter, rect.Y, diameter, diameter, 270, 90);
gp.AddArc(rect.X + rect.Width - diameter, rect.Y + rect.Height - diameter, diameter, diameter, 0, 90);
gp.AddArc(rect.X, rect.Y + rect.Height - diameter, diameter, diameter, 90, 90);
gp.AddArc(rect.X, rect.Y, diameter, diameter, 180, 90);
gp.CloseFigure();
return gp;
}
/// <summary>
/// Gets the placement.
/// </summary>
/// <param name="align">The alignment of the element</param>
/// <param name="rect">A retangle</param>
/// <param name="element">The element to be placed</param>
/// <returns></returns>
public static RectangleF GetAlignPlacement(ContentAlignment align, RectangleF rect, SizeF element)
{
// Left & Top (default)
float lft = rect.Left;
float top = rect.Y;
// Right
if ((align & (ContentAlignment.BottomRight | ContentAlignment.MiddleRight | ContentAlignment.TopRight)) != 0)
lft = rect.Right - element.Width;
// Center
else if ((align & (ContentAlignment.BottomCenter | ContentAlignment.MiddleCenter | ContentAlignment.TopCenter)) != 0)
lft = (rect.Width / 2) - (element.Width / 2) + rect.Left;
// Bottom
if ((align & (ContentAlignment.BottomCenter | ContentAlignment.BottomLeft | ContentAlignment.BottomRight)) != 0)
top = rect.Bottom - element.Height;
// Middle
else if ((align & (ContentAlignment.MiddleCenter | ContentAlignment.MiddleLeft | ContentAlignment.MiddleRight)) != 0)
top = (rect.Height / 2) - (element.Height / 2) + rect.Y;
return new RectangleF(lft, top, element.Width, element.Height);
}
#endregion
#region -- Private methods --
/// <summary>
/// Arranges the pulses.
/// </summary>
private void ArrangePulses()
{
centerRect = new RectangleF(pulseWidth, pulseWidth, Width - 2 * pulseWidth, Height - 2 * pulseWidth);
for (var i = 1; i <= pulses.Length; i++)
{
pulses[i - 1] = new RectangleF(
pulseWidth * i / (float)pulses.Length,
pulseWidth * i / (float)pulses.Length,
Width - 2 * pulseWidth * i / pulses.Length,
Height - 2 * pulseWidth * i / pulses.Length
);
pulseColors[i - 1] = Color.FromArgb((int)(Math.Min(pulses[i - 1].X * 255 / pulseWidth, 255)), Color.White);
}
}
/// <summary>
/// Inflates the pulses.
/// </summary>
private void InflatePulses()
{
for (var i = 0; i < pulses.Length; i++)
{
pulses[i].Inflate(PulseSpeed, PulseSpeed);
if (pulses[i].Width > Width || pulses[i].Height > Height || pulses[i].X < 0 || pulses[i].Y < 0)
pulses[i] = new RectangleF(pulseWidth, pulseWidth, Width - 2 * pulseWidth, Height - 2 * pulseWidth);
pulseColors[i] = Color.FromArgb((int)(Math.Min(pulses[i].X * 255 / pulseWidth, 255)), PulseColor);
}
}
#endregion
}
}
+141
View File
@@ -0,0 +1,141 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace JYControl
{
public class RingProgramBar : Control
{
//这个写最上面是因为我自己也不懂是啥意思,只知道界面控件高速的重绘容易产生闪烁的问题,这个加了就不会有
protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; return cp; } }
//-------------------颜色
private Color bgColor = Color.FromArgb(224, 224, 224); //背景边框颜色
private Color sectorColor = Color.FromArgb(109, 179, 63); //扇形颜色
[Category("控件属性")]
[Description("背景边框颜色")]
public Color BgColor
{
get { return this.bgColor; }
set
{
this.bgColor = value;
this.Invalidate();
}
}
[Category("控件属性")]
[Description("扇形颜色")]
public Color SectorColor
{
get { return this.sectorColor; }
set
{
this.sectorColor = value;
this.Invalidate();
}
}
private int borderWidth = 2; //边框宽度
[Category("控件属性")]
[Description("边框宽度")]
public int BorderWidth
{
get { return this.borderWidth; }
set
{
this.borderWidth = value;
this.Invalidate();
}
}
/// <summary>
/// 圆形进度条实心
/// </summary>
public RingProgramBar()
{
InitControl();
this.SizeChanged += delegate
{
this.Invalidate(); //重绘控件
};
}
int maxValue = 100; //进度最大值
private int progress = 0;
/// <summary>
/// 进度值
/// </summary>
[Category("控件属性")]
[Description("进度值,最大值100")]
public int Progress
{
get { return this.progress; }
set
{
if (value > this.maxValue)
{
return;
}
this.progress = value;
this.Invalidate();
}
}
/// <summary>
/// 初始化控件参数
/// </summary>
private void InitControl()
{
this.Width = 200;
this.Height = 200;
}
//对Control进行绘制
protected override void OnPaint(PaintEventArgs e)
{
DrawShape(e.Graphics); //绘制控件样式
}
/// <summary>
/// 画图
/// </summary>
/// <param name="g">画图工具类</param>
private void DrawShape(Graphics g)
{
if (this.Width < borderWidth*4 || this.Height < borderWidth*4)
{
return;
}
g.SmoothingMode = SmoothingMode.AntiAlias; //消除锯齿,也就是抗锯齿什么鬼东西
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.CompositingQuality = CompositingQuality.HighQuality;
RectangleF bg_rectangle = new RectangleF(0+ borderWidth, 0+ borderWidth, Width - borderWidth * 2, Height - borderWidth * 2); //控件整体坐标
g.DrawEllipse(new Pen(bgColor, borderWidth), bg_rectangle); //画背景圆
Rectangle rl = new Rectangle(0 + borderWidth , 0 + borderWidth , this.Width - borderWidth * 2, this.Height - borderWidth * 2);
decimal topAngle = (this.progress * 1.0M / this.maxValue) * 360M;//计算进度条划过的度数
g.DrawArc(new Pen(sectorColor,borderWidth), rl, 0, (float)topAngle); //填充环形
SizeF fs = g.MeasureString(this.progress.ToString() + "%", this.Font);//计算文字的范围
//SizeF fs = g.MeasureString(this.progress.ToString(), this.Font);//计算文字的范围
g.DrawString(this.progress.ToString() + "%", this.Font, new SolidBrush(this.ForeColor),
//g.DrawString(this.progress.ToString(), this.Font, new SolidBrush(this.ForeColor),
bg_rectangle.X + bg_rectangle.Width / 2 - fs.Width / 2, bg_rectangle.Y + bg_rectangle.Height / 2 - fs.Height / 2);
}
}
}
+36
View File
@@ -0,0 +1,36 @@
namespace JYControl
{
partial class RoundButton
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}
+383
View File
@@ -0,0 +1,383 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace JYControl
{
//public partial class RoundButton : Button
//{
// public RoundButton()
// {
// InitializeComponent();
// }
// protected override void OnPaint(PaintEventArgs pe)
// {
// base.OnPaint(pe);
// }
//}
public partial class RoundButton : Button
{
#region --成员变量--
RectangleF rect = new RectangleF();//控件矩形
bool mouseEnter;//鼠标是否进入控件区域的标志
bool buttonPressed;//按钮是否按下
bool buttonClicked;//按钮是否被点击
#endregion
#region --属性--
#region 形状
/// <summary>
/// 设置或获取圆形按钮的圆的边距离方框边的距离
/// </summary>
[Browsable(true), DefaultValue(2)]
[Category("Appearance")]
public int DistanceToBorder { get; set; }
#endregion
#region 填充色
/// <summary>
/// 获取或设置按钮主体颜色
/// </summary>
/// <value>The color of the focus.</value>
[Browsable(true), DefaultValue(typeof(Color), "DodgerBlue"), Description("按钮主体渐变起始颜色")]
[Category("Appearance")]
public Color ButtonCenterColorEnd { get; set; }
/// <summary>
/// 获取或设置按钮主体颜色
/// </summary>
[Browsable(true), DefaultValue(typeof(Color), "CornflowerBlue"), Description("按钮主体渐变终点颜色")]
[Category("Appearance")]
public Color ButtonCenterColorStart { get; set; }
/// <summary>
/// 获取或设置按钮主体颜色渐变方向
/// </summary>
[Browsable(true), DefaultValue(90), Description("按钮主体颜色渐变方向,X轴顺时针开始")]
[Category("Appearance")]
public int GradientAngle { get; set; }
/// <summary>
/// 是否显示中间标志
/// </summary>
[Browsable(true), DefaultValue(typeof(bool), "true"), Description("是否显示中间标志")]
[Category("Appearance")]
public bool IsShowIcon { get; set; }
/// <summary>
/// 按钮中间标志填充色
/// </summary>
[Browsable(true), DefaultValue(typeof(Color), "Black"), Description("按钮中间标志填充色")]
[Category("Appearance")]
public Color IconColor { get; set; }
#endregion
#region 边框
/// <summary>
/// 获取或设置边框大小
/// </summary>
[Browsable(true), DefaultValue(4), Description("按钮边框大小")]
[Category("Appearance")]
public int BorderWidth { get; set; }
/// <summary>
/// 获取或设置按钮边框颜色
/// </summary>
/// <value>The color of the focus.</value>
[Browsable(true), DefaultValue(typeof(Color), "Black"), Description("按钮边框颜色")]
[Category("Appearance")]
public Color BorderColor { get; set; }
/// <summary>
/// 获取或设置边框透明度
/// </summary>
[Browsable(true), DefaultValue(200), Description("设置边框透明度:0-255")]
[Category("Appearance")]
public int BorderTransparent { get; set; }
/// <summary>
/// 获取或设置按钮获取焦点后边框颜色
/// </summary>
/// <value>The color of the focus.</value>
[Browsable(true), DefaultValue(typeof(Color), "Orange"), Description("按钮获得焦点后的边框颜色")]
[Category("Appearance")]
public Color FocusBorderColor { get; set; }
#endregion
#endregion
#region --构造函数--
/// <summary>
/// 构造函数
/// </summary>
public RoundButton()
{
// 控件风格
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.UserPaint, true);
//初始值设定
this.Height = this.Width = 80;
DistanceToBorder = 4;
ButtonCenterColorStart = Color.CornflowerBlue;
ButtonCenterColorEnd = Color.DodgerBlue;
BorderColor = Color.Black;
FocusBorderColor = Color.Orange;
IconColor = Color.Black;
BorderWidth = 4;
BorderTransparent = 200;
GradientAngle = 90;
mouseEnter = false;
buttonPressed = false;
buttonClicked = false;
IsShowIcon = true;
InitializeComponent();
}
#endregion
#region --重写部分事件--
#region OnPaint事件
/// <summary>
/// 控件绘制
/// </summary>
/// <param name="pevent"></param>
protected override void OnPaint(PaintEventArgs pevent)
{
//base.OnPaint(pevent);
base.OnPaintBackground(pevent);
Graphics g = pevent.Graphics;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.AntiAlias;//抗锯齿
myResize();//调整圆形区域
var brush = new LinearGradientBrush(rect, ButtonCenterColorStart, ButtonCenterColorEnd, GradientAngle);
PaintShape(g, brush, rect);//绘制按钮中心区域
DrawBorder(g);//绘制边框
DrawStateIcon(g);//绘制按钮功能标志
if (mouseEnter)
{
DrawHighLight(g);//绘制高亮区域
DrawStateIcon(g);//绘制按钮功能标志
}
}
#endregion
#region 鼠标
/// <summary>
/// 鼠标点击事件
/// </summary>
/// <param name="e"></param>
protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
buttonClicked = !buttonClicked;
}
/// <summary>
/// Raises the <see cref="E:System.Windows.Forms.Control.MouseUp"/> event.
/// </summary>
/// <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs"/> that contains the event data.</param>
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
if (e.Button != MouseButtons.Left) return;
buttonPressed = false;
base.Invalidate();
}
/// <summary>
/// Raises the <see cref="E:System.Windows.Forms.Control.MouseDown"/> event.
/// </summary>
/// <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs"/> that contains the event data.</param>
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button != MouseButtons.Left) return;
buttonPressed = true;
}
/// <summary>
/// 鼠标进入按钮
/// </summary>
/// <param name="e"></param>
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
mouseEnter = true;
}
/// <summary>
/// 鼠标离开控件
/// </summary>
/// <param name="e"></param>
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
mouseEnter = false;
}
#endregion
#endregion
#region --自定义函数--
/// <summary>
/// 绘制中心区域标志
/// </summary>
/// <param name="g"></param>
private void DrawStateIcon(Graphics g)
{
if (IsShowIcon)
{
if (buttonClicked)
{
GraphicsPath startIconPath = new GraphicsPath();
int W = base.Width / 3;
Point p1 = new Point(W, W);
Point p2 = new Point(2 * W, W);
Point p3 = new Point(2 * W, 2 * W);
Point p4 = new Point(W, 2 * W);
Point[] pts = { p1, p2, p3, p4 };
startIconPath.AddLines(pts);
Brush brush = new SolidBrush(IconColor);
g.FillPath(brush, startIconPath);
}
else
{
GraphicsPath stopIconPath = new GraphicsPath();
int W = base.Width / 4;
Point p1 = new Point(3 * W / 2, W);
Point p2 = new Point(3 * W / 2, 3 * W);
Point p3 = new Point(3 * W, 2 * W);
Point[] pts = { p1, p2, p3, };
stopIconPath.AddLines(pts);
Brush brush = new SolidBrush(IconColor);
g.FillPath(brush, stopIconPath);
}
}
}
/// <summary>
/// 重新确定控件大小
/// </summary>
protected void myResize()
{
int x = DistanceToBorder;
int y = DistanceToBorder;
int width = this.Width - 2 * DistanceToBorder;
int height = this.Height - 2 * DistanceToBorder;
rect = new RectangleF(x, y, width, height);
}
/// <summary>
/// 绘制高亮效果
/// </summary>
/// <param name="g">Graphic对象</param>
protected virtual void DrawHighLight(Graphics g)
{
RectangleF highlightRect = rect;
highlightRect.Inflate(-BorderWidth / 2, -BorderWidth / 2);
Brush brush = Brushes.DodgerBlue;
if (buttonPressed)
{
brush = new LinearGradientBrush(rect, ButtonCenterColorStart, ButtonCenterColorEnd, GradientAngle);
}
else
{
brush = new LinearGradientBrush(rect, Color.FromArgb(60, Color.White),
Color.FromArgb(60, Color.White), GradientAngle);
}
PaintShape(g, brush, highlightRect);
}
/// <summary>
/// 绘制边框
/// </summary>
/// <param name="g">Graphics对象</param>
protected virtual void DrawBorder(Graphics g)
{
Pen p = new Pen(BorderColor);
if (Focused)
{
p.Color = FocusBorderColor;//外圈获取焦点后的颜色
p.Width = BorderWidth;
PaintShape(g, p, rect);
}
else
{
p.Width = BorderWidth;
PaintShape(g, p, rect);
}
}
/// <summary>
///
/// </summary>
/// <param name="g">Graphic对象</param>
protected virtual void DrawPressState(Graphics g)
{
RectangleF pressedRect = rect;
pressedRect.Inflate(-2, -2);
Brush brush = new LinearGradientBrush(rect, Color.FromArgb(60, Color.White),
Color.FromArgb(60, Color.White), GradientAngle);
PaintShape(g, brush, pressedRect);
}
/// <summary>
/// 绘制图形
/// </summary>
/// <param name="g">Graphics对象</param>
/// <param name="pen">Pen对象</param>
/// <param name="rect">RectangleF对象</param>
protected virtual void PaintShape(Graphics g, Pen pen, RectangleF rect)
{
g.DrawEllipse(pen, rect);
}
/// <summary>
/// 绘制图形
/// </summary>
/// <param name="g">Graphics对象</param>
/// <param name="brush">Brush对象</param>
/// <param name="rect">Rectangle对象</param>
protected virtual void PaintShape(Graphics g, Brush brush, RectangleF rect)
{
g.FillEllipse(brush, rect);
}
#endregion
}
}
+98
View File
@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace JYControl
{
/// <summary>
/// TextBox添加水印文字
/// </summary>
[ToolboxBitmap(typeof(TextBox))]
public class WatermarkTextBox : TextBox
{
private string _watermark;
private Color _watermarkColor = Color.DarkGray;
private const int WM_PAINT = 0xF;
public WatermarkTextBox()
: base()
{
}
/// <summary>
/// 输入需要显示水印文字
/// </summary>
///
[Category("控件属性")]
[Description("输入需要显示水印文字")]
[DefaultValue("")]
public string Watermark
{
get { return _watermark; }
set
{
_watermark = value;
base.Invalidate();
}
}
/// <summary>
/// 改变水印文字的颜色
/// </summary>
///
[Category("控件属性")]
[Description("改变水印文字的颜色")]
[DefaultValue(typeof(Color), "DarkGray")]
public Color WatermarkColor
{
get { return _watermarkColor; }
set
{
_watermarkColor = value;
base.Invalidate();
}
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_PAINT)
{
WmPaint(ref m);
}
}
private void WmPaint(ref Message m)
{
using (Graphics graphics = Graphics.FromHwnd(base.Handle))
{
if (Text.Length == 0
&& !string.IsNullOrEmpty(_watermark)
&& !Focused)
{
TextFormatFlags format =
TextFormatFlags.EndEllipsis |
TextFormatFlags.VerticalCenter;
if (RightToLeft == RightToLeft.Yes)
{
format |= TextFormatFlags.RightToLeft | TextFormatFlags.Right;
}
TextRenderer.DrawText(
graphics,
_watermark,
Font,
base.ClientRectangle,
_watermarkColor,
format);
}
}
}
}
}
+43
View File
@@ -0,0 +1,43 @@
namespace JYControl
{
partial class TreeViewEx
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// TreeViewEx
//
this.Name = "NaviButton";
this.Size = new System.Drawing.Size(133, 57);
this.ResumeLayout(false);
}
#endregion
}
}
+649
View File
@@ -0,0 +1,649 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using JYControl.Properties;
namespace JYControl
{
/// <summary>
/// Class TreeViewEx.
/// Implements the <see cref="System.Windows.Forms.TreeView" />
/// </summary>
/// <seealso cref="System.Windows.Forms.TreeView" />
public partial class TreeViewEx : TreeView
{
/// <summary>
/// The ws vscroll
/// </summary>
private const int WS_VSCROLL = 2097152;
/// <summary>
/// The GWL style
/// </summary>
private const int GWL_STYLE = -16;
/// <summary>
/// The LST tips
/// </summary>
private Dictionary<string, string> _lstTips = new Dictionary<string, string>();
/// <summary>
/// The tip font
/// </summary>
private Font _tipFont = new Font("Arial Unicode MS", 12f);
/// <summary>
/// The tip image
/// </summary>
private Image _tipImage = JYControl.Properties.Resources.tips;
/// <summary>
/// The is show tip
/// </summary>
private bool _isShowTip = false;
/// <summary>
/// The is show by custom model
/// </summary>
private bool _isShowByCustomModel = true;
/// <summary>
/// The node height
/// </summary>
private int _nodeHeight = 50;
/// <summary>
/// The node down pic
/// </summary>
private Image _nodeDownPic = JYControl.Properties.Resources.list_add;
/// <summary>
/// The node up pic
/// </summary>
private Image _nodeUpPic = JYControl.Properties.Resources.list_subtract;
/// <summary>
/// The node background color
/// </summary>
private Color _nodeBackgroundColor = Color.White;
/// <summary>
/// The node fore color
/// </summary>
private Color _nodeForeColor = Color.FromArgb(62, 62, 62);
/// <summary>
/// The node is show split line
/// </summary>
private bool _nodeIsShowSplitLine = false;
/// <summary>
/// The node split line color
/// </summary>
private Color _nodeSplitLineColor = Color.FromArgb(232, 232, 232);
/// <summary>
/// The m node selected color
/// </summary>
private Color m_nodeSelectedColor = Color.FromArgb(255, 77, 59);
/// <summary>
/// The m node selected fore color
/// </summary>
private Color m_nodeSelectedForeColor = Color.White;
/// <summary>
/// The parent node can select
/// </summary>
private bool _parentNodeCanSelect = true;
/// <summary>
/// The tree font size
/// </summary>
private SizeF treeFontSize = SizeF.Empty;
/// <summary>
/// The BLN has v bar
/// </summary>
private bool blnHasVBar = false;
/// <summary>
/// Gets or sets the LST tips.
/// </summary>
/// <value>The LST tips.</value>
public Dictionary<string, string> LstTips
{
get
{
return this._lstTips;
}
set
{
this._lstTips = value;
}
}
/// <summary>
/// Gets or sets the tip font.
/// </summary>
/// <value>The tip font.</value>
[Category("自定义属性"), Description("角标文字字体")]
public Font TipFont
{
get
{
return this._tipFont;
}
set
{
this._tipFont = value;
}
}
/// <summary>
/// Gets or sets the tip image.
/// </summary>
/// <value>The tip image.</value>
[Category("自定义属性"), Description("是否显示角标")]
public Image TipImage
{
get
{
return this._tipImage;
}
set
{
this._tipImage = value;
}
}
/// <summary>
/// Gets or sets a value indicating whether this instance is show tip.
/// </summary>
/// <value><c>true</c> if this instance is show tip; otherwise, <c>false</c>.</value>
[Category("自定义属性"), Description("是否显示角标")]
public bool IsShowTip
{
get
{
return this._isShowTip;
}
set
{
this._isShowTip = value;
}
}
/// <summary>
/// Gets or sets a value indicating whether this instance is show by custom model.
/// </summary>
/// <value><c>true</c> if this instance is show by custom model; otherwise, <c>false</c>.</value>
[Category("自定义属性"), Description("使用自定义模式")]
public bool IsShowByCustomModel
{
get
{
return this._isShowByCustomModel;
}
set
{
this._isShowByCustomModel = value;
}
}
/// <summary>
/// Gets or sets the height of the node.
/// </summary>
/// <value>The height of the node.</value>
[Category("自定义属性"), Description("节点高度(IsShowByCustomModel=true时生效)")]
public int NodeHeight
{
get
{
return this._nodeHeight;
}
set
{
this._nodeHeight = value;
base.ItemHeight = value;
}
}
/// <summary>
/// Gets or sets the node down pic.
/// </summary>
/// <value>The node down pic.</value>
[Category("自定义属性"), Description("下翻图标(IsShowByCustomModel=true时生效)")]
public Image NodeDownPic
{
get
{
return this._nodeDownPic;
}
set
{
this._nodeDownPic = value;
}
}
/// <summary>
/// Gets or sets the node up pic.
/// </summary>
/// <value>The node up pic.</value>
[Category("自定义属性"), Description("上翻图标(IsShowByCustomModel=true时生效)")]
public Image NodeUpPic
{
get
{
return this._nodeUpPic;
}
set
{
this._nodeUpPic = value;
}
}
/// <summary>
/// Gets or sets the color of the node background.
/// </summary>
/// <value>The color of the node background.</value>
[Category("自定义属性"), Description("节点背景颜色(IsShowByCustomModel=true时生效)")]
public Color NodeBackgroundColor
{
get
{
return this._nodeBackgroundColor;
}
set
{
this._nodeBackgroundColor = value;
}
}
/// <summary>
/// Gets or sets the color of the node fore.
/// </summary>
/// <value>The color of the node fore.</value>
[Category("自定义属性"), Description("节点字体颜色(IsShowByCustomModel=true时生效)")]
public Color NodeForeColor
{
get
{
return this._nodeForeColor;
}
set
{
this._nodeForeColor = value;
}
}
/// <summary>
/// Gets or sets a value indicating whether [node is show split line].
/// </summary>
/// <value><c>true</c> if [node is show split line]; otherwise, <c>false</c>.</value>
[Category("自定义属性"), Description("节点是否显示分割线(IsShowByCustomModel=true时生效)")]
public bool NodeIsShowSplitLine
{
get
{
return this._nodeIsShowSplitLine;
}
set
{
this._nodeIsShowSplitLine = value;
}
}
/// <summary>
/// Gets or sets the color of the node split line.
/// </summary>
/// <value>The color of the node split line.</value>
[Category("自定义属性"), Description("节点分割线颜色(IsShowByCustomModel=true时生效)")]
public Color NodeSplitLineColor
{
get
{
return this._nodeSplitLineColor;
}
set
{
this._nodeSplitLineColor = value;
}
}
/// <summary>
/// Gets or sets the color of the node selected.
/// </summary>
/// <value>The color of the node selected.</value>
[Category("自定义属性"), Description("选中节点背景颜色(IsShowByCustomModel=true时生效)")]
public Color NodeSelectedColor
{
get
{
return this.m_nodeSelectedColor;
}
set
{
this.m_nodeSelectedColor = value;
}
}
/// <summary>
/// Gets or sets the color of the node selected fore.
/// </summary>
/// <value>The color of the node selected fore.</value>
[Category("自定义属性"), Description("选中节点字体颜色(IsShowByCustomModel=true时生效)")]
public Color NodeSelectedForeColor
{
get
{
return this.m_nodeSelectedForeColor;
}
set
{
this.m_nodeSelectedForeColor = value;
}
}
/// <summary>
/// Gets or sets a value indicating whether [parent node can select].
/// </summary>
/// <value><c>true</c> if [parent node can select]; otherwise, <c>false</c>.</value>
[Category("自定义属性"), Description("父节点是否可选中")]
public bool ParentNodeCanSelect
{
get
{
return this._parentNodeCanSelect;
}
set
{
this._parentNodeCanSelect = value;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="TreeViewEx" /> class.
/// </summary>
public TreeViewEx()
{
base.HideSelection = false;
base.DrawMode = TreeViewDrawMode.OwnerDrawAll;
base.DrawNode += new DrawTreeNodeEventHandler(this.treeview_DrawNode);
base.NodeMouseClick += new TreeNodeMouseClickEventHandler(this.TreeViewEx_NodeMouseClick);
base.SizeChanged += new EventHandler(this.TreeViewEx_SizeChanged);
base.AfterSelect += new TreeViewEventHandler(this.TreeViewEx_AfterSelect);
base.FullRowSelect = true;
base.ShowLines = false;
base.ShowPlusMinus = false;
base.ShowRootLines = false;
this.BackColor = Color.White;
this.BorderStyle = System.Windows.Forms.BorderStyle.None;
DoubleBuffered = true;
}
/// <summary>
/// 重写 <see cref="M:System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message@)" />。
/// </summary>
/// <param name="m">要处理的 Windows<see cref="T:System.Windows.Forms.Message" />。</param>
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0014) // 禁掉清除背景消息WM_ERASEBKGND
return;
base.WndProc(ref m);
}
/// <summary>
/// Handles the AfterSelect event of the TreeViewEx control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="TreeViewEventArgs" /> instance containing the event data.</param>
private void TreeViewEx_AfterSelect(object sender, TreeViewEventArgs e)
{
try
{
if (e.Node != null)
{
if (!this._parentNodeCanSelect)
{
if (e.Node.Nodes.Count > 0)
{
e.Node.Expand();
base.SelectedNode = e.Node.Nodes[0];
}
}
}
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// Handles the SizeChanged event of the TreeViewEx control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
private void TreeViewEx_SizeChanged(object sender, EventArgs e)
{
this.Refresh();
}
/// <summary>
/// Handles the NodeMouseClick event of the TreeViewEx control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="TreeNodeMouseClickEventArgs" /> instance containing the event data.</param>
private void TreeViewEx_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
try
{
if (e.Node != null)
{
if (e.Node.Nodes.Count > 0)
{
if (e.Node.IsExpanded)
{
e.Node.Collapse();
}
else
{
e.Node.Expand();
}
}
if (base.SelectedNode != null)
{
if (base.SelectedNode == e.Node && e.Node.IsExpanded)
{
if (!this._parentNodeCanSelect)
{
if (e.Node.Nodes.Count > 0)
{
base.SelectedNode = e.Node.Nodes[0];
}
}
}
}
}
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// Handles the DrawNode event of the treeview control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="DrawTreeNodeEventArgs" /> instance containing the event data.</param>
private void treeview_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
try
{
if (e.Node == null || !this._isShowByCustomModel || (e.Node.Bounds.Width <= 0 && e.Node.Bounds.Height <= 0 && e.Node.Bounds.X <= 0 && e.Node.Bounds.Y <= 0))
{
e.DrawDefault = true;
}
else
{
e.Graphics.SetGDIHigh();
if (base.Nodes.IndexOf(e.Node) == 0)
{
this.blnHasVBar = this.IsVerticalScrollBarVisible();
}
Font font = e.Node.NodeFont;
if (font == null)
{
font = ((TreeView)sender).Font;
}
if (this.treeFontSize == SizeF.Empty)
{
this.treeFontSize = this.GetFontSize(font, e.Graphics);
}
bool flag = false;
int intLeft = 0;
if (CheckBoxes)
{
intLeft = 20;
}
int num = 0;
if (base.ImageList != null && base.ImageList.Images.Count > 0 && e.Node.ImageIndex >= 0 && e.Node.ImageIndex < base.ImageList.Images.Count)
{
flag = true;
num = (e.Bounds.Height - base.ImageList.ImageSize.Height) / 2;
intLeft += base.ImageList.ImageSize.Width;
}
intLeft += e.Node.Level * Indent;
if ((e.State == TreeNodeStates.Selected || e.State == TreeNodeStates.Focused || e.State == (TreeNodeStates.Focused | TreeNodeStates.Selected)) && (this._parentNodeCanSelect || e.Node.Nodes.Count <= 0))
{
e.Graphics.FillRectangle(new SolidBrush(this.m_nodeSelectedColor), new Rectangle(new Point(0, e.Node.Bounds.Y), new Size(base.Width, e.Node.Bounds.Height)));
e.Graphics.DrawString(e.Node.Text, font, new SolidBrush(this.m_nodeSelectedForeColor), (float)e.Bounds.X + intLeft, (float)e.Bounds.Y + ((float)this._nodeHeight - this.treeFontSize.Height) / 2f);
}
else
{
e.Graphics.FillRectangle(new SolidBrush(this._nodeBackgroundColor), new Rectangle(new Point(0, e.Node.Bounds.Y), new Size(base.Width, e.Node.Bounds.Height)));
e.Graphics.DrawString(e.Node.Text, font, new SolidBrush(this._nodeForeColor), (float)e.Bounds.X + intLeft, (float)e.Bounds.Y + ((float)this._nodeHeight - this.treeFontSize.Height) / 2f);
}
if (CheckBoxes)
{
Rectangle rectCheck = new Rectangle(e.Bounds.X + 3 + e.Node.Level * Indent, e.Bounds.Y + (e.Bounds.Height - 16) / 2, 16, 16);
GraphicsPath pathCheck = rectCheck.CreateRoundedRectanglePath(3);
e.Graphics.FillPath(new SolidBrush(Color.FromArgb(247, 247, 247)), pathCheck);
if (e.Node.Checked)
{
e.Graphics.DrawLines(new Pen(new SolidBrush(m_nodeSelectedColor), 2), new Point[]
{
new Point(rectCheck.Left+2,rectCheck.Top+8),
new Point(rectCheck.Left+6,rectCheck.Top+12),
new Point(rectCheck.Right-4,rectCheck.Top+4)
});
}
e.Graphics.DrawPath(new Pen(new SolidBrush(Color.FromArgb(200, 200, 200))), pathCheck);
}
if (flag)
{
int num2 = e.Bounds.X - num - base.ImageList.ImageSize.Width;
if (num2 < 0)
{
num2 = 3;
}
e.Graphics.DrawImage(base.ImageList.Images[e.Node.ImageIndex], new Rectangle(new Point(num2 + intLeft - base.ImageList.ImageSize.Width, e.Bounds.Y + num), base.ImageList.ImageSize));
}
if (this._nodeIsShowSplitLine)
{
e.Graphics.DrawLine(new Pen(this._nodeSplitLineColor, 1f), new Point(0, e.Bounds.Y + this._nodeHeight - 1), new Point(base.Width, e.Bounds.Y + this._nodeHeight - 1));
}
bool flag2 = false;
if (e.Node.Nodes.Count > 0)
{
if (e.Node.IsExpanded && this._nodeUpPic != null)
{
e.Graphics.DrawImage(this._nodeUpPic, new Rectangle(base.Width - (this.blnHasVBar ? 50 : 30), e.Bounds.Y + (this._nodeHeight - 20) / 2, 20, 20));
}
else if (this._nodeDownPic != null)
{
e.Graphics.DrawImage(this._nodeDownPic, new Rectangle(base.Width - (this.blnHasVBar ? 50 : 30), e.Bounds.Y + (this._nodeHeight - 20) / 2, 20, 20));
}
flag2 = true;
}
if (this._isShowTip && this._lstTips.ContainsKey(e.Node.Name) && !string.IsNullOrWhiteSpace(this._lstTips[e.Node.Name]))
{
int num3 = base.Width - (this.blnHasVBar ? 50 : 30) - (flag2 ? 20 : 0);
int num4 = e.Bounds.Y + (this._nodeHeight - 20) / 2;
e.Graphics.DrawImage(this._tipImage, new Rectangle(num3, num4, 20, 20));
SizeF sizeF = e.Graphics.MeasureString(this._lstTips[e.Node.Name], this._tipFont, 100, StringFormat.GenericTypographic);
e.Graphics.DrawString(this._lstTips[e.Node.Name], this._tipFont, new SolidBrush(Color.White), (float)(num3 + 10) - sizeF.Width / 2f - 3f, (float)(num4 + 10) - sizeF.Height / 2f);
}
}
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// Gets the size of the font.
/// </summary>
/// <param name="font">The font.</param>
/// <param name="g">The g.</param>
/// <returns>SizeF.</returns>
private SizeF GetFontSize(Font font, Graphics g = null)
{
SizeF result;
try
{
bool flag = false;
if (g == null)
{
g = base.CreateGraphics();
flag = true;
}
SizeF sizeF = g.MeasureString("a", font, 100, StringFormat.GenericTypographic);
if (flag)
{
g.Dispose();
}
result = sizeF;
}
catch (Exception ex)
{
throw ex;
}
return result;
}
/// <summary>
/// Gets the window long.
/// </summary>
/// <param name="hwnd">The HWND.</param>
/// <param name="nIndex">Index of the n.</param>
/// <returns>System.Int32.</returns>
[DllImport("user32", CharSet = CharSet.Auto)]
private static extern int GetWindowLong(IntPtr hwnd, int nIndex);
/// <summary>
/// Determines whether [is vertical scroll bar visible].
/// </summary>
/// <returns><c>true</c> if [is vertical scroll bar visible]; otherwise, <c>false</c>.</returns>
private bool IsVerticalScrollBarVisible()
{
return base.IsHandleCreated && (TreeViewEx.GetWindowLong(base.Handle, -16) & 2097152) != 0;
}
}
}
+123
View File
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
</root>