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


  • 相关阅读:
    利用百度地图API实现百度地图坐标拾取
    newtonsoft.json的JObject里的JSON数据 动态
    监听微信返回按钮
    C# 如何理解如下泛型约束 class A<T>:where T:class{}
    微博数据库设计 _转
    新浪微博,腾讯微博mysql数据库主表猜想 __转
    Ferris教程学习笔记:js示例3.9 倒计时时钟
    Ferris教程学习笔记:js示例3.8 简易网页时钟
    Ferris教程学习笔记:js示例3.6 判断数字是否为两位数
    Ferris教程学习笔记:js示例3.5 页面加载后累加,自加1
  • 原文地址:https://www.cnblogs.com/bimgoo/p/2436469.html
Copyright © 2011-2022 走看看