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


  • 相关阅读:
    javascript js date ios手机浏览器出现 NAN的问题解决方法
    DWG TrueView 2022
    FloatingActionButton(悬浮按钮)使用学习<一>
    Android多线程编程<一>Android中启动子线程的方法
    Android多线程编程<二>Handler异步消息处理机制之Message
    Java:类的构造函数
    Java:类与对象概念
    APP免邀请码安装
    .NET4安装总进度一直不动的解决办法
    bitmap缩放时抗锯齿
  • 原文地址:https://www.cnblogs.com/bimgoo/p/2436469.html
Copyright © 2011-2022 走看看