// ***********************************************************************
// Assembly : HZH_Controls
// Created : 08-17-2019
//
// ***********************************************************************
//
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
//
//
// 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.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace HZH_Controls.Controls
{
///
/// Class UCPanelTitle.
/// Implements the
///
///
public partial class UCPanelTitle : UCControlBase, IContainerControl
{
///
/// The m int maximum height
///
private int m_intMaxHeight = 0;
///
/// The is can expand
///
private bool isCanExpand = true;
///
/// Gets or sets a value indicating whether this instance is can expand.
///
/// true if this instance is can expand; otherwise, false.
[Description("是否可折叠"), Category("自定义")]
public bool IsCanExpand
{
get { return isCanExpand; }
set
{
isCanExpand = value;
if (value)
{
lblTitle.Image = GetImg();
}
else
{
lblTitle.Image = null;
}
}
}
///
/// The is expand
///
private bool isExpand = false;
///
/// Gets or sets a value indicating whether this instance is expand.
///
/// true if this instance is expand; otherwise, false.
[Description("是否已折叠"), Category("自定义")]
public bool IsExpand
{
get { return isExpand; }
set
{
isExpand = value;
if (value)
{
m_intMaxHeight = this.Height;
this.Height = lblTitle.Height;
}
else
{
this.Height = m_intMaxHeight;
}
if (isCanExpand)
{
lblTitle.Image = GetImg();
}
else
{
lblTitle.Image = null;
}
}
}
///
/// Gets or sets the color of the border.
///
/// The color of the border.
[Description("边框颜色"), Category("自定义")]
public Color BorderColor
{
get { return this.RectColor; }
set
{
this.RectColor = value;
this.lblTitle.BackColor = value;
}
}
///
/// Gets or sets the title.
///
/// The title.
[Description("面板标题"), Category("自定义")]
public string Title
{
get { return lblTitle.Text; }
set { lblTitle.Text = value; }
}
///
/// 获取或设置控件的前景色。
///
/// The color of the fore.
///
///
///
public override Color ForeColor
{
get
{
return this.lblTitle.ForeColor;
}
set
{
this.lblTitle.ForeColor = value;
GetImg(true);
if (isCanExpand)
{
lblTitle.Image = GetImg();
}
else
{
lblTitle.Image = null;
}
}
}
///
/// Initializes a new instance of the class.
///
public UCPanelTitle()
{
InitializeComponent();
this.SizeChanged += UCPanelTitle_SizeChanged;
if (isCanExpand)
{
lblTitle.Image = GetImg();
}
else
{
lblTitle.Image = null;
}
}
///
/// The bit down
///
Bitmap bitDown = null;
///
/// The bit up
///
Bitmap bitUp = null;
///
/// Gets the img.
///
/// if set to true [BLN refresh].
/// Bitmap.
private Bitmap GetImg(bool blnRefresh = false)
{
if (isExpand)
{
if (bitDown == null || blnRefresh)
{
bitDown = new Bitmap(24, 24);
Graphics g = Graphics.FromImage(bitDown);
g.SetGDIHigh();
GraphicsPath path = new GraphicsPath();
path.AddLine(3, 5, 21, 5);
path.AddLine(21, 5, 12, 19);
path.AddLine(12, 19, 3, 5);
g.FillPath(new SolidBrush(ForeColor), path);
g.Dispose();
}
return bitDown;
}
else
{
if (bitUp == null || blnRefresh)
{
bitUp = new Bitmap(24, 24);
Graphics g = Graphics.FromImage(bitUp);
g.SetGDIHigh();
GraphicsPath path = new GraphicsPath();
path.AddLine(3, 19, 21, 19);
path.AddLine(21, 19, 12, 5);
path.AddLine(12, 5, 3, 19);
g.FillPath(new SolidBrush(ForeColor), path);
g.Dispose();
}
return bitUp;
}
}
///
/// Handles the MouseDown event of the lblTitle control.
///
/// The source of the event.
/// The instance containing the event data.
private void lblTitle_MouseDown(object sender, MouseEventArgs e)
{
if (isCanExpand)
{
IsExpand = !IsExpand;
}
}
///
/// Handles the SizeChanged event of the UCPanelTitle control.
///
/// The source of the event.
/// The instance containing the event data.
private void UCPanelTitle_SizeChanged(object sender, EventArgs e)
{
if (this.Height != lblTitle.Height)
{
m_intMaxHeight = this.Height;
}
lblTitle.Width = this.Width;
}
}
}