void lbl_MouseEnter(object sender, EventArgs e) { label1.Text = "mouse has entered label number " + ID.ToString(); }
void lbl_MouseEnter(object sender, EventArgs e) { label1.Text = "mouse has entered label number " + ((Label)sender).Name; }
monControle.Mo
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionpublic class RectangleAvecNom { public Rectangle Rect; public RectangleAvecNom(string coord1,string coord2) { string[] c1 = coord1.Split(';'); string[] c2 = coord2.Split(';'); Rect = new Rectangle(Convert.ToInt32(c1[0]), Convert.ToInt32(c1[1]), Convert.ToInt32(c2[0]), Convert.ToInt32(c2[1])); } } public class TaClass : Form { private List<RectangleAvecNom> RAN=new List<RectangleAvecNom>(); string affiche = null; Point affichePoint; TextBox textBox1 = new TextBox(); TextBox textBox2 = new TextBox(); Button button1=new Button(); public TaClass () { this.textBox1.Location = new System.Drawing.Point(3, 12); this.textBox1.Size = new System.Drawing.Size(116, 20); this.textBox2.Location = new System.Drawing.Point(125, 12); this.textBox2.Size = new System.Drawing.Size(116, 20); this.button1.Location = new System.Drawing.Point(248, 14); this.button1.Size = new System.Drawing.Size(30, 18); button1.Click+=new EventHandler(button1_Click); this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); this.MouseMove += new MouseEventHandler(BougeSouris); } void BougeSouris(object sender, MouseEventArgs e) { affiche = null; for(int i=0;i<RAN.Count;i++) if (e.X > RAN[i].Rect.X && e.X < RAN[i].Rect.X + RAN[i].Rect.Width && e.Y > RAN[i].Rect.Y && e.Y < RAN[i].Rect.Y + RAN[i].Rect.Height) { affiche = "Rect" + i.ToString(); affichePoint = e.Location; } this.Invalidate(); } protected override void OnPaint(PaintEventArgs e) { try { Bitmap bmp = new Bitmap(e.ClipRectangle.Width, e.ClipRectangle.Height); Graphics gr = Graphics.FromImage(bmp); gr.FillRectangle(new SolidBrush(Color.White), e.ClipRectangle); foreach (RectangleAvecNom r in RAN) { gr.DrawRectangle(new Pen(Color.Black), r.Rect); } if (affiche != null) gr.DrawString(affiche, this.Font, new SolidBrush(Color.Red), affichePoint); e.Graphics.DrawImage(bmp, e.ClipRectangle); gr.Dispose(); } catch { } } private void button1_Click(object sender, EventArgs e) { RAN.Add(new RectangleAvecNom(textBox1.Text, textBox2.Text)); this.Invalidate(); } }
public partial class Form1 : Form { int Xpos, Ypos = 0; int ID = 0; public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { Xpos = RectX(Convert.ToInt32(numericUpDownColumn.Value)); Ypos = RectY(Convert.ToInt32(numericUpDownRow.Value)); Label lbl = new Label(); lbl.Name = "ID_" + ID.ToString(); lbl.Top = Ypos; lbl.Left = Xpos; lbl.BackColor = Color.Black; lbl.Size = new System.Drawing.Size(10, 10); lbl.MouseEnter += lbl_MouseEnter; this.Controls.Add(lbl); } private int RectX(int OriginalXValue) { int offset = 0; if (OriginalXValue <5) offset 0; else if ((OriginalXValue > 5) && (OriginalXValue <10)) offset 3; else if ((OriginalXValue > 10) && (OriginalXValue <15)) offset 6; else if ((OriginalXValue > 15) && (OriginalXValue <20)) offset 9; else if ((OriginalXValue > 20) && (OriginalXValue <25)) offset 12; else if ((OriginalXValue > 25) && (OriginalXValue <30)) offset 15; else if ((OriginalXValue > 30) && (OriginalXValue <35)) offset 18; else if ((OriginalXValue > 35) && (OriginalXValue <40)) offset 21; else if ((OriginalXValue > 40) && (OriginalXValue <45)) offset 24; else if ((OriginalXValue > 45) && (OriginalXValue <50)) offset 27; else if ((OriginalXValue > 50) && (OriginalXValue <55)) offset 30; else if ((OriginalXValue > 55) && (OriginalXValue <60)) offset 33; return 75 + offset + (OriginalXValue * 13); } private int RectY(int OriginalYValue) { return 102 + (OriginalYValue * 16); } void lbl_MouseEnter(object sender, EventArgs e) { label1.Text = "mouse has entered label number " + ID.ToString(); } protected override void OnMouseMove(MouseEventArgs e) { label4.Text = "X: " + e.X.ToString() + "\n" + "Y: " + e.Y.ToString(); } }
private void Methodappellee(object sender, MouseEventArgs e) { MessageBox.Show("blabla"); }
private void MethodSource { Methodappellee( ?? et la je mets quoi ???); }
Si on me demande je dirais que le "sender" est simplement le control en question qui declenche l'evenement
et EvenArgs c'est un "parametre" de ce control.
private void Methodappellee(object sender, MouseEventArgs e) //e est de type MouseEventArgs donc il s'agit d'une méthode liée à une événement MouseMove { MessageBox.Show("blabla"); }
Methodappellee(1, new MouseEventArgs());//si sender et e ne te servent pas dans Methodappellee tu peux aussi bien envoyé un int et un MouseEventArgs vide Label monLabel = new Label(); // si dans Methodappellee, tu as besoin d'un Label alors il faut soit que tu en inities un soit que tu te serve d'un existant MouseEventArgs() monE = new MouseEventArgs();// idem pour e Methodappellee(monLabel,monE);
class Personne { public string Nom { get; set; } public string Prenom { get; set; } }
Personne maPersonne = "Jean, Sort";cela soit intérprété comme il faut et crée une instance de Personne dont le prénom est Jean et le nom est Sort. Je ne vais pas aller plus loin ça n'est pas le sujet.
string[] sourceString = new string[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; double monIndex = 3 / 2;//là c'est 1.5 string moi = sourceString[(int)monIndex];// ici la syntaxe (int) veut dire convertit la variable qui suit en int par la méthode qui est programmée dans sa classe, là ça tronque l'index est 1 et le moi février
((Homme)maPersonne).Barbe;//](Homme)maPersonne veut toujours dire convertit ce qui suit en Homme, mais pour utiliser Barbe on met un jeu de parenthèses qui engloble le cast et la variable.
vaut mieux utiliser les objets que les événement