Welcome Guest!
 VB.NET Helper
 Previous Message All Messages Next Message 
VB .NET Helper Newsletter  Rod Stephens
 Jan 31, 2009 06:45 PST 

In non-programming-related news, I finished Terry Pratchett's "Nation."
As usual, a great book by Pratchett. Very different from most of his,
though. I got the feeling that he may have been facing his own
(everyone's) mortality as he wrote it.

    http://www.amazon.com/exec/obidos/ASIN/0061433012/vbhelper/

See my other favorite books at http://www.BooksToKeep.com.
Rod

Have a great week and thanks for subscribing!

Rod
RodSte-@vb-helper.com
----------
*** Now Available ***

Beginning Database Design Solutions
http://www.amazon.com/exec/obidos/ASIN/0470385499/vbhelper/

Visual Basic 2008 Programmer's Reference
http://www.amazon.com/exec/obidos/ASIN/0470182628/vbhelper/
==========

    VB.NET Contents:
1. Updated HowTo: Make a drawing application in VB .NET
2. New HowTo: Let the user click to draw markers on a map in Visual
Basic 2005
==========
++++++++++
<VB.NET>
++++++++++
==========
1. Updated HowTo: Make a drawing application in VB .NET
http://www.vb-helper.com/howto_net_drawing_framework.html
http://www.vb-helper.com/HowTo/howto_net_drawing_framework.zip

This is a very complex application so its Web page only describes key
points. This newsletter entry only describes the new feature I just
added. Go to http://www.vb-helper.com/howto_net_drawing_framework.html
for more information and to download the example.


To let the user move objects, the program looks for MouseMove events. If
the left button is down, the main form calls the picture's
MoveSelectedDrawableToMouse method to move the currently selected
Drawable. It then invalidates the picture to redraw it.


' If we have an object selected, move it.
Private Sub picCanvas_MouseMove(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.MouseEventArgs) Handles _
    picCanvas.MouseMove
    ' Only move if the left button is down.
    If e.Button = Windows.Forms.MouseButtons.Left Then
        ' Move it.
        m_Picture.MoveSelectedDrawableToMouse(e.X, e.Y)

        ' Redraw to show the new position.
        picCanvas.Invalidate()
    End If
End Sub


The DrawablePicture's MoveSelectedDrawableToMouse method exits if no
Drawable is selected.

If an object is selected, the program calculates the distance the mouse
has been moved and calls the selected Drawable's MoveRelative method to
move it by a corresponding amount. It then saves the new mouse position
for future moves.

(Note: The mouse's position is saved in (m_SelectedMouseX,
m_SelectedMouseY) when a Drawable is selected so it is ready to move.)


' Move the selected drawable. The mouse has moved from
' (m_SelectedMouseX, m_SelectedMouseY) to (x, y).
Public Sub MoveSelectedDrawableToMouse(ByVal x As Integer, _
    ByVal y As Integer)
    ' Do nothing if nothing is selected.
    If SelectedDrawable Is Nothing Then Exit Sub

    ' See how far we want it moved.
    Dim new_dx As Integer = x - m_SelectedMouseX
    Dim new_dy As Integer = y - m_SelectedMouseY

    ' Move it.
    SelectedDrawable.MoveRelative(new_dx, new_dy)

    ' Save the new mouse position.
    m_SelectedMouseX = x
    m_SelectedMouseY = y
End Sub
==========
2. New HowTo: Let the user click to draw markers on a map in Visual
Basic 2005
http://www.vb-helper.com/howto_2005_marker_on_map.html
http://www.vb-helper.com/HowTo/howto_2005_marker_on_map.zip

The program declares a generic List(Of Rectangle) to hold information
about the markers.

When the user clicks on the map, the program adds a new Rectangle to the
list, placing it at the location the user clicked.

The map's Paint event handler loops through the markers drawing them.

Finally the Clear Markers button empties the list of markers.

Private m_Markers As New List(Of Rectangle)

' Add a marker.
Private Sub picMap_MouseClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles picMap.MouseClick
    Const WID As Integer = 7
    m_Markers.Add(New Rectangle(e.X - WID \ 2, e.Y - WID \ 2, WID, WID))

    ' Redraw.
    picMap.Invalidate()
End Sub

' Draw the markers.
Private Sub picMap_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles picMap.Paint
    For Each rect As Rectangle In m_Markers
        e.Graphics.FillEllipse(Brushes.Red, rect)
        e.Graphics.DrawEllipse(Pens.Black, rect)
    Next rect
End Sub

' Clear the markers.
Private Sub btnClearMarkers_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnClearMarkers.Click
    m_Markers.Clear()

    ' Redraw.
    picMap.Invalidate()
End Sub
==========
Archives:
    http://www.topica.com/lists/VBHelper
    http://www.topica.com/lists/VB6Helper
    http://www.topica.com/lists/VBNetHelper

Post questions at:
    http://www.topica.com/lists/VBHelperQA
	
 Previous Message All Messages Next Message 
  Check It Out!

  Topica Channels
 Best of Topica
 Art & Design
 Books, Movies & TV
 Developers
 Food & Drink
 Health & Fitness
 Internet
 Music
 News & Information
 Personal Finance
 Personal Technology
 Small Business
 Software
 Sports
 Travel & Leisure
 Women & Family

  Start Your Own List!
Email lists are great for debating issues or publishing your views.
Start a List Today!

© 2001 Topica Inc. TFMB
Concerned about privacy? Topica is TrustE certified.
See our Privacy Policy.