Drag Drop - KeyState

G

Guest

I want to be able to display a context menu when the user righthand drags an item into a textbox. It states in the documentation that the e.KeyState property will be set accordingly in the drop event. But when I check the value it is always 0, the value is set correctly for Shift, Ctrl, Alt. Am I doing something wrong?

private void textBox2_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}

private void textBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
textBox1.DoDragDrop("Test",DragDropEffects.Copy);
}

private void textBox2_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
label1.Text = e.KeyState.ToString();
}
 
C

ClayB [Syncfusion]

You can probably use the static Control.ModifierKeys property to deterine
what control keys are pressed.

George Shepherd's Windows Forms FAQ contains an entry entitled:

How can I tell if an ALT, Shift or CTL key is pressed without catching
an event?

Check it out at:
http://www.syncfusion.com/faq/winforms/search/656.asp

=============================================
Clay Burch, .NET MVP

Syncfusion, Inc.
visit http://www.syncfusion.com for .NET Essentials



Paul Ledger said:
I want to be able to display a context menu when the user righthand drags
an item into a textbox. It states in the documentation that the e.KeyState
property will be set accordingly in the drop event. But when I check the
value it is always 0, the value is set correctly for Shift, Ctrl, Alt. Am I
doing something wrong?
private void textBox2_DragEnter(object sender,
System.Windows.Forms.DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}

private void textBox1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
textBox1.DoDragDrop("Test",DragDropEffects.Copy);
}

private void textBox2_DragDrop(object sender,
System.Windows.Forms.DragEventArgs e)
 
S

Shakir Hussain

Try this

if(Control.MouseButtons == System.Windows.Forms.MouseButtons.Right)
{
//show context menu
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top