老D

我是一个粗人
  博客园  :: 首页  :: 新随笔  :: 管理

C# 中的一些常用方法

Posted on 2007-07-14 11:11  老D  阅读(558)  评论(0编辑  收藏  举报

//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();