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 8901241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:17:58+00:00 2026-06-15T01:17:58+00:00

This behavior in C# is bizarre. I have the following class to allow me

  • 0

This behavior in C# is bizarre. I have the following class to allow me to effectively ‘draw’ on the desktop:

class drawOnDesktop {
    public static Form dodF = new Form();
    public static Graphics formGraphics;

    public drawOnDesktop() {
        formGraphics = dodF.CreateGraphics();
        dodF.BackColor = Color.LightGreen;
        dodF.TransparencyKey = Color.LightGreen;
        dodF.Size = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
        dodF.Location = new Point(0,0);
        dodF.StartPosition = FormStartPosition.Manual;
        //dodF.FormBorderStyle = FormBorderStyle.None;
        dodF.WindowState = FormWindowState.Maximized;
        dodF.MinimizeBox = false;
        dodF.MaximizeBox = false;
        dodF.ControlBox = false;
        //dodF.TopMost = true;  //For development in case something goes wrong
        dodF.BringToFront();
        dodF.Show();
    }

    public static void drawCircle(Point location) {
        formGraphics.FillEllipse(Brushes.Black, location.X, location.Y, 10, 10);
    }       
}

And I call it like this, from my main form:

drawOnDesktop dod = new drawOnDesktop();
drawOnDesktop.drawCircle(new Point(100,100));

If you run that code, you’ll get a small black circle in the top left corner of your screen. The problem is that you can see the form’s border. Now, try commenting out the FormBorderStyle line. The black dot will appear for a fraction of a second, and disappear. Why!? As you can see, I’ve set a lot of properties on this form, and still it refuses to work. Is it getting repainted over by the OS?

I don’t need to worry about mouse events or things like that – the dots being placed on the screen are completely programmatic, and not from the user. As well, if I set dodF.ShowInTaskbar = false, the entire program crashes.

How can I fix this code so the dot appears and stays until I formGraphics.Clear(Color.Black)?

  • 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-06-15T01:18:00+00:00Added an answer on June 15, 2026 at 1:18 am

    Don’t keep a copy of the graphics around, that is just asking for trouble. As others have stated, you should use the paint event to draw on the screen:

    class drawOnDesktop
    {
        public Form dodF = new Form();
        List<Point> circles = new List<Point>();
        public drawOnDesktop()
        {
    
            dodF.BackColor = Color.LightGreen;
            dodF.TransparencyKey = Color.LightGreen;
            dodF.Size = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            dodF.Location = new Point(0, 0);
            dodF.StartPosition = FormStartPosition.Manual;
            dodF.FormBorderStyle = FormBorderStyle.None;
            dodF.WindowState = FormWindowState.Maximized;
            dodF.MinimizeBox = false;
            dodF.MaximizeBox = false;
            dodF.ControlBox = false;
            dodF.TopMost = true;  //For development in case something goes wrong
            dodF.BringToFront();
            dodF.Paint += dodF_Paint;
            dodF.Show();
        }
    
        void dodF_Paint(object sender, PaintEventArgs e)
        {
            using (Graphics g = dodF.CreateGraphics())
            {
                foreach(Point location in circles)
                    g.FillEllipse(Brushes.Black, location.X, location.Y, 10, 10);    
            }
        }
    
        public  void drawCircle(Point location)
        {
            circles.Add(location);
        }
    }
    

    You can call it the same way, but now every time the form repaints, it will redraw the circles.

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

Sidebar

Related Questions

This behavior is making me wonder about my sanity.. I have a form that
This is gcc 4.4.6 on Linux. Here's the behavior bizarre.c double a[500000000]; main() {
What I want is this behavior: class a: list = [] x = a()
I would like to have this behavior in a task history stack: First task
I don't know the exact words to describe this behavior in the following pages:
I have searched but could not find the reason for this behavior. I have
I'm not sure if this behavior is bizarre, but here's what's happening: it seems
This behavior is so bizarre that I don't even know how best to ask
This is going to sound quite bizarre. I have one ASP .NET MVC 2
I stumbled across some bizarre behavior in Firefox 12. Consider the following HTML: <!DOCTYPE

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.