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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:04:16+00:00 2026-05-25T20:04:16+00:00

I have a TabControl and a TabPage inside it. BackgroundImage consists of lines attaching

  • 0

I have a TabControl and a TabPage inside it. BackgroundImage consists of lines attaching the points. So I have some polygon. All these points are kept in the storage. each point has the time property when it was drawn. So I want to repaint the picture using the delays between points. i have the next code

        Page pg;
        if (storage.book.TryGetValue(currTPage.Name, out pg))
        {
            currTPage.BackgroundImage = new Bitmap(currTPage.Width, currTPage.Height);
            Graphics grap = Graphics.FromImage(currTPage.BackgroundImage);
            grap.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            foreach (Sequence seq in pg.pageSeq)
            {
                Dot startDot = null;
                Pen pen = new Pen(Color.FromArgb(seq.r, seq.g, seq.b), 1);
                foreach (Dot dot in seq.seq)
                {
                    int sX;
                    int sY;
                    if (filter.getPageParameters(currentPattern).orientation == Orientation.Landscape)
                    {
                        if (this.currTPage.Width / (double)this.currTPage.Height >= 1.4)
                        {
                            sX = (int)(dot.x * this.currTPage.Height / pageHeight) + (currTPage.Width - Convert.ToInt32(this.currTPage.Height * Math.Sqrt(2))) / 2;
                            sY = (int)(dot.y * this.currTPage.Height / pageHeight);
                        }
                        else
                        {
                            sX = (int)(dot.x * this.currTPage.Width / pageWidth);
                            sY = (int)(dot.y * this.currTPage.Width / pageWidth) + (currTPage.Height - Convert.ToInt32(this.currTPage.Width / Math.Sqrt(2))) / 2;
                        }
                    }
                    else
                    {
                        if (this.currTPage.Width / (double)this.currTPage.Height <= 1 / 1.4)
                        {
                            sX = (int)(dot.x * this.currTPage.Width / pageWidth);
                            sY = (int)(dot.y * this.currTPage.Width / pageWidth) + (currTPage.Height - Convert.ToInt32(this.currTPage.Width * Math.Sqrt(2))) / 2;
                        }
                        else
                        {
                            sX = (int)(dot.x * this.currTPage.Height / pageWidth) + (currTPage.Width - Convert.ToInt32(this.currTPage.Height / Math.Sqrt(2))) / 2;
                            sY = (int)(dot.y * this.currTPage.Height / pageWidth);
                        }
                    }

                    if (startDot == null)
                    {
                        startDot = new Dot(sX, sY, dot.time, dot.force);
                        continue;
                    }
                    Dot newDot = new Dot(sX, sY, dot.time, dot.force);
                    grap.DrawLine(pen, startDot.x, startDot.y, newDot.x, newDot.y);
                    Thread.Sleep((int)(newDot.time - startDot.time));
                    currTPage.Invalidate(new Rectangle(Math.Min(startDot.x, newDot.x) - 1, Math.Min(startDot.y, newDot.y) - 1, Math.Abs(startDot.x - newDot.x) + 1, Math.Abs(startDot.y - newDot.y) + 1));
                    startDot = newDot;
                }
            }
            currTPage.Invalidate();
        }

but the picture even doesn’t vanish in the beginning of the repainting. it just flash in the end when i do “currTPage.Invalidate();”

What I do wrong?

  • 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-25T20:04:17+00:00Added an answer on May 25, 2026 at 8:04 pm
         Thread.Sleep((int)(newDot.time - startDot.time));
         currTPage.Invalidate(new Rectangle(...));
    

    Your code is fundamentally incompatible with the way painting works in Windows. This code runs on the main thread, like it should, but a thread can do only one thing at a time. It cannot paint the window at the same time it is sleeping or executing your loop. Painting happens after your event handler exits and execution resumes the message loop, the one started by Application.Run(). When there’s nothing more important to do, like handling user input, Windows looks if any part of the window was marked invalid (your Invalidate()) call and generates the Paint event.

    You can now probably see what happens, you didn’t implement the Paint event. So it does the default drawing, it erases everything you drew and restores the default appearance of the tab page. The only reason you saw anything at all is because you used Sleep().

    You’ll need to completely rewrite this. Use a Timer with an Interval value that is the same as the Sleep(). And a class field that keeps track of the dot index. In the Tick event handler, call Invalidate() and increment the index. And implement the Paint event to do the drawing.

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

Sidebar

Related Questions

I have a TrackBar control on a TabPage inside a TabControl. The background of
I currently have a Form with a TabControl containing some TabPage s. Each TabPage
I have the next problem: TabControl has three TabPages. Every TabPage has its own
I have a TabControl and on each TabPage is a DataGridView control docked to
(Hi, all) I have create a new user control inherit from tabcontrol, and override
This is all I have so far. tabControl1.TabPages[0].??? I have a PictureBox inside of
I want to remove a particular tabpage from the tabcontrol. For which i have
i have a TabControl with several TabPages and controls in every TabPage. I'm using
I have some tabControl in C# Windows app. It has some tabPages. Does anyone
I have TabControl. I added it to tabpages. To one of them(tpTags) I dynamically

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.