自定义窗体的最大化,最小化,关闭功能

namespace 自定义窗体的最大化_最小化和关闭按钮
{
    partial class Form1
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.pictureBox_Close = new System.Windows.Forms.PictureBox();
            this.panel_Title = new System.Windows.Forms.Panel();
            this.pictureBox_Min = new System.Windows.Forms.PictureBox();
            this.pictureBox_Max = new System.Windows.Forms.PictureBox();
            this.panel_ALL = new System.Windows.Forms.Panel();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox_Close)).BeginInit();
            this.panel_Title.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox_Min)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox_Max)).BeginInit();
            this.SuspendLayout();
            //
            // pictureBox_Close
            //
            this.pictureBox_Close.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.pictureBox_Close.Location = new System.Drawing.Point(269, 11);
            this.pictureBox_Close.Name = "pictureBox_Close";
            this.pictureBox_Close.Size = new System.Drawing.Size(20, 20);
            this.pictureBox_Close.TabIndex = 3;
            this.pictureBox_Close.TabStop = false;
            this.pictureBox_Close.Tag = "2";
            this.pictureBox_Close.MouseLeave += new System.EventHandler(this.pictureBox_Close_MouseLeave);
            this.pictureBox_Close.Click += new System.EventHandler(this.pictureBox_Close_Click);
            this.pictureBox_Close.MouseEnter += new System.EventHandler(this.pictureBox_Close_MouseEnter);
            //
            // panel_Title
            //
            this.panel_Title.Controls.Add(this.pictureBox_Close);
            this.panel_Title.Controls.Add(this.pictureBox_Min);
            this.panel_Title.Controls.Add(this.pictureBox_Max);
            this.panel_Title.Dock = System.Windows.Forms.DockStyle.Top;
            this.panel_Title.Location = new System.Drawing.Point(0, 0);
            this.panel_Title.Name = "panel_Title";
            this.panel_Title.Size = new System.Drawing.Size(298, 37);
            this.panel_Title.TabIndex = 2;
            //
            // pictureBox_Min
            //
            this.pictureBox_Min.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.pictureBox_Min.Location = new System.Drawing.Point(217, 11);
            this.pictureBox_Min.Name = "pictureBox_Min";
            this.pictureBox_Min.Size = new System.Drawing.Size(20, 20);
            this.pictureBox_Min.TabIndex = 2;
            this.pictureBox_Min.TabStop = false;
            this.pictureBox_Min.Tag = "0";
            this.pictureBox_Min.MouseLeave += new System.EventHandler(this.pictureBox_Close_MouseLeave);
            this.pictureBox_Min.Click += new System.EventHandler(this.pictureBox_Close_Click);
            this.pictureBox_Min.MouseEnter += new System.EventHandler(this.pictureBox_Close_MouseEnter);
            //
            // pictureBox_Max
            //
            this.pictureBox_Max.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.pictureBox_Max.Location = new System.Drawing.Point(243, 11);
            this.pictureBox_Max.Name = "pictureBox_Max";
            this.pictureBox_Max.Size = new System.Drawing.Size(20, 20);
            this.pictureBox_Max.TabIndex = 0;
            this.pictureBox_Max.TabStop = false;
            this.pictureBox_Max.Tag = "1";
            this.pictureBox_Max.MouseLeave += new System.EventHandler(this.pictureBox_Close_MouseLeave);
            this.pictureBox_Max.Click += new System.EventHandler(this.pictureBox_Close_Click);
            this.pictureBox_Max.MouseEnter += new System.EventHandler(this.pictureBox_Close_MouseEnter);
            //
            // panel_ALL
            //
            this.panel_ALL.Dock = System.Windows.Forms.DockStyle.Fill;
            this.panel_ALL.Location = new System.Drawing.Point(0, 37);
            this.panel_ALL.Name = "panel_ALL";
            this.panel_ALL.Size = new System.Drawing.Size(298, 160);
            this.panel_ALL.TabIndex = 3;
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(298, 197);
            this.Controls.Add(this.panel_ALL);
            this.Controls.Add(this.panel_Title);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox_Close)).EndInit();
            this.panel_Title.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox_Min)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox_Max)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.PictureBox pictureBox_Close;
        private System.Windows.Forms.Panel panel_Title;
        private System.Windows.Forms.PictureBox pictureBox_Min;
        private System.Windows.Forms.PictureBox pictureBox_Max;
        private System.Windows.Forms.Panel panel_ALL;
    }
}

Designer.cs

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 自定义窗体的最大化_最小化和关闭按钮
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Width = Properties.Resources.登录界面标题.Width;
            this.Height = Properties.Resources.登录界面标题.Height + Properties.Resources.登录界面下面.Height;
            panel_Title.BackgroundImage = Properties.Resources.登录界面标题;
            panel_ALL.BackgroundImage = Properties.Resources.登录界面下面;
            pictureBox_Min.Image = null;
            pictureBox_Min.Image = Properties.Resources.最小化按钮;
            pictureBox_Max.Image = null;
            pictureBox_Max.Image = Properties.Resources.最大化按钮;
            pictureBox_Close.Image = null;
            pictureBox_Close.Image = Properties.Resources.关闭按钮;
        }

        #region  设置窗体的最大化、最小化和关闭按钮的单击事件
        /// <summary>
        /// 设置窗体的最大化、最小化和关闭按钮的单击事件
        /// </summary>
        /// <param Frm_Tem="Form">窗体</param>
        /// <param n="int">标识</param>
        public void FrmClickMeans(Form Frm_Tem, int n)
        {
            switch (n)
            {
                case 0:
                    Frm_Tem.WindowState = FormWindowState.Minimized;
                    break;
                case 1:
                    {
                        if (Frm_Tem.WindowState == FormWindowState.Maximized)
                            Frm_Tem.WindowState = FormWindowState.Normal;
                        else
                            Frm_Tem.WindowState = FormWindowState.Maximized;
                        break;
                    }
                case 2:
                    Frm_Tem.Close();
                    break;
            }
        }
        #endregion

        #region  控制图片的切换状态
        /// <summary>
        /// 控制图片的切换状态
        /// </summary>
        /// <param Frm_Tem="Form">要改变图片的对象</param>
        /// <param n="int">标识</param>
        /// <param ns="int">移出移入标识</param>
        public static PictureBox Tem_PictB = new PictureBox();
        public void ImageSwitch(object sender, int n, int ns)
        {
            Tem_PictB = (PictureBox)sender;

            switch (n)
            {
                case 0:
                    {
                        Tem_PictB.Image = null;
                        if (ns == 0)
                            Tem_PictB.Image = Properties.Resources.最小化变色;
                        if (ns == 1)
                            Tem_PictB.Image = Properties.Resources.最小化按钮;
                        break;
                    }
                case 1:
                    {
                        Tem_PictB.Image = null;
                        if (ns == 0)
                            Tem_PictB.Image = Properties.Resources.最大化变色;
                        if (ns == 1)
                            Tem_PictB.Image = Properties.Resources.最大化按钮;
                        break;
                    }
                case 2:
                    {
                        Tem_PictB.Image = null;
                        if (ns == 0)
                            Tem_PictB.Image = Properties.Resources.关闭变色;
                        if (ns == 1)
                            Tem_PictB.Image = Properties.Resources.关闭按钮;
                        break;
                    }
            }
        }
        #endregion

        private void pictureBox_Close_Click(object sender, EventArgs e)
        {
            FrmClickMeans(this, Convert.ToInt16(((PictureBox)sender).Tag.ToString()));
        }

        private void pictureBox_Close_MouseEnter(object sender, EventArgs e)
        {
            ImageSwitch(sender, Convert.ToInt16(((PictureBox)sender).Tag.ToString()), 0);
        }

        private void pictureBox_Close_MouseLeave(object sender, EventArgs e)
        {
            ImageSwitch(sender, Convert.ToInt16(((PictureBox)sender).Tag.ToString()), 1);
        }

    }
}

