Je dois dessiner une image sur un panneau, contenant des contrôles enfants. Je ne veux pas le laisser se cacher derrière ces contrôles, ce qui est le cas actuellement lorsque je dessine l'image dans l'événement Paint
.Dessiner l'image au-dessus des contrôles enfants
Voici le code que je l'habitude de passer outre la méthode OnPaint
de mon panneau:
protected override void OnPaint(PaintEventArgs e)
{
try
{
base.OnPaint(e);
//Draw icon for views at top right corner of the panel.
e.Graphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighQuality;
if (_viewButton != ViewButton.None)
{
Brush menuBrush =
new SolidBrush(_viewButton == ViewButton.Highlighted ?
Color.Black : Color.Gray);
e.Graphics.FillPolygon(menuBrush, new Point[] {
new Point(this.Width - 29, 03),
new Point(this.Width - 19, 03),
new Point(this.Width - 24, 09) });
menuBrush.Dispose();
//Draw border of the panel.
Rectangle borderRect =
new Rectangle(0, 0, this.Width - 1, this.Height - 1);
GraphicsPath borderPath = GetRoundPath(borderRect, 8);
e.Graphics.DrawPath(new Pen(Color.LightGray), borderPath);
}
}
catch (Exception ex)
{
throw new IDSException(ex);
}
}
protected override void OnPaint(PaintEventArgs e)
{
try
{
base.OnPaint(e);
//Draw icon for views at top right corner of the panel.
e.Graphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighQuality;
if (_viewButton != ViewButton.None)
{
Brush menuBrush =
new SolidBrush(_viewButton == ViewButton.Highlighted ?
Color.Black : Color.Gray);
e.Graphics.FillPolygon(menuBrush, new Point[] {
new Point(this.Width - 29, 03),
new Point(this.Width - 19, 03),
new Point(this.Width - 24, 09) });
menuBrush.Dispose();
//Draw border of the panel.
Rectangle borderRect =
new Rectangle(0, 0, this.Width - 1, this.Height - 1);
GraphicsPath borderPath = GetRoundPath(borderRect, 8);
e.Graphics.DrawPath(new Pen(Color.LightGray), borderPath);
}
}
catch (Exception ex)
{
throw new IDSException(ex);
}
}
Salut casperOne merci pour une réponse rapide car j'attends avec impatience. J'avais essayé cette chose mais j'ai échoué. Ça ne fonctionne pas. :( – Lalit
@Lalit: En cas d'échec, vous devez indiquer le code qui affiche l'erreur, sinon nous ne pouvons pas vous aider à déterminer où se trouve le problème – casperOne
Hi, M affichant le code comme autre réponse en tant que longueur de commentaire Ceci est une restriction pour moi. Ce sera une aide de gr8 pour le faire réparer. :) – Lalit