Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4557798
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:33:33+00:00 2026-05-21T17:33:33+00:00

I created a custom control which I want to use to overlay part of

  • 0

I created a custom control which I want to use to overlay part of my form with status information on demand. It should display a text and have a background color depending on the type of information. Here is the still incomplete code.

public partial class StatusPanel : UserControl
{
    public enum PanelStyle
    {
        Info,
        Warning,
        Error
    }

    public PanelStyle Style { get; set; }

    public StatusPanel()
    {
        InitializeComponent();

        this.imgGreen = new Bitmap(256, 256, PixelFormat.Format32bppArgb);
        using(Graphics g = Graphics.FromImage(this.imgGreen))
        {
            g.Clear(Color.Transparent);
            Brush bg = new SolidBrush(Color.FromArgb(200, Color.Green));
            g.FillRectangle(bg, 0, 0, 256, 256);
        }

        this.imgYellow = new Bitmap(256, 256, PixelFormat.Format32bppArgb);
        using(Graphics g = Graphics.FromImage(this.imgYellow))
        {
            g.Clear(Color.Transparent);
            Brush bg = new SolidBrush(Color.FromArgb(10, Color.Yellow));
            g.FillRectangle(bg, 0, 0, 256, 256);
        }
    }

    protected readonly Font font = new Font("Arial", 12.0F);

    protected readonly Brush textBrush = new SolidBrush(Color.Black);

    protected readonly Image imgGreen;

    protected readonly Image imgYellow;

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
            return cp;
        }
    }

    protected override void OnPaintBackground(PaintEventArgs e)
    {
        // do not draw background
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
        e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
        e.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
        e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

        Image img = GetImage();

        e.Graphics.DrawImage(img, 0, 0, this.Width, this.Height);

        e.Graphics.DrawString("ABC", this.font, this.textBrush, 1.0F, 1.0F);
    }

    protected Image GetImage()
    {
        return (this.Style == PanelStyle.Info) ? this.imgGreen : this.imgYellow;
    }
}

This works quite fine. But when I put some buttons on a form and one of this controls infront of them, they will “overdraw” when the mouse moves over the button and the highlight effects redraws them.

How will my component be notified that it needs to redraw because underlying control have redrawn?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T17:33:33+00:00Added an answer on May 21, 2026 at 5:33 pm

    register a paint-handler to all controls under Parent.Control and a handler for Parent.ControlAdded that registers your paint-handler

    something like this:

    private void myDummyUserControl_Load(object sender, EventArgs e)
    {
        var uc = (DummyUserControl)sender;
        uc.Parent.ControlAdded += new ControlEventHandler(Parent_ControlAdded);
        foreach (Control c in uc.Parent.Controls)
        {
            if (uc == c)
                continue;
            c.Paint += new PaintEventHandler(c_Paint);
        }
    }
    
    void c_Paint(object sender, PaintEventArgs e)
    {
        //checks & paint stuff here
    }
    
    void Parent_ControlAdded(object sender, ControlEventArgs e)
    {
        e.Control.Paint += new PaintEventHandler(c_Paint);
    }
    

    //edit

    not sure if you need to use recursion to go down the tree of child controls and need to add handlers on those too …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a custom control in C# which I will use multiple
I've created a custom control which consists of two radio buttons with their appearance
I've created a custom user control that has several properties. One specifies which database
I have created a Dynamic View Panel custom control and want to add a
I've created a custom control for MahTweets which simplifies/unifies the look of each update
Which is the right MVC way to create custom form control (like custom drop
I created a custom Camera Control with overlay ... Now i am zooming image
I created a WPF custom control, which works fine. It has a style which
I use custom control which creates a span and 2 asp controls with int.
​ Synopsis I want to build a custom control which displays events in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.