cs

时间: 2024-08-02 02:51:14

自定义窗体的最大化,最小化,关闭功能的相关文章

C#程序实现窗体的最大化/最小化

C#代码实现: private void button1_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Maximized; this.notifyIcon1.Visible = true; } private void button2_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; t

【转】ubuntu 12.04 LTS将关闭最大化最小化移动到右上角

原文网址:http://www.4byte.cn/learning/114801.html ubuntu 12.04 LTS将关闭最大化最小化移动到右上角 还是按下“ALT +F2”组合键,输入gconf-editor并回车运行. www.4byte.cn (如果此时没有运行,则说明你需要安装gconf-editor,打开终端输入sudo apt-get install gconf-editor回车运行,等待安装完毕就行了.) 这时会打开一个配置编辑器,在左侧一次展开“apps/metacity

Q窗口操作函数(窗口最大化,全屏,隐藏最大化最小化按钮)

//Qt主窗口没有最小化,最大化按钮且最大化显示  int main(int argc, char *argv[]) { QApplication a(argc, argv); TestQtForWinCE w; w.setWindowFlags(w.windowFlags()& ~Qt::WindowMaximizeButtonHint& ~Qt::WindowMinimizeButtonHint); w.showMaximized(); return a.exec(); } 这里的&q

delphi 窗体最大化 最小化

procedure TForm1.SpeedButton2Click(Sender: TObject); begin sendmessage(form1.WindowHandle,WM_SYSCOMMAND,SC_ICON,0);//窗体最小化  任务栏中 end;   procedure TForm1.SpeedButton2Click(Sender: TObject); begin form1.WindowState :=  wsMaximized;//窗体最大化 end;   proced

WPF 最大化最小化窗口

public static void FullOrMin(this Window window)        {            //如果是全屏,则最小化            if (window.WindowState == WindowState.Maximized)            {                window.Topmost = false;                window.WindowState = WindowState.Normal; 

Unity中的多屏以及最大化最小化

一 多屏 首先是多屏,我的需求是只显示在第二块屏幕上,而且第一块屏幕上的操作不能影响到第二块屏幕. 如果连了另一块屏幕,在打开exe的时候的配置框可以选择显示在哪块屏幕上 如果选择了第二块,不删除Data文件夹,回到Unity取消勾选Display Resolution Diag,下次打开直接跳到第二快屏幕上. 二 解决第二块屏幕的后台 但是如果仅仅这样,会遇到一个不大大小的问题-在主屏幕点击一下,第二块屏幕的显示就跑到后台去了. 我是想让第二块屏幕,不受第一块屏幕的影响而跑到后台. 经过尝试,

WinForm窗体的托盘最小化实现代码

//窗体最小化时候将窗体隐藏掉,同时让托盘控件显示 private void Form1_SizeChanged(object sender, EventArgs e) { if(this.WindowState == FormWindowState.Minimized) { this.Hide(); this.notifyIcon1.Visible = true; } } private void notifyIcon1_MouseDoubleClick(object sender, Mous

electron 的窗口设置最大化 最小化

/** * Created by Administrator on 2016/11/23. * 页面对窗口的一些操作封装,用于渲染进程 */ "use strict"; const Common = require('../../window/common.js'); const { ipcRenderer, remote } = require('electron'); const WinReg = require('winreg'); const RUN_LOCATION = '\

自定义最大化 最小化 关闭按钮

实现效果:  知识运用: 资源文件 将图片存入资源文件 资源管理器-Properties-Resources.resx文件 读取资源文件中的图片 Properties命名空间下的Resoources资源类 pictureBox.Image=Properties.Resources.max; WindowState属性 用于获取或设置窗体的状体 public FormWindowstate WindowsState{ get;set; } 参数为FormWindowState枚举值之一 Maxim