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
{
///
/// The m LST freeze control
///
static Dictionary m_lstFreezeControl = new Dictionary();
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);
}
}
///
/// Handles the Disposed event of the control control.
///
/// The source of the event.
/// The instance containing the event data.
static void control_Disposed(object sender, EventArgs e)
{
try
{
if (m_lstFreezeControl.ContainsKey((Control)sender))
m_lstFreezeControl.Remove((Control)sender);
}
catch { }
}
///
/// 设置GDI高质量模式抗锯齿
///
/// The g.
public static void SetGDIHigh(this Graphics g)
{
g.SmoothingMode = SmoothingMode.AntiAlias; //使绘图质量最高,即消除锯齿
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.CompositingQuality = CompositingQuality.HighQuality;
}
///
/// 根据矩形和圆得到一个圆角矩形Path
///
/// The rect.
/// The corner radius.
/// GraphicsPath.
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;
}
}
}