C#窗体应用程序


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 WindowsFormsApplication1
{


    //所有的窗体的父类型为Form
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }


        private void Form2_Load(object sender, EventArgs e)//窗体的加载事件
        {
            //弹出消息
           // MessageBox.Show("hello!");
        }


        private void Form2_Click(object sender, EventArgs e)//窗体的点击事件
        {
            MessageBox.Show("click me!");
        }


        private void Form2_DragDrop(object sender, DragEventArgs e)
        {
            //拖放操作
            
        }


        private void Form2_DragOver(object sender, DragEventArgs e)
        {
           
        }


        private void Form2_DragEnter(object sender, DragEventArgs e)
        {
            MessageBox.Show("click me!");
        }


        //事件触发时,会给这个事件的响应方法串两个参数
        //sender
        //e 一般是EventArgs类型与EventArgs类型的子类型,
        //EventArgs 是事件参数类型,如果e的类型是EventArgs的子类型的话
        //那么我门可以获取到想要的一些信息
        //e .NET平台在事件触发时给方法提供的信息
        //sender 事件源,事件的触发者
        private void Form2_FormClosing(object sender, FormClosingEventArgs e)
        {
            ((Form2)sender).Opacity = 0.5;
            
            //弹出消息结果类型
            //MessageBoxButtons
           DialogResult dia= MessageBox.Show("关闭?"+((Form2)sender).Text,"温馨提示:",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
           if (dia==DialogResult.OK)
           {
               
           }
           else
           {
               e.Cancel = true;
               this.Opacity = 1;
           }
        }


        private void Form2_Deactivate(object sender, EventArgs e)
        {
            this.Text="飞机活!";
        }


        private void Form2_Activated(object sender, EventArgs e)
        {
            this.Text = "激活";
        }


        private void Form2_KeyDown(object sender, KeyEventArgs e)
        {
            //按下一个键
            //弹出按下的是什么键
            Keys k = e.KeyCode;
            if (k==Keys.A)
            {
               Point p= this.Location;
               p.X -= 5;
               this.Location = p;
            }
            if (k==Keys.D)
            {
                Point p = this.Location;
                p.X += 5;
                this.Location = p;
            }
            if (k==Keys.W)
            {
                 Point p = this.Location;
                p.Y-= 5;
                this.Location = p;
            }
            if (k==Keys.S)
            {
                 Point p = this.Location;
               p.Y += 5;
                this.Location = p;
            }
            
        }


        private void Form2_MouseEnter(object sender, EventArgs e)
        {
            MessageBox.Show("奥特曼不坑爹");
        }
    }
}


this.Close(); //关闭当前窗体   
            //如果当前窗体是这个程序的主窗体时,那程序中的其他正在运行的窗体也立即关闭

this.Hide(); //隐藏当前窗体

 Application.Exit();//结束应用程序,所有窗体都关闭

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值