Scrolling

Team-Fly    

 
Application Development Using Visual Basic and .NET
By Robert J. Oberg, Peter Thorsteinson, Dana L. Wyatt
Table of Contents
Chapter 11.  Introduction to GDI+


graphics/codeexample.gif

Often a window may not be large enough to display all the information available. For example, in Version 1 of ScrollDemo in the previous section, if the window is made small, you will not be able to see all the lines of text displayed at the same time. In such a situation it is useful for the user to be able to scroll the output to view additional information. The standard way Windows handles this situation is to provide horizontal and vertical scrollbars. Version 2 of ScrollDemo adds scrolling capability to our program, as illustrated in Figure 11-12.

Figure 11-12. Scrollbars enable user to view multiple lines of text.

graphics/11fig12.jpg

The .NET Framework makes it easy to implement scrolling in your programs through an autoscroll capability. You set the AutoScroll property of the form to True , and you specify a minimum scroll size through the AutoScrollMinSize property. You then adjust the coordinates in your output by AutoScrollPosition .

 Public Class Form1    Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " ...    Private m_strings() As String = {"This is", _       "an example", "of text", "distributed", _       "over several", "lines"}    Private m_deltaY As Integer    Private Sub Form1_Load(ByVal sender As Object, _     ByVal e As System.EventArgs) Handles MyBase.Load       m_deltaY = Font.Height       Me.BackColor = Color.White  Me.AutoScroll = True   Me.AutoScrollMinSize = New Size(400, 200)  End Sub    Private Sub Form1_Paint(ByVal sender As Object, _     ByVal e As System.Windows.Forms.PaintEventArgs) _     Handles MyBase.Paint       Dim g As Graphics = e.Graphics       Dim i As Integer       Dim y As Integer = 0  Dim pt As Point = Me.AutoScrollPosition  For i = 0 To m_strings.Length - 1          g.DrawString(m_strings(i), Font, _             Brushes.Black,  pt.X  ,  pt.Y + y  )          y += m_deltaY       Next    End Sub End Class 

Team-Fly    
Top
 


Application Development Using Visual BasicR and .NET
Application Development Using Visual BasicR and .NET
ISBN: N/A
EAN: N/A
Year: 2002
Pages: 190

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net