Scrolling a Map
Description
Exercise 8, requires that you learn to scroll the world map from the Date /Time Control Panel of Windows/Windows NT. In the current quiz, Quiz 4, you must scroll a map, starting with only a map in jpg format. The map used is a digitized version of a hand-colored engraving, originally published in 1856. It depicts the Roman Empire at its greatest extent.
Since this is the Roman Empire, center the map on Roma and choose three more points. The executable uses Gaul, Palestine, and India. When a location is selected, the map should scroll to that approximate position.
Note: the scrolling map will look odd to the modern eye since, in all settings but Roma, the tip of the Iberian Peninsula will reach to the west, wrapping around and touching India!
Map courtesy of Baldwin's Old Maps & Prints, PO Box 3515 Norfolk, Virginia 23514 (757) 625-1888.
Resources
- An executable like the application you are asked to create: click QPr4.exe . (From Internet Explorer, select the "Run this program" option of the "File download" dialog box that appears—from Netscape, save and double-click the file QPr4.exe.)
- The JPEG image of the map of the Roman Empire
Submission
Submit the following files:
- QPr4.resx
- QPr4.vb
- QPr4.vbproj
- Any image files your project uses directly
--------------------------------------------------------------------------------------------------------------------------------
我认为这个题目的难度在于如何将事件放置好,我在刚开始的时候将redraw放在了selectchanged里面,导致每次在redraw时被一些控件覆盖了。
Public Class MainForm Private Sub redrawImage(ByVal sender As System.Object, ByVal e As Windows.Forms.PaintEventArgs) Handles MainPB.Paint Dim l As Integer Select Case Me.LocationCB.SelectedIndex Case 0 l = (160) Case 1 l = (0) Case 2 l = (220) Case 3 l = (80) End Select Dim r As Rectangle r.Y = 0 r.X = l r.Width = My.Resources.RomanEmpire.Width r.Height = My.Resources.RomanEmpire.Height e.Graphics.DrawImage(My.Resources.RomanEmpire, r) r.X = -r.Width + l e.Graphics.DrawImage(My.Resources.RomanEmpire, r) End Sub Private Sub LocationCB_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LocationCB.SelectedIndexChanged Me.MainPB.Refresh() End Sub End Class
关键点:
- MainPB是picture box 控件
- 每次不是直接redraw而是调用refresh 方法
- 让redraw在paint even 中被调用