WinForm一些常用方法(转)

转自:http://www.cnblogs.com/elzero/archive/2007/07/14/817939.html
//TextBox控件中只能输入数字和使用删除键
private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar) || e.KeyChar==8)
                e.Handled = false;
            else
                e.Handled = true;
        }
//关闭窗口时弹出对话框,确定是否真的退出
private void Form_Closing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("你确定要退出本系统吗?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1) == DialogResult.OK)
                e.Cancel = false;
            else
                e.Cancel = true;

        }
//窗口控制中的常用方法
1.窗口默认显示在屏幕中心位置
在Form的Property窗口中,将“StartPosition”属性设置为“CerterScreen”即可。
 
2.始终位于屏幕最前端
在Form的Property窗口中,将“TopMost”属性设置为“True”即可。
3.禁止窗口最大化
在Form的Property窗口中,将“MaximizeBox”属性设置为“False”即可。
4.禁止调整窗口大小
在Form的Property窗口中,将“FormBorderStyle”属性设置为“FixedDialog”
即可。
同时,如果将“FormBorderStyle”属性设置为“FixedToolWindow”,则将得到一个只有关闭按钮的窗口。

5.设置窗口是否MDI容器
IsMdiContainer=true/false;
当设置为true后,可以在主容器中添加子容器
Form Form = new Form();
Form.MdiParent = this;
nForm.Show();

转载于:https://www.cnblogs.com/ziyouyong/archive/2009/09/09/1562997.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值