|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Oct 2008
Messaggi: 39
|
[C#] Click con Destro + Sinistro
Come faccio a dire al sistema che è stato fatto click sia col tasto destro che col sinistro? (Stile prato fiorito insomma...)
Ho provato con Codice:
void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button==MouseButtons.Right)
{
if (e.Button == MouseButtons.Left)
{
//Premuti entrambi i tasti
__________________
Mala Rupta! |
|
|
|
|
|
#2 | |
|
Senior Member
Iscritto dal: Dec 2004
Messaggi: 3210
|
Quote:
Io la farei così : 1. Creo 2 var bool a livello di Form : Codice:
public partial class Form1 : Form
{
private bool DX = false;
private bool SN = false;
Codice:
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
SN = true;
}
if (e.Button == MouseButtons.Right)
{
DX = true;
}
if (SN == true && DX == true)
{
//Codice da eseguire...
this.BackColor = Color.Green;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
SN = false;
}
if (e.Button == MouseButtons.Right)
{
DX = false;
}
this.BackColor = SystemColors.Control;
}
|
|
|
|
|
|
|
#3 |
|
Member
Iscritto dal: Oct 2008
Messaggi: 39
|
e a quel punto come faccio a distinguere il click destro dal sinistro?
Ho tre situazioni: Click con entrambi Click con il destro Click col sinistro Tu onmouseUp riporti tutte e due le situazioni a false... Lì magari devo controllare che se erano già a false devo fare quello del tasto opposto... Uno dei due deve essere comunque a true dato che sennò non partiva l'evento.
__________________
Mala Rupta! |
|
|
|
|
|
#4 | |
|
Senior Member
Iscritto dal: Dec 2004
Messaggi: 3210
|
Quote:
Codice:
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
SN = true;
}
if (e.Button == MouseButtons.Right)
{
DX = true;
}
if (SN == true && DX == true)
{
//Codice da eseguire...
this.BackColor = Color.Green;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
SN = false;
}
if (e.Button == MouseButtons.Right)
{
DX = false;
}
}
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && DX==false)
{
//Codice per Click Sinistro:
this.BackColor = Color.Yellow;
}
if (e.Button == MouseButtons.Right && SN==false)
{
//Codice per Click Destro:
this.BackColor = Color.Red;
}
}
|
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 07:56.



















