scrolling a bitmap - how is it done?

R

Richard

Hi all,

I have a bitmap that I draw onto with text and stuff, and I copy the bitmap
to the form for display. I do this as form's in .net no longer have
autoredraw, so I keep my own copy of the image and then paint it to the form
in the Paint event. Here is how I set up the bitmap:

Dim mGraphics as Graphics
Dim mBitmap as Bitmap

In form load I do this:

mBitmap = New Bitmap(SystemInformation.WorkingArea.Width,
SystemInformation.WorkingArea.Height, Me.CreateGraphics())
mGraphics = Graphics.FromImage(mBitmap)

and I draw onto the bitmap with

mGraphics.DrawString(c, mFont, New SolidBrush(mForeGround), mX * mCharWidth,
mY * mCharHeight)

I update the form with

Me.CreateGraphics.DrawImage(mBitmap, 0, 0) ' update the form with the bitmap

This is all working beautifully, but I need to scroll the bitmap image up
by, say, 16 pixels. I have tried using DrawImage:

mGraphics.DrawImage(mBitmap, New Rectangle(0, 0, mBitmap.Width,
mBitmap.Height), New Rectangle(0, 16, mBitmap.Width, mBitmap.Height),
System.Drawing.GraphicsUnit.Pixel)
Me.CreateGraphics.DrawImage(mBitmap, 0, 0)

To me, the logic looks correct. I draw the portion of the bitmap starting
from 16 pixels down the image, back to the top of the bitmap, to simulate a
scrolling effect.

If anybody out there has any suggestions, please reply to this thread.

Thanks in advance,

Richard
 
T

Tom Leylan

Hi Richard... I don't know exactly where you are putting what but I was able
to draw the word "test" onto the form and scroll it up each time I clicked a
button.

My first question is... you are drawing in the paint event right? And after
you scroll are you invalidating the form?

Rather than draw (in your paint event) at 0, 0 have it draw at X, Y with
those variables set to zero initially. Then you should be able to scroll by
simply decrementing Y. The value goes negative and image appears to scroll.
 
C

Cor

Hi Richard,

I did not exactly examine your code.
But for that you need in my opinion to play with the start position from the
rectangle from the bitmap from the sender. And not with the made bitmap,
than you will only make it smaller.

Just my thought.


Cor
 
B

Bob Powell [MVP]

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top