Home All Groups Group Topic Archive Search About

GDI+ moving drawings

Author
11 Jan 2007 12:44 PM
sonny
hi,

i'd like to scroll an square across the form, but i have 2 requirements.  it
should only be visibile for a certain amount of time (generally 400 ms) and
it should move across the screen for a certain disance.

the code i have written works (sorta), the only problem is that it appears
choppy.  how can i do this where my square moves smoothly across the screen?

while (DateTime.Now < endTime)
{
   TimeSpan span = DateTime.Now.Subtract(startTime);

   distance = (int)(((span.Seconds * 1000) + span.Milliseconds) *
pixPerMilli);
   if (distance > cnt)
   {
       difference = distance - cnt;
       for (int i = 0; i < difference; i++)
       {
           DrawingUtilities.DrawLine(grafix, canvas.BackColor, 1, new
Point(x + cnt, y), new Point(x + cnt, y + sz.Height - 1));
           DrawingUtilities.DrawLine(grafix, stimuliColor, 1, new Point(x +
cnt + sz.Width - 1, y), new Point(x + cnt + sz.Width - 1, y + sz.Height - 1));
           cnt++;
        }
    }
    Thread.Sleep(1);
}

thx for you help...sonny

Author
11 Jan 2007 2:48 PM
Kevin Spencer
Try using the System.Windows.Forms.ControlPaint class. Specifically, the
FillReversibleRectangle method:

http://msdn2.microsoft.com/en-us/library/system.windows.forms.controlpaint.fillreversiblerectangle.aspx

--
HTH,

Kevin Spencer
Microsoft MVP
Bit Player
http://unclechutney.blogspot.com

Where there's a Will, there's a William.


Show quote
"sonny" <so***@discussions.microsoft.com> wrote in message
news:5E3EE20F-04D0-4472-B556-BD148F32B94B@microsoft.com...
> hi,
>
> i'd like to scroll an square across the form, but i have 2 requirements.
> it
> should only be visibile for a certain amount of time (generally 400 ms)
> and
> it should move across the screen for a certain disance.
>
> the code i have written works (sorta), the only problem is that it appears
> choppy.  how can i do this where my square moves smoothly across the
> screen?
>
> while (DateTime.Now < endTime)
> {
>   TimeSpan span = DateTime.Now.Subtract(startTime);
>
>   distance = (int)(((span.Seconds * 1000) + span.Milliseconds) *
> pixPerMilli);
>   if (distance > cnt)
>   {
>       difference = distance - cnt;
>       for (int i = 0; i < difference; i++)
>       {
>           DrawingUtilities.DrawLine(grafix, canvas.BackColor, 1, new
> Point(x + cnt, y), new Point(x + cnt, y + sz.Height - 1));
>           DrawingUtilities.DrawLine(grafix, stimuliColor, 1, new Point(x +
> cnt + sz.Width - 1, y), new Point(x + cnt + sz.Width - 1, y + sz.Height -
> 1));
>           cnt++;
>        }
>    }
>    Thread.Sleep(1);
> }
>
> thx for you help...sonny
>
Author
11 Jan 2007 3:40 PM
sonny
thx kevin,

am i missing something?  how do i use this to move a drawing across the
screen?

Show quote
"Kevin Spencer" wrote:

