Note that there are some explanatory texts on larger screens.

plurals
  1. PODrawing transparent controls (with all contents getting transparent too)
    primarykey
    data
    text
    <p>i just made a control which fades using alpha. The problem is, the "Icon" (from SystemIcons) i draw, and the other controls (one button atm) don´t get transparent. All texts and backgrounds fades by the alpha value i use in "Graphics.DrawXXX(...)".</p> <p>How could i draw those things in the same alpha value? </p> <p>Thanks a lot! R</p> <pre><code> protected override void OnPaint(PaintEventArgs e) { if (!Visible) return; Graphics g = e.Graphics; Color borderColor; Color gradientTopColor; Color gradientBottomColor; Color textColor; if (_displayColorStyle == IB_DisplayColorStyle.Normal) { borderColor = Color.FromArgb(fade_currentAlpha, 187, 191, 196); gradientTopColor = Color.FromArgb(fade_currentAlpha, 246, 249, 251); gradientBottomColor = Color.FromArgb(fade_currentAlpha, 233, 236, 240); textColor = Color.FromArgb(fade_currentAlpha, 106, 106, 106); } else if (_displayColorStyle == IB_DisplayColorStyle.Info) { borderColor = Color.FromArgb(fade_currentAlpha, 171, 186, 208); gradientTopColor = Color.FromArgb(fade_currentAlpha, 224, 236, 249); gradientBottomColor = Color.FromArgb(fade_currentAlpha, 210, 225, 240); textColor = Color.FromArgb(fade_currentAlpha, 106, 106, 106); } else if (_displayColorStyle == IB_DisplayColorStyle.Warning) { borderColor = Color.FromArgb(fade_currentAlpha, 106, 106, 106); gradientTopColor = Color.FromArgb(fade_currentAlpha, 240, 225, 53); gradientBottomColor = Color.FromArgb(fade_currentAlpha, 239, 194, 37); textColor = Color.FromArgb(fade_currentAlpha, 106, 106, 106); } else { borderColor = Color.FromArgb(fade_currentAlpha, 106, 106, 106); gradientTopColor = Color.FromArgb(fade_currentAlpha, 255, 0, 0); gradientBottomColor = Color.FromArgb(fade_currentAlpha, 217, 0, 0); textColor = Color.FromArgb(fade_currentAlpha, 224, 236, 249); } //Draw Background LinearGradientBrush backgroundBrush = new LinearGradientBrush(ClientRectangle, gradientTopColor, gradientBottomColor, 90f); g.FillRectangle(backgroundBrush, 1, 1, ClientRectangle.Width - 2, ClientRectangle.Height - 2); //Draw Border g.DrawRectangle(new Pen(new SolidBrush(borderColor), 1f), 0, 0, ClientRectangle.Width - 1, ClientRectangle.Height - 1); //Select Icon to use Icon usedIcon = _displayColorStyle == IB_DisplayColorStyle.Normal ? null : _displayColorStyle == IB_DisplayColorStyle.Info ? SystemIcons.Information : _displayColorStyle == IB_DisplayColorStyle.Warning ? SystemIcons.Warning : SystemIcons.Error; if (usedIcon != null) //If icon is used, draw this g.DrawIcon(usedIcon, 5, Size.Height / 2 - (SystemIcons.Error.Height / 2)); if (!string.IsNullOrEmpty(_title)) //If a title should be displayed { if (usedIcon == null) //No Icon, text left aligned { g.DrawString(_text, new Font("Arial", 8f, FontStyle.Regular), new SolidBrush(textColor), new RectangleF(5f, 20f, (Width - _closeButton.Width - 10), Height - 12f)); g.DrawString(_title, new Font("Arial", 10f, FontStyle.Bold), new SolidBrush(textColor), new RectangleF(5f, 5f, (Width - _closeButton.Width - 10), 15f)); } else { g.DrawString(_text, new Font("Arial", 8f, FontStyle.Regular), new SolidBrush(textColor), new RectangleF(10f + usedIcon.Width, 20f, (Width - _closeButton.Width - 20 - usedIcon.Width), Height - 12f)); g.DrawString(_title, new Font("Arial", 10f, FontStyle.Bold), new SolidBrush(textColor), new RectangleF(10f + usedIcon.Width, 5f, (Width - _closeButton.Width - 20 - usedIcon.Width), 15f)); } } else { if (usedIcon == null) //No Icon, text left aligned g.DrawString(_text, new Font("Arial", 8f, FontStyle.Regular), new SolidBrush(textColor), new RectangleF(5f, 5f, (Width - _closeButton.Width - 10), Height - 2f)); else g.DrawString(_text, new Font("Arial", 8f, FontStyle.Regular), new SolidBrush(textColor), new RectangleF(10f + usedIcon.Width, 5f, (Width - _closeButton.Width - 20 - usedIcon.Width), Height - 2f)); } base.OnPaint(e); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload