添加项目文件。
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user