官网

http://www.hzhcontrols.com

前提

入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。

GitHub:https://github.com/kwwwvagaa/NetWinformControl

码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git

如果觉得写的还行,请点个 star 支持一下吧

欢迎前来交流探讨: 企鹅群568015492 

idkey=6e08741ef16fe53bf0314c1c9e336c4f626047943a8b76bac062361bab6b4f8d">

目录

https://www.cnblogs.com/bfyx/p/11364884.html

准备工作

这个窗体继承子基类窗体FrmBase,如果你对FrmBase还不了解,请移步 (十七)c#Winform自定义控件-基类窗体 查看

开始

添加Form,命名FrmWithTitle,继承自FrmBase

代码较少,直接全部代码

 // 版权所有  黄正辉  交流群:568015492   QQ:623128629
// 文件名称:FrmWithTitle.cs
// 创建日期:2019-08-15 16:05:30
// 功能描述:FrmWithTitle
// 项目地址:https://gitee.com/kwwwvagaa/net_winform_custom_control
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
{
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(System.ComponentModel.Design.IDesigner))]
public partial class FrmWithTitle : FrmBase
{
[Description("窗体标题"), Category("自定义")]
public string Title
{
get
{
return lblTitle.Text;
}
set
{
lblTitle.Text = value;
}
}
private bool _isShowCloseBtn = 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 - , );
btnClose.BringToFront();
}
}
} public FrmWithTitle()
{
InitializeComponent();
} private void btnClose_MouseDown(object sender, MouseEventArgs e)
{
this.Close();
} private void FrmWithTitle_Shown(object sender, EventArgs e)
{
if (IsShowCloseBtn)
{
btnClose.Location = new Point(this.Width - btnClose.Width - , );
btnClose.BringToFront();
}
} private void btnClose_MouseDown_1(object sender, MouseEventArgs e)
{
this.Close();
} private void FrmWithTitle_VisibleChanged(object sender, EventArgs e)
{
}
}
}
 namespace HZH_Controls.Forms
{
partial class FrmWithTitle
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows Form Designer generated code /// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmWithTitle));
this.lblTitle = new System.Windows.Forms.Label();
this.ucSplitLine_H1 = new HZH_Controls.Controls.UCSplitLine_H();
this.btnClose = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// lblTitle
//
this.lblTitle.BackColor = System.Drawing.Color.Transparent;
this.lblTitle.Dock = System.Windows.Forms.DockStyle.Top;
this.lblTitle.Font = new System.Drawing.Font("微软雅黑", 17F);
this.lblTitle.Location = new System.Drawing.Point(, );
this.lblTitle.Name = "lblTitle";
this.lblTitle.Size = new System.Drawing.Size(, );
this.lblTitle.TabIndex = ;
this.lblTitle.Text = "标题";
this.lblTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// ucSplitLine_H1
//
this.ucSplitLine_H1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.ucSplitLine_H1.Dock = System.Windows.Forms.DockStyle.Top;
this.ucSplitLine_H1.Location = new System.Drawing.Point(, );
this.ucSplitLine_H1.Name = "ucSplitLine_H1";
this.ucSplitLine_H1.Size = new System.Drawing.Size(, );
this.ucSplitLine_H1.TabIndex = ;
this.ucSplitLine_H1.TabStop = false;
//
// btnClose
//
this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnClose.BackgroundImage = global::HZH_Controls.Properties.Resources.dialog_close;
this.btnClose.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.btnClose.Location = new System.Drawing.Point(, );
this.btnClose.MaximumSize = new System.Drawing.Size(, );
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(, );
this.btnClose.TabIndex = ;
this.btnClose.Visible = false;
this.btnClose.MouseDown += new System.Windows.Forms.MouseEventHandler(this.btnClose_MouseDown_1);
//
// FrmWithTitle
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.btnClose);
this.Controls.Add(this.ucSplitLine_H1);
this.Controls.Add(this.lblTitle);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.IsFullSize = false;
this.IsShowMaskDialog = true;
this.IsShowRegion = true;
this.Name = "FrmWithTitle";
this.Redraw = true;
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.Text = "FrmWithTitle";
this.Shown += new System.EventHandler(this.FrmWithTitle_Shown);
this.VisibleChanged += new System.EventHandler(this.FrmWithTitle_VisibleChanged);
this.ResumeLayout(false); } #endregion private System.Windows.Forms.Label lblTitle;
private Controls.UCSplitLine_H ucSplitLine_H1;
private System.Windows.Forms.Panel btnClose; }
}

用处及效果

最后的话

如果你喜欢的话,请到 https://gitee.com/kwwwvagaa/net_winform_custom_control 点个星 星吧

