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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:12:41+00:00 2026-05-14T05:12:41+00:00

so i got this piece of code. (currPosX is defined earlier) while (earliestDate <

  • 0

so i got this piece of code. (currPosX is defined earlier)

while (earliestDate < DateTime.Today)
        {
            currPosX = currPosX + 5;
            e.Graphics.DrawLine(Pens.Black, currPosX, 0, currPosX, 10);

            earliestDate = earliestDate.AddDays(1);
        }

the graphics don’t draw. it’s really weird, since this only happens when the condition statement is a date comparison. I debugged, and it does go in the loop, and the values are messed with (currPosX for example). But, no display. one more weirdness, if I add a MessageBox.Show(“blabla”) in the loop, the message box pops up, and graphics are drawn. what’s going on here?

EDIT: just to remind you guys, when it’s a non-datetime condition, it works. meaning that this code works. it does display a series of lines

int i = 0;

        while(i < 10)
        {
            currPosX = currPosX + 5;
            e.Graphics.DrawLine(Pens.Black, currPosX, 0, currPosX, 10);
            i++;
        }
  • 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-14T05:12:41+00:00Added an answer on May 14, 2026 at 5:12 am

    As your tests indicate, the issue has nothing to do with comparing DateTime’s. Since your code is entering the loop, and you know the painting is being done, something else must be going on. We’ll probably need to see more code to identify the problem

    Trying to step through painting code is useless. The fact that the debugger and application window trade focus will completely screw things up. You are better off using tracepoints, not breakpoints.

    But here’s some possibilities:

    • Are you sure your coordinates are in the control’s visible client area?
    • Are you doing the above in the control’s Paint event?
    • Are you remembering to invalidate the control using the Invalidate or Refresh method?
    • Are you painting on the UI thread?
    • Do you have any non-standard control styles set?

    UPDATE
    In response to your edit:

    Your problem is that earliestDate will keep creeping forward because you are modifying it in your Paint event and the value will persist between Paint events. Paint events occur repeatedly every time the control is invalidated. You have two options.

    1. Copy earliestDate to a local variable in the Paint event and use that
    2. Reset earliestDate back to its starting value at the end of the event.

    I suggest option 1.

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

Sidebar

Related Questions

I got this doubt while writing some code. Is 'bool' a basic datatype defined
Hallo all. I got this piece of code: <div> <input id=id1 name=radioButton type=radio> <input
I got this piece of Assembly code extracted from some piece of software, but
I've got this piece of Java code with embedded Rhino (irrelevant bits omitted): Context
I got this error today when trying to open a Visual Studio 2008 project
I got this flash application where you can click a link while watching a
I ran this piece of code var m = new MarkdownSharp.Markdown(); var sz =
I have this piece of code // TR Fading when deleted $('.delete').live('click', function() {
I got this output when running sudo cpan Scalar::Util::Numeric jmm@freekbox:~/bfwsandbox/sa/angel/astroportal/dtu8e/resources$ sudo cpan Scalar::Util::Numeric [sudo]
I got this síngleton cache object and it exposes an IEnumerable property which just

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.