Welcome Guest!
 VB Helper
 Previous Message All Messages Next Message 
VB Helper Newsletter  Rod Stephens
 Jan 30, 2011 19:14 PST 

Have a great week and thanks for subscribing!

Rod
RodSte-@vb-helper.com

Twitter feeds:
    VBHelper
    CSharpHelper
----------
==========

    VB.NET Contents:
1. New HowTo: Let the user zoom and scroll a picture drawn by the
program in Visual Basic .NET
2. New HowTo: Make a second version of the kaleidoscope program in
Visual Basic .NET
==========
++++++++++
      <VB.NET>
++++++++++
==========
1. New HowTo: Let the user zoom and scroll a picture drawn by the
program in Visual Basic .NET
http://www.vb-helper.com/howto_net_zoom_big_bitmap.html
http://www.vb-helper.com/HowTo/howto_net_zoom_big_bitmap.zip

The program contains a Panel with AutoScale = true. Inside the Panel is
a PictureBox with SizeMode = AutoSize. The PictureBox contains a Bitmap
that displays the drawing.

The basic idea is simple. When the user selects a scale, the program
builds a Bitmap of the correct size. It makes a Graphics object to draw
on the Bitmap and uses its ScaleTransform method to make it draw
suitably scaled. The code then calls a drawing routine to make the
drawing. The drawing routine uses the same code at all scales and the
ScaleTransform call makes the result scale properly.

The following code shows the SetScale method that prepares the Bitmap,
makes the Graphics object, calls that object's ScaleTransform method,
and then calls DrawImage to do the drawing. The code is fairly
self-explanatory.

' Set the scale and redraw.
Private Sub SetScale(ByVal picture_scale As Single)
    ' Set the scale.
    PictureScale = picture_scale

    ' Make a Bitmap of the righ size.
    Bm = New Bitmap( _
        CInt(PictureScale * WorldWidth), _
        CInt(PictureScale * WorldHeight))

    ' Make a Graphics object for the Bitmap.
    ' (If you need to use this later, you can give it
    ' class scope so you don't need to make a new one.)
    Using gr As Graphics = Graphics.FromImage(Bm)
        ' Use a white background
        ' (so you can see where the picture is).
        gr.Clear(Color.White)

        ' Draw smoothly.
        gr.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.AntiAlias

        ' Scale.
        gr.ScaleTransform(PictureScale, PictureScale)

        ' Draw the image.
        DrawImage(gr)
    End Using

    ' Display the result.
    picCanvas.Image = Bm
End Sub

The following code shows the DrawImage method that draws the smiley
face.

' Draw the image in world coordinates.
Private Sub DrawImage(ByVal gr As Graphics)
    Dim rect As Rectangle

    rect = New Rectangle(10, 10, 80, 80)
    gr.FillEllipse(Brushes.LightGreen, rect)
    gr.DrawEllipse(Pens.Green, rect)

    rect = New Rectangle(40, 40, 20, 30)
    gr.FillEllipse(Brushes.LightBlue, rect)
    gr.DrawEllipse(Pens.Blue, rect)

    rect = New Rectangle(25, 30, 50, 50)
    gr.DrawArc(Pens.Red, rect, 20, 140)

    rect = New Rectangle(25, 25, 15, 20)
    gr.FillEllipse(Brushes.White, rect)
    gr.DrawEllipse(Pens.Black, rect)
    rect = New Rectangle(30, 30, 10, 10)
    gr.FillEllipse(Brushes.Black, rect)

    rect = New Rectangle(60, 25, 15, 20)
    gr.FillEllipse(Brushes.White, rect)
    gr.DrawEllipse(Pens.Black, rect)
    rect = New Rectangle(65, 30, 10, 10)
    gr.FillEllipse(Brushes.Black, rect)
End Sub

Notice that this code contains simple calls to drawing methods and
doesn't know anything about the scale at which it is drawing.
==========
2. New HowTo: Make a second version of the kaleidoscope program in
Visual Basic .NET
http://www.vb-helper.com/howto_net_kaleidoscope2.html
http://www.vb-helper.com/HowTo/howto_net_kaleidoscope2.zip

