1.在c#中能不能让一个窗体一装载就是模态化的啊???如果不能那有什么办法让窗体一装载就是模态化的。我想实现的功能是这个程序一运行就只能操作这个窗体上的内容而不能执行其他的操作。全屏不行 全屏的状态下有鼠标是不可以对其他的程序进行操作了 但是有键盘可以啊 你按Alt+F4就可以关掉这个程序了 我想的是只有你把这个窗体上的任务做完了才能做其他的事 还有就是怎么才能禁用掉键盘啊程序怎么写啊 是在窗体的装载KeyDown事件中编写吗?
2.可不可以用c#中的程序禁用掉某些按键的功能啊??比如一运行Alt+F4就不能用了。
2.可不可以用c#中的程序禁用掉某些按键的功能啊??比如一运行Alt+F4就不能用了。
using System.Collections.Generic;
using System.Windows.Forms;namespace ModuleForm
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace ModuleForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.ShowInTaskbar = false;
new Form2().ShowDialog();
}
}
}using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace ModuleForm
{
public partial class Form2 : Form
{
bool AlowClose = false;
public Form2()
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
} private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
if (AlowClose)
{
Application.Exit();
}
else
{
e.Cancel = true;
}
} private void button1_Click(object sender, EventArgs e)
{
AlowClose = true;
this.Close();
}
}
}完全能解决你的问题,记得给分哦,不清楚的可以联系Q:751749251
注:
e.Cancel=true;取消关闭
e.Cancel=false;关闭 2、使用KeyDown事件
先点窗体右键->属性->将KeyPrieview设置为true,然后在窗体的DeyDown事件中添加处理: 屏蔽Alt+F4
private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if ((e.KeyCode == Keys.F4)&&(e.Alt == true))
{
e.Handled = true;
}
}