ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2019-09-08 10:38:13  阅读:253  来源: 互联网

标签:控件 自定义 c# label1 btnBack1 System Forms new Drawing


前提

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

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

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

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

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

目录

https://blog.csdn.net/kwwwvagaa/article/details/100586547

准备工作

其实我也不知道这个应该叫什么名字,暂且叫有后退的窗体吧,这个窗体继承子基类窗体FrmBase,如果你对FrmBase还不了解,请移步 (十七)c#Winform自定义控件-基类窗体 查看

开始

添加一个Form,命名FrmBack,继承自FrmBase

属性

复制代码

 1  private string _frmTitle = "自定义窗体";
 2         /// <summary>
 3         /// 窗体标题
 4         /// </summary>
 5         [Description("窗体标题"), Category("自定义")]
 6         public string FrmTitle
 7         {
 8             get { return _frmTitle; }
 9             set
10             {
11                 _frmTitle = value;
12                 btnBack1.BtnText = value;
13             }
14         }
15         [Description("帮助按钮点击事件"), Category("自定义")]
16         public event EventHandler BtnHelpClick;

复制代码

一点小事件

复制代码

 1  private void btnBack1_btnClick(object sender, EventArgs e)
 2         {
 3             this.Close();
 4         }
 5 
 6         private void label1_MouseDown(object sender, MouseEventArgs e)
 7         {
 8             if (BtnHelpClick != null)
 9                 BtnHelpClick(sender, e);
10         }

复制代码

完整代码

// 版权所有  黄正辉  交流群:568015492   QQ:623128629
// 文件名称:FrmTemp1.cs
// 创建日期:2019-08-15 16:04:48
// 功能描述:FrmTemp1
// 项目地址: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 FrmBack : FrmBase
    {
        private string _frmTitle = "自定义窗体";
        /// <summary>
        /// 窗体标题
        /// </summary>
        [Description("窗体标题"), Category("自定义")]
        public string FrmTitle
        {
            get { return _frmTitle; }
            set
            {
                _frmTitle = value;
                btnBack1.BtnText = value;
            }
        }
        [Description("帮助按钮点击事件"), Category("自定义")]
        public event EventHandler BtnHelpClick;

        public FrmBack()
        {
            InitializeComponent();
        }

        private void btnBack1_btnClick(object sender, EventArgs e)
        {
            this.Close();
        }

        private void label1_MouseDown(object sender, MouseEventArgs e)
        {
            if (BtnHelpClick != null)
                BtnHelpClick(sender, e);
        }
    }
}
namespace HZH_Controls.Forms
{
    partial class FrmBack
    {
        /// <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()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmBack));
            this.panTop = new System.Windows.Forms.Panel();
            this.label1 = new System.Windows.Forms.Label();
            this.btnBack1 = new HZH_Controls.Controls.UCBtnImg();
            this.imageList1 = new System.Windows.Forms.ImageList(this.components);
            this.ucSplitLine_H1 = new HZH_Controls.Controls.UCSplitLine_H();
            this.panTop.SuspendLayout();
            this.SuspendLayout();
            // 
            // panTop
            // 
            this.panTop.Controls.Add(this.label1);
            this.panTop.Controls.Add(this.btnBack1);
            this.panTop.Dock = System.Windows.Forms.DockStyle.Top;
            this.panTop.Location = new System.Drawing.Point(0, 0);
            this.panTop.Name = "panTop";
            this.panTop.Size = new System.Drawing.Size(679, 60);
            this.panTop.TabIndex = 2;
            // 
            // label1
            // 
            this.label1.BackColor = System.Drawing.Color.Transparent;
            this.label1.Dock = System.Windows.Forms.DockStyle.Right;
            this.label1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
            this.label1.Image = global::HZH_Controls.Properties.Resources.help;
            this.label1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.label1.Location = new System.Drawing.Point(612, 0);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(67, 60);
            this.label1.TabIndex = 1;
            this.label1.Text = "帮助";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.label1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.label1_MouseDown);
            // 
            // btnBack1
            // 
            this.btnBack1.BackColor = System.Drawing.Color.Transparent;
            this.btnBack1.BtnBackColor = System.Drawing.Color.Transparent;
            this.btnBack1.BtnFont = new System.Drawing.Font("微软雅黑", 17F);
            this.btnBack1.BtnForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(102)))), ((int)(((byte)(102)))), ((int)(((byte)(102)))));
            this.btnBack1.BtnText = "自定义按钮";
            this.btnBack1.ConerRadius = 5;
            this.btnBack1.Cursor = System.Windows.Forms.Cursors.Hand;
            this.btnBack1.Dock = System.Windows.Forms.DockStyle.Left;
            this.btnBack1.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
            this.btnBack1.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
            this.btnBack1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(102)))), ((int)(((byte)(102)))), ((int)(((byte)(102)))));
            this.btnBack1.Image = ((System.Drawing.Image)(resources.GetObject("btnBack1.Image")));
            this.btnBack1.IsRadius = true;
            this.btnBack1.IsShowRect = true;
            this.btnBack1.IsShowTips = false;
            this.btnBack1.Location = new System.Drawing.Point(0, 0);
            this.btnBack1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
            this.btnBack1.Name = "btnBack1";
            this.btnBack1.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
            this.btnBack1.RectWidth = 1;
            this.btnBack1.Size = new System.Drawing.Size(200, 60);
            this.btnBack1.TabIndex = 0;
            this.btnBack1.TabStop = false;
            this.btnBack1.TipsText = "";
            this.btnBack1.BtnClick += new System.EventHandler(this.btnBack1_btnClick);
            // 
            // imageList1
            // 
            this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
            this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
            this.imageList1.Images.SetKeyName(0, "help.png");
            // 
            // ucSplitLine_H1
            // 
            this.ucSplitLine_H1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(238)))), ((int)(((byte)(238)))), ((int)(((byte)(238)))));
            this.ucSplitLine_H1.Dock = System.Windows.Forms.DockStyle.Top;
            this.ucSplitLine_H1.Location = new System.Drawing.Point(0, 60);
            this.ucSplitLine_H1.MaximumSize = new System.Drawing.Size(0, 1);
            this.ucSplitLine_H1.Name = "ucSplitLine_H1";
            this.ucSplitLine_H1.Size = new System.Drawing.Size(679, 1);
            this.ucSplitLine_H1.TabIndex = 0;
            this.ucSplitLine_H1.TabStop = false;
            // 
            // FrmTemp1
            // 
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
            this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(247)))), ((int)(((byte)(247)))));
            this.ClientSize = new System.Drawing.Size(679, 477);
            this.Controls.Add(this.ucSplitLine_H1);
            this.Controls.Add(this.panTop);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "FrmTemp1";
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.Text = "FrmTemp1";
            this.panTop.ResumeLayout(false);
            this.ResumeLayout(false);

        }

        #endregion

        private Controls.UCBtnImg btnBack1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.ImageList imageList1;
        private Controls.UCSplitLine_H ucSplitLine_H1;
        private System.Windows.Forms.Panel panTop;
    }
}

设计效果

用处及效果

用处:这个看个人使用情况吧,你高兴的话就用这个窗体就可以了

最后的话

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

标签:控件,自定义,c#,label1,btnBack1,System,Forms,new,Drawing
来源: https://blog.csdn.net/kwwwvagaa/article/details/100620861

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有