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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:26:14+00:00 2026-05-14T14:26:14+00:00

I’m coming from a Java background and trying to port a simple version of

  • 0

I’m coming from a Java background and trying to port a simple version of Conway’s Game of Life that I wrote to C# in order to learn the language.

In Java, I drew my output by inheriting from JComponent and overriding paint(). My new canvas class then had an instance of the simulation’s backend which it could read/manipulate. I was then able to get the WYSIWYG GUI editor (Matisse, from NetBeans) to allow me to visually place the canvas.

In C#, I’ve gathered that I need to override OnPaint() to draw things, which (as far as I know) requires me to inherit from something (I chose Panel). I can’t figure out how to get the Windows forms editor to let me place my custom class. I’m also uncertain about where in the generated code I need to place my class.

How can I do this, and is putting all my drawing code into a subclass really how I should be going about this? The lack of easy answers on Google suggests I’m missing something important here. If anyone wants to suggest a method for doing this in WPF as well, I’m curious to hear it.

Thanks

  • 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-14T14:26:15+00:00Added an answer on May 14, 2026 at 2:26 pm

    In Windows Forms, you can simply draw on any control by calling its CreateGraphics method. If you have a panel, for example, you can draw like this:

    using (var g = panel1.CreateGraphics()) {
        g.DrawString("Hello World", 0, 0);
    }
    

    Controls also have a Paint event. Add an event handler by double-clicking the event in the properties window, and you can draw like this:

    private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
        e.Graphics.DrawString("Hello World", 0, 0);
    }
    

    If you want to derive from a control, you can either just do it in code, or create a new user control and change the base class in the code and in the .Designer.cs file (though UserControl or just Control will be fine). If you already have a form in the designer, it’s already derived from Form, and you can just override OnPaint.

    My advice is: You typically won’t need to create a new class if you just want to draw something. Just use the Paint event. If you need to immediately redraw, call Refresh to make the control redraw itself. This should get you going. Note that there is also a protected DoubleBuffered property, which can help you avoid flickering (set it for the form or in your derived control).

    I’m not sure what you would do in WPF. I never needed to actually draw something manually in WPF, since the layout and rendering engine is very powerful, and you can just get away with data templates, control templates etc. The point in WPF is that you typically don’t draw anything, the engine draws for you.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Seems like a reasonable bug to open. I never noticed… May 15, 2026 at 5:22 am
  • Editorial Team
    Editorial Team added an answer Evets actually are not the way to go here. You… May 15, 2026 at 5:22 am
  • Editorial Team
    Editorial Team added an answer Is the created markup identical? Is it valid (x)html? Do… May 15, 2026 at 5:22 am

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.