how do i scroll a form?

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

Hi,

I am writing text for a telnet application to a form, and when I get to the
bottom of the screen I want to scroll the image upwards by one line. I know
the height of the text I am printing, via MeasureString.Height but I do not
know how to scroll the actual image contained within the form.

Can anybody help me out here?

Regards and thanks,

Richard
 
* "Richard said:
I am writing text for a telnet application to a form, and when I get to the
bottom of the screen I want to scroll the image upwards by one line. I know
the height of the text I am printing, via MeasureString.Height but I do not
know how to scroll the actual image contained within the form.

Please be more specific. Do you use the form's 'AutoScroll' feature?
How do you display the image? Do you draw it onto the form or is it
displayed in a picturebox control?
 
Sorry if I was vague - I have setup variables

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

I use this method so that I keep a permanent copy of what has been drawn to
the form, without having to do much coding in the Paint event.

I think I have to scroll the form (or rather, my copy of the form) with the
DrawImage command, but I have yet to work out how to this. But there is
probably another way that I do not know of.

Richard
 
* "Richard said:
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

Never do that. Instead use this:

\\\
Dim g As Graphics = Me.CreateGraphics()
g.DrawImage(...)
g.Dispose()
///
I use this method so that I keep a permanent copy of what has been drawn to
the form, without having to do much coding in the Paint event.

I think I have to scroll the form (or rather, my copy of the form) with the
DrawImage command, but I have yet to work out how to this. But there is
probably another way that I do not know of.

Do you use 2 scrollbars or the form's 'AutoScroll' scrollbars?
 
Never do that. Instead use this:

\\\
Dim g As Graphics = Me.CreateGraphics()
g.DrawImage(...)
g.Dispose()
///

If I alt-tab away from the form, will the image still remain? Forms no
longer have autoredraw capability.
Do you use 2 scrollbars or the form's 'AutoScroll' scrollbars?

It'll be pretty basic at first - when the (x,y) of the text output reaches
the end of the screen I will scroll the screen up one line. I do not plan to
have scroll-bars at present, but I may implement them at a later date. It's
basically a 80 x 24 screen (configurable though).

Richard
 
* "Richard said:
Never do that. Instead use this:

\\\
Dim g As Graphics = Me.CreateGraphics()
g.DrawImage(...)
g.Dispose()
///

If I alt-tab away from the form, will the image still remain? Forms no
longer have autoredraw capability.

You will have to redraw the form's content in its 'OnPaint' method or
'Paint' event handler.
 
Herfried K. Wagner said:
You will have to redraw the form's content in its 'OnPaint' method or
'Paint' event handler.

I am emulating the AutoRedraw functionality by creating a bitmap and drawing
onto the image of the bitmap, and then copying the bitmap to the actual form
in the OnPaint event.

Back to my original question - how do I scroll the image?

Thanks,

Richard
 
* "Richard said:
I am emulating the AutoRedraw functionality by creating a bitmap and drawing
onto the image of the bitmap, and then copying the bitmap to the actual form
in the OnPaint event.

Back to my original question - how do I scroll the image?

Paint the part of the image according to the scrollbars' positions using
'DrawImage'.
 
Herfried K. Wagner said:
Paint the part of the image according to the scrollbars' positions using
'DrawImage'.

Thanks, I would never have worked that part out for myself!

There are NO scrollbars, by the way.

I've already said in my original post - and included the code for it - that
I was unable to get the scrolling action to work, using the DrawImage
method.

Obviously my code is incorrect - how do I scroll the bitmap image up, say,
16 pixels?

Richard
 
Richard,

* "Richard said:
I've already said in my original post - and included the code for it - that
I was unable to get the scrolling action to work, using the DrawImage
method.

Obviously my code is incorrect - how do I scroll the bitmap image up, say,
16 pixels?

Quock and dirty, place a timer control on the form:

\\\
Private m_Bitmap As Bitmap
Private m_CurrentY As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
m_Bitmap = New Bitmap("C:\WINDOWS\Angler.bmp")
With Me.Timer1
.Interval = 100
.Enabled = True
End With
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
m_CurrentY = (m_CurrentY + 16) Mod Me.ClientSize.Height
Me.Refresh()
End Sub

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
With e.Graphics
.Clear(Me.BackColor)
.DrawImage(m_Bitmap, 10, m_CurrentY)
End With
End Sub
///
 
Back
Top