2011-09-13 11 views
9

मैं उस स्थान पर contextmenustrip खोलने की कोशिश कर रहा हूं जहां मैंने माउस पर राइट-क्लिक किया था, लेकिन यह हमेशा स्क्रीन के ऊपरी बाईं ओर दिखाता है।एक संदर्भमेनस्ट्रिप की स्थिति निर्धारित नहीं कर सकता है?

private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) 
{ 
    if (e.Button == MouseButtons.Right) 
    { 
     contextMenuStrip1.Show(new Point(e.X,e.Y)); 
     doss.getdossier(connection.conn, Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value)); 
    } 
} 
+1

अपने मंच बहुत मदद मिलेगी। (चांदी की रोशनी, wpf, asp.net, winforms, आदि) –

उत्तर

11
if (e.Button == MouseButtons.Right) 
{ 
    contextMenuStrip1.Show(Cursor.Position); 
} 

कारण यह प्रकट नहीं हो रही है, क्योंकि आप मूल्यों के लिए e.X और e.Y उपयोग कर रहे हैं:

यहाँ कोड मैं प्रयोग किया जाता है। वे स्क्रीन पर वास्तविक स्थान नहीं हैं। वे डेटाग्रिड के भीतर माउस का स्थान हैं। तो कहें कि आपने पहली पंक्ति के पहले सेल पर क्लिक किया है, जो उस घटक के ऊपरी बाईं ओर होगा। e.X और e.Y घटक के भीतर माउस स्थान हैं।

2

संभालने आप Windows फार्म में हैं, इस प्रयास करें:

if (e.Button == MouseButtons.Right) 
{ 
    Control control = (Control) sender; 

    // Calculate the startPoint by using the PointToScreen 
    // method. 

    var startPoint = control.PointToScreen(new Point(e.X, e.Y)); 
    contextMenuStrip1.Show(startPoint); 
    ... 
    ... 
संबंधित मुद्दे

 संबंधित मुद्दे