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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:56:46+00:00 2026-05-12T15:56:46+00:00

I was looking about some GDI tutorial but everything I have found so far

  • 0

I was looking about some GDI tutorial but everything I have found so far works with OnPaint method, which passes Paintarguments to Graphics. I have not found how to start from scratch, I mean how to use Graphics class itself?
This is the whole code I have treid that just doesnt work for me:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Pen pen= new Pen(Color.Red, 3);
            Graphics g;
            g = this.CreateGraphics();
    g.DrawEllipse(pen, 150, 150, 100, 100);
        }
    }
}

It just doesnt do anything. I tried it in new form, nothing.

Thank you in advance!

  • 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-12T15:56:47+00:00Added an answer on May 12, 2026 at 3:56 pm

    The code is probably OK, it is drawing a ellipse as you are hoping for. However, after the Load event, there will be a PaintBackground event and a PaintEvent as the form is displayed. The PaintBackground will, by default, erase the contents of the control, effectively removing the ellipse you’ve just drawn.

    Painting is a two stage process:

    for each (region in set of regions that need updating)
    {
      PaintBackground (region)
      Paint (region)
    }
    

    The window manager only redraws the parts of the control that require updating, if the contents of the control haven’t changed or no user action has altered the control’s visibility then no painting is done.

    So, why do you want to draw the ellipse in the Load method? Usually, you only want to draw something when something needs to be drawn, and your form is told when something needs drawing in the PaintBackground and Paint events.

    Are you worried about flickering? Or is it a speed issue? Ellipses are quick to draw. Flickering, however, is harder to fix. You need to create a bitmap, draw to the bitmap and blit the bitmap to the control during the Paint event. Also, make the PaintBackground event do nothing – no erasing the control, it’s the erasing that causes the flicker.

    EDIT: An example, I’m using DevStudio 2005 here.

    1. Create a new C# winform application.
    2. In Form1.cs add the following:

      protected override void OnPaintBackground (PaintEventArgs e)
      {
        // do nothing! prevents flicker
      }
      
      protected override void OnPaint (PaintEventArgs e)
      {
        e.Graphics.FillRectangle (new SolidBrush (BackColor), e.ClipRectangle);
      
        Point
          mouse = PointToClient (MousePosition);
      
        e.Graphics.DrawEllipse (new Pen (ForeColor), new Rectangle (mouse.X - 20, mouse.Y - 10, 40, 20));
      }
      
      protected override void OnMouseMove (MouseEventArgs e)
      {
        base.OnMouseMove (e);
        Invalidate ();
      }
      
    3. Compile and run.

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

Sidebar

Ask A Question

Stats

  • Questions 279k
  • Answers 279k
  • 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 Are you handling multiple callbacks of -connection: didReceiveData:? That will… May 13, 2026 at 3:22 pm
  • Editorial Team
    Editorial Team added an answer Windows programs have a DOS stub in the beginning, and… May 13, 2026 at 3:22 pm
  • Editorial Team
    Editorial Team added an answer You could create a ServletContextListener defined in web.xml that opens… May 13, 2026 at 3:22 pm

Related Questions

I'm working on a CMS as my hobby project. Because I'm not paid for
I'm looking for a Git alternatives to svn info. Today I added some information
I am total noob with XSL and XSL-FO and I am looking for some
MVC + classic webforms in the same website Now I am wondering if 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.