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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:47:04+00:00 2026-06-12T05:47:04+00:00

I have a relatively simple windows application. It uses about 15 controls. My constructor

  • 0

I have a relatively simple windows application. It uses about 15 controls.

My constructor method looks like this:

public Form1()
{
    InitializeComponent();
    this.Paint += this.Teken;
}

My Teken method (simplified) looks like this:

private void Teken(object o, PaintEventArgs pea)
{
    if (start)
    {
        if (comboBox1.Text == "Basic")
            Bitmaps.DrawBitmap1(pea.Graphics, bitmapsize, max);
    }
}

My DrawBitmap1 method sets every pixel a certain color and then draws a bitmap using the Graphics.DrawImage method.

After the bitmap is drawn, the controls become really laggy and it takes more than a second to select text in a textbox. The main form just gets really slow.

I can understand the bitmap to be drawn slowly but I can’t understand this.

Is there a simple solution to my problem?

EDIT:

Here’s the Drawbitmap1 code:

public static void DrawBitmap1(Graphics gr, int bitmapsize, int max)
    {
        Bitmap bitmap1 = new Bitmap(bitmapsize, bitmapsize);

        for (int x = 1; x < bitmapsize; x++)
        {
            for (int y = 1; y < bitmapsize; y++)
            {
                int mandelnumber = CalculateMandel(x,y)

                if (Form1.mandelnumber == max) 
                    bitmap1.SetPixel(x, y, Color.Black);
                else if (Form1.mandelnumber %2 == 0) 
                    bitmap1.SetPixel(x, y, Color.White);
                else 
                    bitmap1.SetPixel(x, y, Color.Black);
            }
        }
        gr.DrawImage(bitmap1, 50, 100);
    }

mandelnumber is a variable calculated in another part of the program.

EDIT2:

I’ve run a profiler and it seems that the method CalculateMandel() doesn’t stop running after it’s been through every pixel of the bitmap. How is this possible?

EDIT3:

Turns out the DrawBitmap1 function is called again when hovering over textboxes or buttons. How is this possible, I don’t have any hover events, not even TextChanged events..

  • 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-12T05:47:05+00:00Added an answer on June 12, 2026 at 5:47 am
    this.Paint += this.Teken;
    

    This is wrong, it will call your Teken routine every time your app needs repainting; when you open your window, when you resize your window, when you change focus, move another window, get a tooltip, change resolution or themes, practically all the time. In fact, about the only time Teken is not called is when CalculateMandel is finished and you need to show the results. You never call Invalidate so you are never alerted when you need to draw your results.

    … CalculateMandel() doesn’t stop running after it’s been through every pixel of the bitmap. How is this possible?

    Because you are specifically telling it to recalculate everything in your bitmap every time anything changes in your U.I.; over and over and over again. Unless only your bitmap changes, then you don’t tell it to repaint. Completely backward. This will also lock up your U.I. as you are uselessly recalculating your bitmap even if it doesn’t need redrawing.

    … DrawBitmap1 function is called again when hovering over textboxes or buttons. How is this possible, I don’t have any hover events

    But something else does; perhaps a tooltip. And you have told your app to call CalculateMandel() every time anything in your app U.I. (except your bitmap) changes.

    The problem is you have two totally separate things going on; your app needs to repaint the U.I. when something changes, and you have a calculation (CalculateMandel()) that you want to update the U.I. when it’s done. These are separate events and you must handle them separately.

    First, get rid of this.Paint += this.Teken;; that’s causing your problems and will not do what you want.

    Second, create a BackgroundWorker that calls CalculateMandel() in its DoWork event and in your ProgressChanged event returns the completed bitmap then calls yourWindowOrPanelOrWhatever.Invalidate() to redraw the new data.

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

Sidebar

Related Questions

I have a relatively simple HTML / JavaScript form. Such as this: <form method='POST'
I have a relatively simple object with a method that makes an HTTP request.
I have a relatively simple application which I need to make native Mac OSX
I have this relatively simple regex for usernames // Enforce that username has to
I have a simple Windows Forms (C#, .NET 2.0) application, built with Visual Studio
I have taken over a Windows-CE 6.0 application that I would like to port
At the moment I have a Silverlight application in Windows Phone which uses the
I have moved a relatively simple ZF app from a windows based server to
I have a relatively simple question. Will using PHP guarantee that a form is
I have two relatively simple codes. One main activity and one intent service. Main

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.