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

  • Home
  • SEARCH
  • 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 512125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:17:16+00:00 2026-05-13T07:17:16+00:00

I have a WinForms control on which I want to display two things: An

  • 0

I have a WinForms control on which I want to display two things:

  1. An underlying image painstakingly loaded bit-by-bit from an external input device; and
  2. A series of DrawLine calls that create a visual pattern over that image.

Thing #1, for our purposes, doesn’t change, and I’d rather not have to redraw it.

Thing #2 has to be redrawn relatively quickly, as it rotates when the user turns another control.

In my fantasy, I want to put each Thing in its own Graphics object, give #2 a transparent background, and simply hit #2 with a rotational transformation to match the user control setting. But I don’t see a way to make a Graphics object transparent, nor a way to rotate what’s already been drawn on one. So I’m probably asking Graphics to do something it wasn’t designed for.

Here’s my question: What’s the best way to set this up? Should I attempt to overlap my Graphics objects, or is there some completely different and better way to do this that I’m not thinking of?

  • 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-13T07:17:16+00:00Added an answer on May 13, 2026 at 7:17 am

    The Windows painting model is a good match for your requirements. It separates drawing the background (OnPaintBackground) from the foreground (OnPaint). That however doesn’t mean that you can only paint the background once and be done with it. Window surface invalidation invokes both. This is above all required to make anti-aliasing effects work properly, they can only look good against a known background color.

    Punt this and draw the Image in the OnPaintBackground() override. You can let Control do this automatically for you by assigning the BackgroundImage property. You’ll probably need to set the DoubleBuffer property to true to avoid the flicker you’ll see when the background is drawn, temporarily wiping out the foreground pixels. Call Invalidate() if you need to update the foreground.

    To be complete, your fantasy is in fact possible. You’d need to overlay the image with a toplevel layered window. That is easy to get with a Form whose TransparencyKey property is set. Here is a sample implementation:

    using System;
    using System.Drawing;
    using System.Windows.Forms;
    
    class OverlayedPictureBox : PictureBox {
        private Form mOverlay;
        private bool mShown;
        public event PaintEventHandler PaintOverlay;
        public OverlayedPictureBox() {
            mOverlay = new Form();
            mOverlay.FormBorderStyle = FormBorderStyle.None;
            mOverlay.TransparencyKey = mOverlay.BackColor = Color.Magenta;
            mOverlay.ShowInTaskbar = false;
        }
        protected void OnPaintOverlay(PaintEventArgs e) {
            // NOTE: override this or implement the PaintOverlay event
            PaintEventHandler handler = PaintOverlay;
            if (handler != null) handler(this, e);
        }
        public void RefreshOverlay() {
            // NOTE: call this to force the overlay to be repainted
            mOverlay.Invalidate();
        }
        protected override void Dispose(bool disposing) {
            if (disposing) mOverlay.Dispose();
            base.Dispose(disposing);
        }
        protected override void OnVisibleChanged(EventArgs e) {
            if (!mShown && !this.DesignMode) {
                Control parent = this.Parent;
                while (!(parent is Form)) parent = parent.Parent;
                parent.LocationChanged += new EventHandler(parent_LocationChanged);
                mOverlay.Paint += new PaintEventHandler(mOverlay_Paint);
                mOverlay.Show(parent);
                mShown = true;
            }
            base.OnVisibleChanged(e);
        }
        protected override void OnLocationChanged(EventArgs e) {
            mOverlay.Location = this.PointToScreen(Point.Empty);
            base.OnLocationChanged(e);
        }
        protected override void OnSizeChanged(EventArgs e) {
            mOverlay.Size = this.Size;
            base.OnSizeChanged(e);
        }
        void parent_LocationChanged(object sender, EventArgs e) {
            mOverlay.Location = this.PointToScreen(Point.Empty);
        }
        private void mOverlay_Paint(object sender, PaintEventArgs e) {
            OnPaintOverlay(e);
        }
    }
    

    One interesting artifact: minimizing the form and restoring it again looks, erm, special.

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

Sidebar

Ask A Question

Stats

  • Questions 270k
  • Answers 270k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would think you would want a table named Emotions… May 13, 2026 at 1:29 pm
  • Editorial Team
    Editorial Team added an answer LocalSqlServer is a default connection string entry in machine.config. It… May 13, 2026 at 1:29 pm
  • Editorial Team
    Editorial Team added an answer I'd second Toby's answer. Still, if you can't use an… May 13, 2026 at 1:29 pm

Related Questions

This one has been stumping me for a while. But I'm no expert. This
I need to dock a WinForms user control at run time but I'm encountering
I'm new to the WinForms control toolbox, so I'm looking to get suggestions on
I'm using a winforms webbrowser control to display some content in a windows forms
How do you create your own custom component for vb.net 2008? I want it

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.