简单问题,马上结贴 请问一下,有什么简单的方法判断,当我点击鼠标左键时,是否同时按住了Ctrl键,要在OnMouseDown事件中判断,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 做一个全局变量 private bool m_Ctrl = false; private void Form1_Load(object sender, EventArgs e) { this.KeyPreview = true; } private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.ControlKey) m_Ctrl = true; } private void Form1_KeyUp(object sender, KeyEventArgs e) { m_Ctrl = false; } private void Form1_MouseDown(object sender, MouseEventArgs e) { if (m_Ctrl == true) { this.Text = e.Button.ToString(); } }或则使用API GetKeyboardState也可以 private void Form1_MouseDown(object sender, MouseEventArgs e) { if (Control.ModifierKeys== Keys.Control) { MessageBox.Show("你按了ctrl"); } } private void Form1_MouseDown(object sender, MouseEventArgs e) { if (Control.ModifierKeys== Keys.Control&&e.Button== MouseButtons.Left) { MessageBox.Show("你按了ctrl+鼠标左键"); } } 我现在把这个事件写在了一个类中,所有好象Control.ModifierKeys== Keys.Control这一步不行啊,有没有其他的好办法啊,谢谢了 忘说了,这个类没有继承Form类 没有继承form哪里来的OnMouseDown?你可以给类引用System.Windows.Form.dll [DllImport("USER32.dll")] static extern short GetKeyState(int nVirtKey); const int VK_CONTROL = 0x11; private void frmMain_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && ((GetKeyState(VK_CONTROL) & 0x8000)!=0)) { //你同时按下了Ctrl加左键 MessageBox.Show("CTRL+Left"); } } 偏移的问题 求救。。。数据库连接池使用 推荐一款Sql编辑器。 继承ArrayList类,实现 this[int index]时的一个问题 顶者有分 winform里怎么从窗体1传值给窗体2里的textbox并显示出来? ~~如何用Dropdownlist控件对DataGird进行数据筛选?也就是重新有条件加载DataGrid~~ 关于wpf的scrollviewer以及图像缩放的问题 求PetShop中文版! 主从关系 C# 如何实现将文件夹分卷压缩 如何通过算法来提取网页当中的正文? 知道的指导一下
private bool m_Ctrl = false;
private void Form1_Load(object sender, EventArgs e)
{
this.KeyPreview = true;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.ControlKey) m_Ctrl = true;
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
m_Ctrl = false;
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (m_Ctrl == true)
{
this.Text = e.Button.ToString();
}
}
或则使用API GetKeyboardState也可以
{
if (Control.ModifierKeys== Keys.Control)
{
MessageBox.Show("你按了ctrl");
}
}
{
if (Control.ModifierKeys== Keys.Control&&e.Button== MouseButtons.Left)
{
MessageBox.Show("你按了ctrl+鼠标左键");
}
}
忘说了,这个类没有继承Form类
static extern short GetKeyState(int nVirtKey);
const int VK_CONTROL = 0x11; private void frmMain_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && ((GetKeyState(VK_CONTROL) & 0x8000)!=0))
{
//你同时按下了Ctrl加左键
MessageBox.Show("CTRL+Left"); }
}