// *********************************************************************** // Assembly : HZH_Controls // Created : 08-08-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.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace HZH_Controls.Forms { /// /// Class FrmWithTitle. /// Implements the /// /// [Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(System.ComponentModel.Design.IDesigner))] public partial class FrmWithTitle : FrmBase { /// /// Gets or sets the title. /// /// The title. [Description("窗体标题"), Category("自定义")] public string Title { get { return lblTitle.Text; } set { lblTitle.Text = value; } } /// /// The is show close BTN /// private bool _isShowCloseBtn = false; /// /// Gets or sets a value indicating whether this instance is show close BTN. /// /// true if this instance is show close BTN; otherwise, false. [Description("是否显示右上角关闭按钮"), Category("自定义")] public bool IsShowCloseBtn { get { return _isShowCloseBtn; } set { _isShowCloseBtn = value; btnClose.Visible = value; if (value) { btnClose.Location = new Point(this.Width - btnClose.Width - 10, 0); btnClose.BringToFront(); } } } /// /// Initializes a new instance of the class. /// public FrmWithTitle() { InitializeComponent(); InitFormMove(this.lblTitle); } /// /// Handles the Shown event of the FrmWithTitle control. /// /// The source of the event. /// The instance containing the event data. private void FrmWithTitle_Shown(object sender, EventArgs e) { if (IsShowCloseBtn) { btnClose.Location = new Point(this.Width - btnClose.Width - 10, 0); btnClose.BringToFront(); } } /// /// Handles the VisibleChanged event of the FrmWithTitle control. /// /// The source of the event. /// The instance containing the event data. private void FrmWithTitle_VisibleChanged(object sender, EventArgs e) { } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } private void FrmWithTitle_SizeChanged(object sender, EventArgs e) { btnClose.Location = new Point(this.Width - btnClose.Width, btnClose.Location.Y); } } }