Welcome Guest!
 VB.NET Helper
 Previous Message All Messages Next Message 
VB .NET Helper Newsletter  Rod Stephens
 Nov 28, 2011 08:39 PST 

Two quick notes.

O'Reilly is having a one-day CyberMonday Sale: 60% off 60 top ebooks
including my book "Start Here! Fundamentals of Microsoft .NET
Programming." Shop at http://bit.ly/s3vkkJ

I've also received no solutions yet for the "find the triangles" puzzles
so I'm going to wait another week before posting my solutions. See the
puzzles at:

    Puzzle: find the equilateral triangles in Visual Basic 6

    Puzzle: find the equilateral triangles in Visual Basic .NET
Beginning Database Design Solutions

    A good database design doesn't guarantee success, but a bad one
guarantees failure.
Have a great week and thanks for subscribing!


Twitter feeds:

    VB.NET Contents:
1. New HowTo: Copy part of an image into a new PictureBox in Visual
Basic .NET
1. New HowTo: Copy part of an image into a new PictureBox in Visual
Basic .NET

When you enter top, left, width, and height values and click the Copy
button, the program uses the following code to copy part of the image on
the left and display it on the right.

' Copy part of the original image.
Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCopy.Click
    Dim top As Integer = Integer.Parse(txtTop.Text)
    Dim left As Integer = Integer.Parse(txtLeft.Text)
    Dim width As Integer = Integer.Parse(txtWidth.Text)
    Dim height As Integer = Integer.Parse(txtHeight.Text)

    ' Make a Bitmap to hold the result.
    Dim bm As New Bitmap(width, height)

    ' Associate a Graphics object with the Bitmap
    Using gr As Graphics = Graphics.FromImage(bm)
        ' Define source and destination rectangles.
        Dim src_rect As New Rectangle(left, top, width, height)
        Dim dst_rect As New Rectangle(0, 0, width, height)

        ' Copy that part of the image.
        gr.DrawImage(picOriginal.Image, dst_rect, src_rect,
    End Using

    ' Display the result.
    picResult.Image = bm
End Sub

This code starts by getting the values you entered and making a Bitmap
to hold the result. It then makes a Graphics object associated with the

It defines a source Rectangle to indicate the part of the original image
that should be copied and a destination Rectangle to indicate where that
part of the image should be drawn in the new Bitmap. It then calls the
Graphics object's DrawImage method to copy that part of the image.

The code finishes by displaying the new Bitmap in the PictureBox named

Twitter feeds:

Post questions at:
 Previous Message All Messages Next Message 
  Check It Out!

  Topica Channels
 Best of Topica
 Art & Design
 Books, Movies & TV
 Food & Drink
 Health & Fitness
 News & Information
 Personal Finance
 Personal Technology
 Small Business
 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.