Files
lserp_cs_6.0/插件库/Lskj.Control/ImageLibrary/ImageCarouselExtDesigner.cs
T
cyf ab56a9bcf7 基线 SVN r240
SVN-Revision: r240
2025-02-06 06:46:06 +00:00

66 lines
2.6 KiB
C#

using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace Lskj.Control.ImageLibrary
{
/// <summary>
/// ImageCarousel控件设计模式行为
/// </summary>
[Description("ImageCarousel控件设计模式行为")]
public class ImageCarouselExtDesigner : ControlDesigner
{
protected override void OnPaintAdornments(PaintEventArgs pe)
{
base.OnPaintAdornments(pe);
this.DrawTipText(pe.Graphics);
this.DrawBorder(pe.Graphics);
}
/// <summary>
/// 绘制虚线边框
/// </summary>
/// <param name="graphics"></param>
private void DrawBorder(Graphics graphics)
{
ImageCarouselExt control = (ImageCarouselExt)this.Control;
Rectangle clientRectangle = control.ClientRectangle;
Pen pen = new Pen((double)control.BackColor.GetBrightness() >= 0.5 ? ControlPaint.Dark(control.BackColor) : ControlPaint.Light(control.BackColor));
pen.DashStyle = DashStyle.Dash;
--clientRectangle.Width;
--clientRectangle.Height;
graphics.DrawRectangle(pen, clientRectangle);
#region
RectangleF rectf = control.GetDisplayRectangle();
pen.DashStyle = DashStyle.Solid;
pen.Color = Color.OliveDrab;
graphics.DrawRectangle(pen, rectf.X, rectf.Y, rectf.Width, rectf.Height);
#endregion
pen.Dispose();
}
/// <summary>
/// 绘制提示文本
/// </summary>
/// <param name="graphics"></param>
private void DrawTipText(Graphics graphics)
{
ImageCarouselExt _control = (ImageCarouselExt)this.Control;
System.Windows.Forms.Control control = this.Control;
if (_control.Images.Count < 1)
{
string text = "请添加图片";
SizeF text_size = graphics.MeasureString(text, _control.Font);
SolidBrush text_sb = new SolidBrush((double)control.BackColor.GetBrightness() >= 0.5 ? ControlPaint.Dark(control.BackColor) : ControlPaint.Light(control.BackColor));
graphics.DrawString(text, _control.Font, text_sb, new RectangleF(control.ClientRectangle.X + (control.ClientRectangle.Width - text_size.Width) / 2f, control.ClientRectangle.Y + (control.ClientRectangle.Height - text_size.Height) / 2f, text_size.Width, text_size.Height));
text_sb.Dispose();
}
}
}
}