zoukankan      html  css  js  c++  java
  • 创建无边框窗体并可调大小

    本例创建一个无边框窗体,并加入鼠标事件,通过操纵PictureBox调整窗体大小,程序运行如下图所示。

    20120408204116

    窗体程序如下所示。

    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Windows.Forms;
    namespace eg35_noborderApp
    {
    	public partial class MainForm : Form
    	{
    		static int frmLastWidth=0;
    		static int frmLastHeight=0;
    		static int frmWidth;
    		static int frmHeight;
    		static bool frmIsResizing=false;
    		System.Drawing.Rectangle frmRectangle=new System.Drawing.Rectangle();
    		public MainForm()
    		{
    			InitializeComponent();
    		}
    		
    		void Button1Click(object sender, EventArgs e)
    		{
    			this.Close();
    		}
    		
    		void PictureBox1MouseDown(object sender, MouseEventArgs e)
    		{
    			frmRectangle.Location=new System.Drawing.Point(this.Left,this.Top);
    			frmRectangle.Size=new System.Drawing.Size(frmWidth,frmHeight);
    			ControlPaint.DrawReversibleFrame(frmRectangle,Color.Empty,System.Windows.Forms.FrameStyle.Thick);
    		}
    		
    		void PictureBox1MouseUp(object sender, MouseEventArgs e)
    		{
    			frmIsResizing=false;
    			frmRectangle.Location=new System.Drawing.Point(this.Left,this.Top);
    			frmRectangle.Size=new System.Drawing.Size(frmWidth,frmHeight);
    			ControlPaint.DrawReversibleFrame(frmRectangle,Color.Empty,System.Windows.Forms.FrameStyle.Thick);
    			this.Width=frmWidth;
    			this.Height=frmHeight;
    		}
    		
    		void PictureBox1MouseMove(object sender, MouseEventArgs e)
    		{
    			if(e.Button==MouseButtons.Left)
    			{
    				int sizeageX=(MousePosition.X-this.Location.X);
    				int sizeageY=(MousePosition.Y-this.Location.Y);
    				if(sizeageX<120)
    					sizeageX=120;
    				if(sizeageY<81)
    					sizeageY=81;
    				frmWidth=sizeageX;
    				frmHeight=sizeageY;
    				if(frmLastWidth==0)
    					frmLastWidth=frmWidth;
    				if(frmLastHeight==0)
    					frmLastHeight=frmHeight;
    				if(frmIsResizing)
    				{
    					frmRectangle.Location=new System.Drawing.Point(this.Left,this.Top);
    					frmRectangle.Size=new System.Drawing.Size(frmLastWidth,frmLastHeight);
    				}
    				frmIsResizing=true;
    				ControlPaint.DrawReversibleFrame(frmRectangle,Color.Empty,System.Windows.Forms.FrameStyle.Thick);
    				frmLastWidth=frmWidth;
    				frmLastHeight=frmHeight;
    				frmRectangle.Location=new System.Drawing.Point(this.Left,this.Top);
    				frmRectangle.Size=new System.Drawing.Size(frmWidth,frmHeight);
    				ControlPaint.DrawReversibleFrame(frmRectangle,Color.Empty,System.Windows.Forms.FrameStyle.Thick);
    			}
    		}
    	}
    }
    作者:codee
    文章千古事,得失寸心知。


  • 相关阅读:
    HarmonyOS Java UI之AdaptiveBoxLayout布局示例
    【鸿蒙开发板试用报告】OneNet平台+开发板实时监控温湿度(一)
    安装了瑞友天翼4.0后出现了远程桌面无法连接的问题
    CISVC.EXE的资源占用
    Delphi如何在窗体标题栏添加按钮
    Delphi中捕捉窗体的最小化、最大化、还原消息
    打印机任务无法删除
    Delphi创建一个虚幻的层窗口(Win2000/XP)
    工资年结时提示“上年数据已经结转”
    Delphi中如何控制其他程序窗体上的窗口控件
  • 原文地址:https://www.cnblogs.com/bimgoo/p/2436469.html
Copyright © 2011-2022 走看看