(二十四)c#Winform自定义控件-单标题窗体的更多相关文章

  1. (二十)c#Winform自定义控件-有后退的窗体

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  2. (二十七)c#Winform自定义控件-多输入窗体

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  3. Bootstrap<基础二十四> 缩略图

    Bootstrap 缩略图.大多数站点都需要在网格中布局图像.视频.文本等.Bootstrap 通过缩略图为此提供了一种简便的方式.使用 Bootstrap 创建缩略图的步骤如下: 在图像周围添加带有 ...

  4. (C/C++学习笔记) 二十四. 知识补充

    二十四. 知识补充 ● 子类调用父类构造函数 ※ 为什么子类要调用父类的构造函数? 因为子类继承父类,会继承到父类中的数据,所以子类在进行对象初始化时,先调用父类的构造函数,这就是子类的实例化过程. ...

  5. 学习笔记:CentOS7学习之二十四:expect-正则表达式-sed-cut的使用

    目录 学习笔记:CentOS7学习之二十四:expect-正则表达式-sed-cut的使用 24.1 expect实现无交互登录 24.1.1 安装和使用expect 24.2 正则表达式的使用 24 ...

  6. 二十四、Struts2中的UI标签

    二十四.Struts2中的UI标签 Struts2中UI标签的优势: 数据回显 页面布局和排版(Freemark),struts2提供了一些常用的排版(主题:xhtml默认 simple ajax) ...

  7. WCF技术剖析之二十四: ServiceDebugBehavior服务行为是如何实现异常的传播的?

    原文:WCF技术剖析之二十四: ServiceDebugBehavior服务行为是如何实现异常的传播的? 服务端只有抛出FaultException异常才能被正常地序列化成Fault消息,并实现向客户 ...

  8. VMware vSphere 服务器虚拟化之二十四 桌面虚拟化之手动池管理物理机

    VMware vSphere 服务器虚拟化之二十四 桌面虚拟化之手动池管理物理机 VMwareView手动池可以管理物理计算机 说明: 环境基于实验二十三 1.准备一台Windows 7的物理计算机名 ...

  9. Bootstrap入门(二十四)data属性

    Bootstrap入门(二十四)data属性 你可以仅仅通过 data 属性 API 就能使用所有的 Bootstrap 插件,无需写一行 JavaScript 代码.这是 Bootstrap 中的一 ...

随机推荐

  1. Mybatis__模糊查询

    在一个Web工程中,查询功能几乎都要用到姓名模糊查询,,虽然学号,工号等可以最准确最快的定位,但如果清楚信息到连学号,工号都一个数不差,应该也没必要去查询了. 故需要用到一下语句实现模糊查询: sel ...

  2. 关于爬虫平台的架构实现和框架的选型(二)--scrapy的内部实现以及实时爬虫的实现

    我们接着关于爬虫平台的架构实现和框架的选型(一)继续来讲爬虫框架的架构实现和狂阶的选型. 前面介绍了scrapy的基本操作,下面介绍下scrapy爬虫的内部实现架构如下图 1.Spiders(爬虫): ...

  3. bzoj3316 JC loves Mkk题解

    3316: JC loves Mkk Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 979  Solved: 316[Submit][Status][Di ...

  4. python菜鸟入门知识

    第二章 入门 2.1 输出 2.1.1print() 输出 print(12+21) print((12+21)*9) print(a) # 注意a不可以加引号 2.2变量 1.变量由字母,数字,下划 ...

  5. 开源一个好用的nodejs访问mysql类库

    一.背景问题 自nodejs诞生以来出现了一大批的web框架如express koa2 egg等等,前端可以不再依赖后端可以自己控制服务端的逻辑.原来的后端开发同学的阵地前端如今同样也写的风生水起,撸 ...

  6. 个人永久性免费-Excel催化剂功能第91波-地图数据挖宝之行政区域信息实时下载(含经纬度)

    移动互联网和O2O兴起的这十年时间里,由地图LBS功能衍生出一大堆的极高商业价值的数据及应用,地图相关的数据,也是数据分析过程中一个大宝藏,从此篇开始将带给大家一系列的地图相关的数据采集,满足数据分析 ...

  7. 百度OCR 文字识别 Android安全校验

    百度OCR接口使用总结: 之前总结一下关于百度OCR文字识别接口的使用步骤(Android版本 不带包名配置 安全性弱).这边博客主要介绍,百度OCR文字识别接口,官方推荐使用方式,授权文件(安全模式 ...

  8. 为什么选择 Spring 作为 Java 框架

    1. 概述 在本文中,我们将讨论 Spring 作为最流行的 Java 框架之一的主要价值体现. 最重要的是,我们将尝试理解 Spring 成为我们选择框架的原因.Spring 的详细信息及其组成部分 ...

  9. 基础篇-1.2Java世界的规章制度(下)

    1 Java运算符 Java世界中的运算其实就是数学运算,而运算符就是其中的媒介. 算术运算符 操作符 描述 + 加法,对符号两边的数值相加 - 减法,符号左边的数减去右边的数 * 乘法,符号两边的数 ...

  10. 访问腾讯云主机mysql的设置问题

    ---恢复内容开始--- 1.需要打开腾讯云主机的防火墙端口3306,具体实现可以在腾讯云控制台安全组中设置开放全部端口(安全组对应入站.出战规则): 2.将云主机mysql中mysql数据库user ...