> Try using the System.Windows.Forms.ControlPaint class. Specifically, the
> FillReversibleRectangle method:
>
> http://msdn2.microsoft.com/en-us/library/system.windows.forms.controlpaint.fillreversiblerectangle.aspx
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> Bit Player
> http://unclechutney.blogspot.com
>
> Where there's a Will, there's a William.
>
>
> "sonny" <so***@discussions.microsoft.com> wrote in message
> news:5E3EE20F-04D0-4472-B556-BD148F32B94B@microsoft.com...
> > hi,
> >
> > i'd like to scroll an square across the form, but i have 2 requirements.
> > it
> > should only be visibile for a certain amount of time (generally 400 ms)
> > and
> > it should move across the screen for a certain disance.
> >
> > the code i have written works (sorta), the only problem is that it appears
> > choppy.  how can i do this where my square moves smoothly across the
> > screen?
> >
> > while (DateTime.Now < endTime)
> > {
> >   TimeSpan span = DateTime.Now.Subtract(startTime);
> >
> >   distance = (int)(((span.Seconds * 1000) + span.Milliseconds) *
> > pixPerMilli);
> >   if (distance > cnt)
> >   {
> >       difference = distance - cnt;
> >       for (int i = 0; i < difference; i++)
> >       {
> >           DrawingUtilities.DrawLine(grafix, canvas.BackColor, 1, new
> > Point(x + cnt, y), new Point(x + cnt, y + sz.Height - 1));
> >           DrawingUtilities.DrawLine(grafix, stimuliColor, 1, new Point(x +
> > cnt + sz.Width - 1, y), new Point(x + cnt + sz.Width - 1, y + sz.Height -
> > 1));
> >           cnt++;
> >        }
> >    }
> >    Thread.Sleep(1);
> > }
> >
> > thx for you help...sonny
> >
>
>
>
Author
11 Jan 2007 5:41 PM
Kevin Spencer
Hi sonny,

To quote the article:

"The results of this method can be reversed by drawing the same rectangle
again. Drawing a rectangle using this method is similar to inverting a
region of the screen, except that it provides better performance for a wider
variety of colors."
"sonny" <so***@discussions.microsoft.com> wrote in message
news:F2007F95-9D63-4FC2-9848-

Although I haven't used this specific method, I have used other ControlPaint
methods to, for example, draw a selection rectangle with the mouse. What you
would want to do is to draw, reverse, draw, reverse in progressively
different locations.

--
HTH,

Kevin Spencer
Microsoft MVP
Bit Player
http://unclechutney.blogspot.com

Where there's a Will, there's a William.

B720FE963***@microsoft.com...
Show quote
> thx kevin,
>
> am i missing something?  how do i use this to move a drawing across the
> screen?
>
> "Kevin Spencer" wrote:
>
>> Try using the System.Windows.Forms.ControlPaint class. Specifically, the
>> FillReversibleRectangle method:
>>
>> http://msdn2.microsoft.com/en-us/library/system.windows.forms.controlpaint.fillreversiblerectangle.aspx
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> Bit Player
>> http://unclechutney.blogspot.com
>>
>> Where there's a Will, there's a William.
>>
>>
>> "sonny" <so***@discussions.microsoft.com> wrote in message
>> news:5E3EE20F-04D0-4472-B556-BD148F32B94B@microsoft.com...
>> > hi,
>> >
>> > i'd like to scroll an square across the form, but i have 2
>> > requirements.
>> > it
>> > should only be visibile for a certain amount of time (generally 400 ms)
>> > and
>> > it should move across the screen for a certain disance.
>> >
>> > the code i have written works (sorta), the only problem is that it
>> > appears
>> > choppy.  how can i do this where my square moves smoothly across the
>> > screen?
>> >
>> > while (DateTime.Now < endTime)
>> > {
>> >   TimeSpan span = DateTime.Now.Subtract(startTime);
>> >
>> >   distance = (int)(((span.Seconds * 1000) + span.Milliseconds) *
>> > pixPerMilli);
>> >   if (distance > cnt)
>> >   {
>> >       difference = distance - cnt;
>> >       for (int i = 0; i < difference; i++)
>> >       {
>> >           DrawingUtilities.DrawLine(grafix, canvas.BackColor, 1, new
>> > Point(x + cnt, y), new Point(x + cnt, y + sz.Height - 1));
>> >           DrawingUtilities.DrawLine(grafix, stimuliColor, 1, new
>> > Point(x +
>> > cnt + sz.Width - 1, y), new Point(x + cnt + sz.Width - 1, y +
>> > sz.Height -
>> > 1));
>> >           cnt++;
>> >        }
>> >    }
>> >    Thread.Sleep(1);
>> > }
>> >
>> > thx for you help...sonny
>> >
>>
>>
>>

AddThis Social Bookmark Button