FrmWithTitle.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // ***********************************************************************
  2. // Assembly : HZH_Controls
  3. // Created : 08-08-2019
  4. //
  5. // ***********************************************************************
  6. // <copyright file="FrmWithTitle.cs">
  7. // Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
  8. // </copyright>
  9. //
  10. // Blog: https://www.cnblogs.com/bfyx
  11. // GitHub:https://github.com/kwwwvagaa/NetWinformControl
  12. // gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
  13. //
  14. // If you use this code, please keep this note.
  15. // ***********************************************************************
  16. using System;
  17. using System.Collections.Generic;
  18. using System.ComponentModel;
  19. using System.Data;
  20. using System.Drawing;
  21. using System.Linq;
  22. using System.Text;
  23. using System.Windows.Forms;
  24. namespace HZH_Controls.Forms
  25. {
  26. /// <summary>
  27. /// Class FrmWithTitle.
  28. /// Implements the <see cref="HZH_Controls.Forms.FrmBase" />
  29. /// </summary>
  30. /// <seealso cref="HZH_Controls.Forms.FrmBase" />
  31. [Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(System.ComponentModel.Design.IDesigner))]
  32. public partial class FrmWithTitle : FrmBase
  33. {
  34. /// <summary>
  35. /// Gets or sets the title.
  36. /// </summary>
  37. /// <value>The title.</value>
  38. [Description("窗体标题"), Category("自定义")]
  39. public string Title
  40. {
  41. get
  42. {
  43. return lblTitle.Text;
  44. }
  45. set
  46. {
  47. lblTitle.Text = value;
  48. }
  49. }
  50. /// <summary>
  51. /// The is show close BTN
  52. /// </summary>
  53. private bool _isShowCloseBtn = false;
  54. /// <summary>
  55. /// Gets or sets a value indicating whether this instance is show close BTN.
  56. /// </summary>
  57. /// <value><c>true</c> if this instance is show close BTN; otherwise, <c>false</c>.</value>
  58. [Description("是否显示右上角关闭按钮"), Category("自定义")]
  59. public bool IsShowCloseBtn
  60. {
  61. get
  62. {
  63. return _isShowCloseBtn;
  64. }
  65. set
  66. {
  67. _isShowCloseBtn = value;
  68. btnClose.Visible = value;
  69. if (value)
  70. {
  71. btnClose.Location = new Point(this.Width - btnClose.Width - 10, 0);
  72. btnClose.BringToFront();
  73. }
  74. }
  75. }
  76. /// <summary>
  77. /// Initializes a new instance of the <see cref="FrmWithTitle" /> class.
  78. /// </summary>
  79. public FrmWithTitle()
  80. {
  81. InitializeComponent();
  82. InitFormMove(this.lblTitle);
  83. }
  84. /// <summary>
  85. /// Handles the Shown event of the FrmWithTitle control.
  86. /// </summary>
  87. /// <param name="sender">The source of the event.</param>
  88. /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
  89. private void FrmWithTitle_Shown(object sender, EventArgs e)
  90. {
  91. if (IsShowCloseBtn)
  92. {
  93. btnClose.Location = new Point(this.Width - btnClose.Width - 10, 0);
  94. btnClose.BringToFront();
  95. }
  96. }
  97. /// <summary>
  98. /// Handles the VisibleChanged event of the FrmWithTitle control.
  99. /// </summary>
  100. /// <param name="sender">The source of the event.</param>
  101. /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
  102. private void FrmWithTitle_VisibleChanged(object sender, EventArgs e)
  103. {
  104. }
  105. private void btnClose_Click(object sender, EventArgs e)
  106. {
  107. this.Close();
  108. }
  109. private void FrmWithTitle_SizeChanged(object sender, EventArgs e)
  110. {
  111. btnClose.Location = new Point(this.Width - btnClose.Width, btnClose.Location.Y);
  112. }
  113. }
  114. }