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
    文章千古事,得失寸心知。


  • 相关阅读:
    URL中传参带有%2F等特殊字符
    js根据对象数组中某一属性值,合并相同项,并对某一属性累加处理
    windows传输文件到linux
    npm 切换源
    linux下安装java
    PowerShell:因为在此系统上禁止运行脚本,解决方法
    wget: 未找到命令
    发货通知单禁止手工新增
    固定提前期
    容差码
  • 原文地址:https://www.cnblogs.com/bimgoo/p/2436469.html
Copyright © 2011-2022 走看看