Welcome Guest!
 VB Helper
 Previous Message All Messages Next Message 
VB Helper Newsletter  Rod Stephens
 Dec 28, 2008 12:20 PST 

I don't remember if I mentioned this book excerpt. It came out a while
ago but I didn't see it on my Online Articles page
(http://www.vb-helper.com/online_articles.html).

    DevX: Book Excerpt: Visual Basic 2005 with .NET 3.0 Programmer's
Reference
    http://www.devx.com/dotnet/Article/37432
    March 12, 2008

    This chapter explains how to print in .NET. It was written for
Visual Basic 2005 with the .NET Framework 3.0 but works with other
versions, too.

It's a good explanation of printing in Visual Basic .NET.
-----
Happy Holidays!

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/
==========

    VB6 Contents:
1. New HowTo: Randomize a list of names in Visual Basic 6

    VB.NET Contents:
2. New HowTo: List information about the files in a directory in a
ListView using Visual Basic 2005
3. New HowTo: Set another application's size and position in Visual
Basic 2008
4. New HowTo: Overlay one picture on another in Visual Basic 2008
5. New HowTo: Make a line control in Visual Basic 2005

    Both Contents:
6. New Links
==========
++++++++++
   <VB6>
++++++++++
==========
1. New HowTo: Randomize a list of names in Visual Basic 6
http://www.vb-helper.com/howto_radomize_name_list.html
http://www.vb-helper.com/HowTo/howto_radomize_name_list.zip

I recently used this program to select random people to receive free
books.

Enter the list of names that you want to randomize in the Split
statement.

The program uses Split to break the names apart and put them in an
array. It then randomizes the array.

(For each position i in the array except the last one, the program
randomly picks an index j between i and the end of the array. It then
swaps the item at position j into position i.)

The program then displays the list in its randomized order.

Private Sub cmdRandomize_Click()
Dim names() As String
Dim i As Integer
Dim j As Integer
Dim tmp As String
Dim txt As String

    ' Put the names in an array.
    names = Split("Alice;Ben;Cindy;Dan;Erica;Frank", ";")

    ' Randomize the array.
    Randomize
    For i = LBound(names) To UBound(names) - 1
        ' Pick a random entry.
        j = Int((UBound(names) - i + 1) * Rnd + i)

        ' Swap the names.
        tmp = names(i)
        names(i) = names(j)
        names(j) = tmp
    Next i
    
    ' Display the results.
    For i = LBound(names) To UBound(names)
        txt = txt & vbCrLf & i & ": " & names(i)
    Next i
    txt = Mid$(txt, Len(vbCrLf) + 1)

    txtResults.Text = txt
End Sub

To pick N names from the list, simply use the first N as they are
presented randomly.
==========
++++++++++
<VB.NET>
++++++++++
==========
2. New HowTo: List information about the files in a directory in a
ListView using Visual Basic 2005
http://www.vb-helper.com/howto_2005_list_file_info.html
http://www.vb-helper.com/HowTo/howto_2005_list_file_info.zip

The program uses My.Computer.FileSystem.GetFiles to list the files in
the directory. For each file name, it uses
My.Computer.FileSystem.GetFileInfo to get a FileInfo object for the
file. It uses that object to get the file's size, creation date, and
last modification date.

Private Sub btnListFiles_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnListFiles.Click
    lvwFileInfo.Items.Clear()

    For Each file_name As String In
My.Computer.FileSystem.GetFiles(txtDirectory.Text)
        Dim file_info As System.IO.FileInfo = _
            My.Computer.FileSystem.GetFileInfo(file_name)

        Dim new_item As ListViewItem = _
            lvwFileInfo.Items.Add(file_name)
        new_item.SubItems.Add(file_info.Length)
        new_item.SubItems.Add(file_info.CreationTime.ToString())
        new_item.SubItems.Add(file_info.LastWriteTime.ToString())
    Next file_name
End Sub
==========
3. New HowTo: Set another application's size and position in Visual
Basic 2008
http://www.vb-helper.com/howto_2008_position_other_app.html
http://www.vb-helper.com/HowTo/howto_2008_position_other_app.zip

(While writing books, there is a maximum size that an image should be. I
wrote this program to make it easy to set an example program to exactly
that size.)

The program uses FindWindow to find the target application's handle.
Unfortunately this means that you must type the target application's
form caption exactly.

After finding the target's handle, the program passes it to the
SetWindowPos API function to set the target's size and position.

Imports System.Runtime.InteropServices

Public Class Form1
    Public Const SWP_NOSIZE As Int32 = &H1
    Public Const SWP_NOMOVE As Int32 = &H2

    Public Declare Function SetWindowPos Lib "user32.dll" (ByVal hWnd As
IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Int32, ByVal Y As
Int32, ByVal cx As Int32, ByVal cy As Int32, ByVal uFlags As Int32) As
Boolean
    Private Declare Auto Function FindWindow Lib "user32" (ByVal
lpClassName As String, ByVal lpWindowName As String) As IntPtr

    Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGo.Click
        Dim target_hwnd As Long = FindWindow(vbNullString,
txtAppName.Text)
        Dim x As Int32 = Val(txtXmin.Text)
        Dim y As Int32 = Val(txtYmin.Text)
        Dim cx As Int32 = Val(txtWidth.Text)
        Dim cy As Int32 = Val(txtHeight.Text)
        SetWindowPos(target_hwnd, 0, x, y, cx, cy, 0)
    End Sub
End Class
==========
4. New HowTo: Overlay one picture on another in Visual Basic 2008
http://www.vb-helper.com/howto_2008_overlay_picture.html
http://www.vb-helper.com/HowTo/howto_2008_overlay_picture.zip

The program overlays one picture over another. The places where the
foreground image should be transparent are drawn in red.

The program makes a new Bitmap and copies the foreground image into it.
It then calls the Bitmap's MakeTransparent method to make the Bitmap's
red pixels transparent.

Next the program creates a Bitmap to hold the result. It copies the
background image into it, copies the foreground image on top, and then
displays the result.
' Overlay the non-red parts of the foreground image on top of the
background image.
Private Sub btnOverlay_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOverlay.Click
    ' Copy the foreground image into a bitmap.
    Dim fg_wid As Integer = picForeground.Image.Width
    Dim fg_hgt = picForeground.Image.Height
    Dim fg_bm As New Bitmap(fg_wid, fg_hgt)
    Using gr As Graphics = Graphics.FromImage(fg_bm)
        gr.DrawImage(picForeground.Image, 0, 0, fg_wid, fg_hgt)
    End Using

    ' Make the red pixels transparent.
    fg_bm.MakeTransparent(Color.Red)

    ' Make the result bitmap.
    Dim bg_wid As Integer = picBackground.Image.Width
    Dim bg_hgt = picBackground.Image.Height
    Dim bg_bm As New Bitmap(bg_wid, bg_hgt)
    Dim cx As Integer = (bg_wid - fg_wid) \ 2
    Dim cy As Integer = (bg_hgt - fg_hgt) \ 2
    Using gr As Graphics = Graphics.FromImage(bg_bm)
        gr.DrawImage(picBackground.Image, 0, 0, bg_wid, bg_hgt)

        ' Draw the foreground image on top.
        gr.DrawImage(fg_bm, cx, cy, fg_wid, fg_hgt)
    End Using

    ' Display the result.
    picResult.Image = bg_bm

    ' We don't need the foreground bitmap any more.
    fg_bm.Dispose()
End Sub
==========
5. New HowTo: Make a line control in Visual Basic 2005
http://www.vb-helper.com/howto_2005_line_control.html
http://www.vb-helper.com/HowTo/howto_2005_line_control.zip

Thanks to Mike for contributing this. Here's his description:

    I've created a line control that I thought you might like to add to
the VB-Helper site and newsletter. I have an application that requires
some simple graphics capability. I'm not ready to convert the whole
thing to WPF and the line shape control in the Visual Basic Power Pack
lacks line segments. So, I created my own line segment control. It
features all of the capabilities of the line shape control in the Power
Pack plus it features the methods AddPoint() and DeletePoint().

    The AddPoint() method has a couple of overloads. If you call it
with no parameters and the mouse is over the line, then it will add a
point on the line under the mouse. You can also pass the point to it
explicitly.

    The DeletePoint() method also has a couple of overloads. If you
call it with no parameters, then it will remove the point on the line
that is closest to the mouse. You can also explicitly pass the point
that you want deleted.

    The control has code built in to it to allow the user to drag the
points around to reshape the line at runtime.

See the code for details.
==========
++++++++++
<Both>
++++++++++
==========
6. New Links
http://www.vb-helper.com/links.html

Intertech.com
http://www.intertech.com
Instructor-led training on VB.NET and other .NET technologies such as
WPF, C#, and Silverlight.

Nordicaccess
http://www.nordicaccess.com
A dozen or so Visual Basic examples and videos.

Mr. Bool
http://www.mrbool.com
A bunch of short, free video tutorials (around 15 minutes each) on
Visual Basic, C#, etc.
==========
Archives:
    http://www.topica.com/lists/VBHelper
    http://www.topica.com/lists/VB6Helper
    http://www.topica.com/lists/VBNetHelper
    
http://www.vb-helper.com/cgi-bin/mojo/mojo.cgi?flavor=archive&list=VB_Helper_Newsletter


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.