Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2006

Tip: Looking for answers? Try searching our database.

gdi+ question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ZQ - 24 Mar 2006 11:52 GMT
Hi everyone!

I have a question about GDI+.

float deltaY = 0;

// the onPaint handler of my control
protected override void OnPaint(PaintEventArgs e)
{
   e.Graphics.TranslateTransform(0, deltaY);
   GenerateGraphics(e.Graphics);
}

In an OnClick event, I change the value of deltaY, and invalidate the
control.
Everything works fine - the graphics is then moved upwards or downwards -
depending
what the deltaY is set to, but it's very slow.

So I figured I should use BufferedGraphics and do something like this:

BufferedGraphics buff;
float deltaY = 0;

...somewhere in the code...
InitializeBufferedGraphics(buff);

...elsewhere in the code...
GenerateGraphics(buff.Graphics);
// this draws strings and rectangles and stuff on the buffered graphics
// this happens only when graphics needs to be changed, and not in the
OnPaint handler like it used
// to be earlier

// the onPaint handler of my control
protected override void OnPaint(PaintEventArgs e)
{
   e.Graphics.TranslateTransform(0, deltaY);
   buff.Render(e.Graphics);
}

However, the TranslateTransform has absolutely no effect on buff.Render. -
the graphics rendered
from bufferedGraphics is not moved anywhere.

Is there a way to render the BufferedGraphics object over the OnPaint's
Graphics object, but translated?
Jianwei Sun - 24 Mar 2006 18:31 GMT
see inline.

> Hi everyone!
>
[quoted text clipped - 34 lines]
> {
>     e.Graphics.TranslateTransform(0, deltaY);
[  you probably need to the transfer on the BufferedGraphics
     buff.Graphics.TranslateTransform(0, deltaY);

>     buff.Render(e.Graphics);
> }
[quoted text clipped - 5 lines]
> Is there a way to render the BufferedGraphics object over the OnPaint's
> Graphics object, but translated?
ZQ - 24 Mar 2006 20:21 GMT
Thanks for your response!

I considered that, and buff.Graphics.TranslateTransform(0, deltaY) has no
effect whatsoever.
TranslateTransform does it's transformations only on things that are drawn
AFTER it is called.

In this case:
1. a lot of things are drawn to buff.Graphics at time X
2. inside OnPaint(), buff.Graphics is rendered to the e.Graphics (everything
shows up on screen ok)
3. when user clicks a button only deltaY changes, nothing new is drawn on
buff.Graphics -- therefore, if I call the
buff.Graphics.TranslateTransform(0, deltaY) now, it won't apply to anything
because nothing is drawn after that
4. i call this.Invlidate() to refresh the control and display the translated
drawings
5. inside OnPaint(), buff.Graphics is rendered to the e.Graphics (it is
supposed to be on a new location, but it seems impossible)

I expected it to be normal that e.Graphics.translateTransform (...) would
affect everything that is rendered to e.Graphics from bufferedGraphics, but
that doesn't seem to be right.

It seems to me all I can do is optimize the GenerateGraphics method.

> see inline.
>
[quoted text clipped - 48 lines]
>> Is there a way to render the BufferedGraphics object over the OnPaint's
>> Graphics object, but translated?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.