This is a revised version of the example <a
href="http://www.vb-helper.com/howto_net_kaleidoscope.html">Make a
kaleidoscope program in Visual Basic .NET</a>. This version works much
as the previous version except it uses an array of transformations to
draw.

When you click and draw on this program's form, the code draws other
curves related to yours. For example, it might draw a mirror image of
what you draw or it might repeat your drawing rotated by multiples of 30
degrees.

MouseDown, MouseMove, and MouseUp event handlers do most of the work.
The program stores drawing information in a List(Of List(Of Point)).
Each item in the list gives a list of points to draw to make a curve.
The MouseDown, MouseMove, and MouseUp event handlers create the lists of
Points.

The MouseMove event handler refreshes the program's PictureBox, which
uses the following event handler to draw your curves and the modified
versions.

' Draw the polylines.
Private Sub picCanvas_Paint(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles picCanvas.Paint
    e.Graphics.SmoothingMode = SmoothingMode.AntiAlias

    ' Make a list of transformations, starting with the identity.
    Dim matrices As New List(Of Matrix)()
    matrices.Add(New Matrix())

    ' Make transformation matrices for the selected style.
    Dim wid As Integer = picCanvas.ClientSize.Width
    Dim hgt As Integer = picCanvas.ClientSize.Height
    Dim src_rect As New Rectangle(0, 0, wid, hgt)
    If (mnuStyleReflectX.Checked OrElse mnuStyleReflectXY.Checked) Then
        ' Reflect across X axis.
        Dim pts As Point() = {New Point(wid, 0), New Point(0, 0), New
Point(wid, hgt)}
        Dim mat As New Matrix(src_rect, pts)
        matrices.Add(mat)
    End If
    If (mnuStyleReflectY.Checked OrElse mnuStyleReflectXY.Checked) Then
        ' Reflect across Y axis.
        Dim pts As Point() = {New Point(0, hgt), New Point(wid, hgt),
New Point(0, 0)}
        Dim mat As New Matrix(src_rect, pts)
        matrices.Add(mat)
    End If
    If (mnuStyleReflectXY.Checked) Then
        ' Reflect across X and Y axes.
        Dim pts As Point() = {New Point(wid, hgt), New Point(0, hgt),
New Point(wid, 0)}
        Dim mat As New Matrix(src_rect, pts)
        matrices.Add(mat)
    End If
    If (mnuStyleRotate2.Checked) Then
        ' Rotate 180 degrees.
        Dim mat As New Matrix()
        mat.RotateAt(180, New PointF(CSng(wid / 2), CSng(hgt / 2)))
        matrices.Add(mat)
    End If
    If (mnuStyleRotate4.Checked) Then
        ' Rotate 90 degrees three times.
        For i As Integer = 1 To 3
            Dim mat As New Matrix()
            mat.RotateAt(i * 90, New PointF(CSng(wid / 2), CSng(hgt /
2)))
            matrices.Add(mat)
        Next i
    End If
    If (mnuStyleRotate8.Checked) Then
        ' Rotate 45 degrees seven times.
        For i As Integer = 1 To 7
            Dim mat As New Matrix()
            mat.RotateAt(i * 45, New PointF(CSng(wid / 2), CSng(hgt /
2)))
            matrices.Add(mat)
        Next i
    End If

    ' Loop through all of the transformations.
    For Each mat As Matrix In matrices
        e.Graphics.Transform = mat
        For Each pline As List(Of Point) In Polylines
            e.Graphics.DrawLines(Pens.Blue, pline.ToArray())
        Next pline
    Next mat
End Sub

The code makes a List(Of Matrix) to store transformation matrices. It
initializes the list by adding the identity transformation, a
transformation that leaves the drawing unchanged. Then depending on the
kaleidoscope style you selected from the program's menu, the code adds
other transformation matrices to the list.

After is has made a list of transformations, the program loops through
them. For each transformation, the program loops through the List(Of
List(Of Point)) connecting the points to draw the curves you made. The
result is several transformed copies of your curves, making a
kaleidoscopic result.
==========
Archives:
    http://www.topica.com/lists/VBHelper
    http://www.topica.com/lists/VB6Helper
    http://www.topica.com/lists/VBNetHelper

Twitter feeds:
    VBHelper
    CSharpHelper

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.