public Form() { InitializeComponent(); foreach (Control c in Controls) { c.Click += new EventHandler(c_Click); } } void c_Click(object sender, EventArgs e) { throw new NotImplementedException(); }
//changement du texte du label 1 depuis l'exterieur public string Text1 { get { return label1.Text; } set { label1.Text = value; Invalidate(); } } public UserControl1() { InitializeComponent(); Paint += new PaintEventHandler(UserControl1_Paint); Click += new EventHandler(UserControl1_Click); //on cache tous les controls pour lesquels on ne veut pas d'évenement click pictureBox1.Visible = false; label1.Visible = false; label2.Visible = false; } private void UserControl1_Click(object sender, EventArgs e) { //Click sur le user controle, ou sur un des controles cachés } private void UserControl1_Paint(object sender, PaintEventArgs e) { // on redéssine les controles cachés // on en profite pour mettre un joli fond LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(ClientRectangle,Color.AliceBlue,Color.CornflowerBlue,0.0); e.Graphics.FillRectangle(myLinearGradientBrush, ClientRectangle); //on utilise les propriété des controles, pour rendre plus facile le design e.Graphics.DrawString(label1.Text, label1.Font, Brushes.Black, label1.Location); e.Graphics.DrawString(label2.Text, label2.Font, Brushes.Black, label2.Location); RectangleF sourceRect = new RectangleF(0,0, pictureBox1.Image.Width,pictureBox1.Image.Height ); RectangleF destRect = new RectangleF(pictureBox1.Location, pictureBox1.Size); e.Graphics.DrawImage(pictureBox1.Image,destRect, sourceRect, GraphicsUnit.Pixel); }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question