Commit 04b5fedc HZH

倒影组件

1 个父辈 e5d7c299
......@@ -6,16 +6,16 @@ using System.Windows.Forms;
namespace HZH_Controls.Controls
{
[DefaultEvent("Paint")]
public partial class GraphicalOverlay : Component
public partial class GraphicalOverlayComponent : Component
{
public event EventHandler<PaintEventArgs> Paint;
public GraphicalOverlay()
public GraphicalOverlayComponent()
{
InitializeComponent();
}
public GraphicalOverlay(IContainer container)
public GraphicalOverlayComponent(IContainer container)
{
container.Add(this);
......
namespace HZH_Controls.Controls
{
partial class GraphicalOverlay
partial class GraphicalOverlayComponent
{
/// <summary>
/// Required designer variable.
......
// ***********************************************************************
// Assembly : HZH_Controls
// Created : 2019-09-28
//
// ***********************************************************************
// <copyright file="ShadowComponent.cs">
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
// </copyright>
//
// Blog: https://www.cnblogs.com/bfyx
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
//
// If you use this code, please keep this note.
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing.Drawing2D;
namespace HZH_Controls.Controls
{
/// <summary>
/// Class ShadowComponent.
/// Implements the <see cref="System.ComponentModel.Component" />
/// Implements the <see cref="System.ComponentModel.IExtenderProvider" />
/// </summary>
/// <seealso cref="System.ComponentModel.Component" />
/// <seealso cref="System.ComponentModel.IExtenderProvider" />
[ProvideProperty("ShowShadow", typeof(Control))]
public class ShadowComponent : Component, IExtenderProvider
{
/// <summary>
/// The m control cache
/// </summary>
Dictionary<Control, bool> m_controlCache = new Dictionary<Control, bool>();
#region 构造函数 English:Constructor
/// <summary>
/// Initializes a new instance of the <see cref="ShadowComponent" /> class.
/// </summary>
public ShadowComponent()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ShadowComponent" /> class.
/// </summary>
/// <param name="container">The container.</param>
public ShadowComponent(IContainer container)
: this()
{
container.Add(this);
}
#endregion
/// <summary>
/// 指定此对象是否可以将其扩展程序属性提供给指定的对象。
/// </summary>
/// <param name="extendee">要接收扩展程序属性的 <see cref="T:System.Object" />。</param>
/// <returns>如果此对象可以扩展程序属性提供给指定对象,则为 true;否则为 false。</returns>
public bool CanExtend(object extendee)
{
if (extendee is Control && !(extendee is Form))
return true;
return false;
}
/// <summary>
/// Gets the show shadow.
/// </summary>
/// <param name="control">The control.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
[Browsable(true), Category("自定义属性"), Description("是否显示倒影"), DisplayName("ShowShadow"), Localizable(true)]
public bool GetShowShadow(Control control)
{
if (m_controlCache.ContainsKey(control))
return m_controlCache[control];
else
return false;
}
/// <summary>
/// Sets the show shadow.
/// </summary>
/// <param name="control">The control.</param>
/// <param name="isShowShadow">if set to <c>true</c> [is show shadow].</param>
public void SetShowShadow(Control control, bool isShowShadow)
{
control.ParentChanged += control_ParentChanged;
m_controlCache[control] = isShowShadow;
}
/// <summary>
/// Handles the ParentChanged 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>
void control_ParentChanged(object sender, EventArgs e)
{
Control control = sender as Control;
if (control.Parent != null && m_controlCache[control])
{
if (!lstPaintEventControl.Contains(control.Parent))
{
lstPaintEventControl.Add(control.Parent);
Type type = control.Parent.GetType();
System.Reflection.PropertyInfo pi = type.GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
pi.SetValue(control.Parent, true, null);
control.Parent.Paint += Parent_Paint;
}
}
}
/// <summary>
/// The LST paint event control
/// </summary>
List<Control> lstPaintEventControl = new List<Control>();
/// <summary>
/// The shadow height
/// </summary>
private float shadowHeight = 0.3f;
/// <summary>
/// Gets or sets the height of the shadow.
/// </summary>
/// <value>The height of the shadow.</value>
[Browsable(true), Category("自定义属性"), Description("倒影高度,0-1"), Localizable(true)]
public float ShadowHeight
{
get { return shadowHeight; }
set { shadowHeight = value; }
}
/// <summary>
/// The BLN loading
/// </summary>
bool blnLoading = false;
/// <summary>
/// Handles the Paint event of the Parent control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param>
void Parent_Paint(object sender, PaintEventArgs e)
{
if (blnLoading)
return;
if (shadowHeight > 0)
{
var control = sender as Control;
var lst = m_controlCache.Where(p => p.Key.Parent == control && p.Value);
if (lst != null && lst.Count() > 0)
{
blnLoading = true;
e.Graphics.SetGDIHigh();
foreach (var item in lst)
{
Control _control = item.Key;
using (Bitmap bit = new Bitmap(_control.Width, _control.Height))
{
_control.DrawToBitmap(bit, _control.ClientRectangle);
using (Bitmap bitNew = new Bitmap(bit.Width, (int)(bit.Height * shadowHeight)))
{
using (var g = Graphics.FromImage(bitNew))
{
g.DrawImage(bit, new RectangleF(0, 0, bitNew.Width, bitNew.Height), new RectangleF(0, bit.Height - bit.Height * shadowHeight, bit.Width, bit.Height * shadowHeight), GraphicsUnit.Pixel);
}
bitNew.RotateFlip(RotateFlipType.Rotate180FlipNone);
e.Graphics.DrawImage(bitNew, new Point(_control.Location.X, _control.Location.Y + _control.Height + 1));
Color bgColor = GetParentColor(_control);
LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(_control.Location.X, _control.Location.Y + _control.Height + 1, bitNew.Width, bitNew.Height), Color.FromArgb(50, bgColor), bgColor, 90f); //75f 表示角度
e.Graphics.FillRectangle(lgb, new Rectangle(new Point(_control.Location.X, _control.Location.Y + _control.Height + 1), bitNew.Size));
}
}
}
}
}
blnLoading = false;
}
/// <summary>
/// Gets the color of the parent.
/// </summary>
/// <param name="c">The c.</param>
/// <returns>Color.</returns>
private Color GetParentColor(Control c)
{
if (c.Parent.BackColor != Color.Transparent)
{
return c.Parent.BackColor;
}
return GetParentColor(c.Parent);
}
}
}
......@@ -70,11 +70,11 @@
<Compile Include="Controls\Charts\RadarChart\UCRadarChart.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\GraphicalOverlay\GraphicalOverlay.cs">
<Compile Include="Controls\GraphicalOverlay\GraphicalOverlayComponent.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\GraphicalOverlay\GraphicalOverlay.designer.cs">
<DependentUpon>GraphicalOverlay.cs</DependentUpon>
<Compile Include="Controls\GraphicalOverlay\GraphicalOverlayComponent.designer.cs">
<DependentUpon>GraphicalOverlayComponent.cs</DependentUpon>
</Compile>
<Compile Include="Controls\Navigation\CrumbNavigationClickEventArgs.cs" />
<Compile Include="Controls\Navigation\CrumbNavigationItem.cs" />
......@@ -88,6 +88,9 @@
<Compile Include="Controls\ScrollBar\UCHScrollbar.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\Shadow\ShadowComponent.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\Verification\VerificationAttribute.cs" />
<Compile Include="Controls\Verification\VerificationComponent.cs">
<SubType>Component</SubType>
......
......@@ -62,6 +62,7 @@ namespace Test
tnControl.Nodes.Add("控件水印");
tnControl.Nodes.Add("表单验证");
tnControl.Nodes.Add("图片采样控件");
tnControl.Nodes.Add("倒影");
this.tvMenu.Nodes.Add(tnControl);
TreeNode tnCharts = new TreeNode(" 图表");
......@@ -254,6 +255,9 @@ namespace Test
case "图片采样控件":
AddControl(new UC.UCTestSampling() );
break;
case "倒影":
AddControl(new UC.UCTestShadow());
break;
#endregion
#region 图表 English:Chart
......
......@@ -254,6 +254,12 @@
<Compile Include="UC\UCTestScrollbar.Designer.cs">
<DependentUpon>UCTestScrollbar.cs</DependentUpon>
</Compile>
<Compile Include="UC\UCTestShadow.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="UC\UCTestShadow.Designer.cs">
<DependentUpon>UCTestShadow.cs</DependentUpon>
</Compile>
<Compile Include="UC\UCTestSignalLamp.cs">
<SubType>UserControl</SubType>
</Compile>
......@@ -437,6 +443,9 @@
<EmbeddedResource Include="UC\UCTestScrollbar.resx">
<DependentUpon>UCTestScrollbar.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UC\UCTestShadow.resx">
<DependentUpon>UCTestShadow.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UC\UCTestSignalLamp.resx">
<DependentUpon>UCTestSignalLamp.cs</DependentUpon>
</EmbeddedResource>
......
......@@ -29,7 +29,7 @@
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.graphicalOverlay1 = new HZH_Controls.Controls.GraphicalOverlay(this.components);
this.graphicalOverlay1 = new HZH_Controls.Controls.GraphicalOverlayComponent(this.components);
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
......@@ -108,7 +108,7 @@
#endregion
private HZH_Controls.Controls.GraphicalOverlay graphicalOverlay1;
private HZH_Controls.Controls.GraphicalOverlayComponent graphicalOverlay1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
......
......@@ -35,33 +35,7 @@ namespace Test.UC
{
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(100, r.Next(0, 255), r.Next(0, 255), r.Next(0, 255))), item.Bounds);
}
//using (Bitmap bit = new Bitmap(button4.Width, button4.Height))
//{
// button4.DrawToBitmap(bit, button4.ClientRectangle);
// using (Bitmap bitNew = new Bitmap(bit.Width, bit.Height / 3))
// {
// using (var g = Graphics.FromImage(bitNew))
// {
// g.DrawImage(bit, new RectangleF(0, 0, bitNew.Width, bitNew.Height), new RectangleF(0, bit.Height - bit.Height / 3, bit.Width, bit.Height / 3), GraphicsUnit.Pixel);
// }
// bitNew.RotateFlip(RotateFlipType.Rotate180FlipNone);
// float flt = 200.0f / bitNew.Height;
// for (int i = 0; i < bitNew.Height; i++)
// {
// for (int j = 0; j < bitNew.Width; j++)
// {
// Color c = bitNew.GetPixel(j, i);
// int a = 200 - (int)(flt * i);
// if (a < 0)
// a = 0;
// bitNew.SetPixel(j, i, Color.FromArgb(a, c));
// }
// }
// e.Graphics.DrawImage(bitNew, new Point(button4.Location.X, button4.Location.Y + button4.Height + 1));
// }
//}
}
}
......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Test.UC
{
[ToolboxItem(false)]
public partial class UCTestShadow : UserControl
{
public UCTestShadow()
{
InitializeComponent();
}
}
}
<?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.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="ucBtnImg21.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADrwAAA68AZW8ckkAAABcSURBVFhH7dLBDYBACETRbcYCZGMnEg92YEt2Yxc2A0pC
DUs2+e8EXGYONADA1EzlyrGGaX9tlyfX8VxFKBEoEUzX07X7X+DO0ziEl4SHfLqa8GDHtuQIALNq7QPU
SkBGN/v52QAAAABJRU5ErkJggg==
</value>
</data>
<data name="ucBtnImg21.ImageFontIcons" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADrwAAA68AZW8ckkAAABcSURBVFhH7dLBDYBACETRbcYCZGMnEg92YEt2Yxc2A0pC
DUs2+e8EXGYONADA1EzlyrGGaX9tlyfX8VxFKBEoEUzX07X7X+DO0ziEl4SHfLqa8GDHtuQIALNq7QPU
SkBGN/v52QAAAABJRU5ErkJggg==
</value>
</data>
<metadata name="shadowComponent1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<data name="ucBtnImg20.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADrwAAA68AZW8ckkAAACmSURBVFhHYxgFo2AUjIJRMAoGPfgXYtz1L8TEF8olGQD1
r/0famQE5ZIG/oUYzf4favyfMgcYHfoXanyTZEfALQ81jIYKkQ1IdgQo2CGWG98Ea6YChpsXaCgBtQY3
APkariHUqJJiDI9Ko0NQKwgDuCOAmqFCZAFQsMNCEipEPECEhFEWVIhkQLblMADKAf/CTVWhXJIBJY4f
BaNgFIyCUUAHwMAAAEJ7pLguJwW2AAAAAElFTkSuQmCC
</value>
</data>
<data name="ucBtnImg20.ImageFontIcons" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADrwAAA68AZW8ckkAAACmSURBVFhHYxgFo2AUjIJRMAoGPfgXYtz1L8TEF8olGQD1
r/0famQE5ZIG/oUYzf4favyfMgcYHfoXanyTZEfALQ81jIYKkQ1IdgQo2CGWG98Ea6YChpsXaCgBtQY3
APkariHUqJJiDI9Ko0NQKwgDuCOAmqFCZAFQsMNCEipEPECEhFEWVIhkQLblMADKAf/CTVWhXJIBJY4f
BaNgFIyCUUAHwMAAAEJ7pLguJwW2AAAAAElFTkSuQmCC
</value>
</data>
<data name="ucBtnImg22.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADrwAAA68AZW8ckkAAABUSURBVFhH7c7hCYBQCEVhl2kBo02SdmjMtmgZCx+2glac
DwT1z70CAPgVN91zreerHjF51hrhNp+XqearDuEt4aG9QKDE41Ul8uzh2zLlCgBfIXID9bo/uLiREz0A
AAAASUVORK5CYII=
</value>
</data>
<data name="ucBtnImg22.ImageFontIcons" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADrwAAA68AZW8ckkAAABUSURBVFhH7c7hCYBQCEVhl2kBo02SdmjMtmgZCx+2glac
DwT1z70CAPgVN91zreerHjF51hrhNp+XqearDuEt4aG9QKDE41Ul8uzh2zLlCgBfIXID9bo/uLiREz0A
AAAASUVORK5CYII=
</value>
</data>
</root>
\ No newline at end of file
......@@ -80,7 +80,7 @@
this.textBox18 = new System.Windows.Forms.TextBox();
this.panel1 = new System.Windows.Forms.Panel();
this.verificationComponent1 = new HZH_Controls.Controls.VerificationComponent(this.components);
this.graphicalOverlay1 = new HZH_Controls.Controls.GraphicalOverlay(this.components);
this.graphicalOverlay1 = new HZH_Controls.Controls.GraphicalOverlayComponent(this.components);
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
......@@ -880,7 +880,7 @@
private HZH_Controls.Controls.UCCombox ucCombox2;
private System.Windows.Forms.ComboBox comboBox2;
private System.Windows.Forms.TextBox textBox2;
private HZH_Controls.Controls.GraphicalOverlay graphicalOverlay1;
private HZH_Controls.Controls.GraphicalOverlayComponent graphicalOverlay1;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox3;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!