Welcome Guest!
 VB Helper
 Previous Message All Messages Next Message 
VB Helper Newsletter  Rod Stephens
 May 30, 2009 06:43 PDT 

Just a short one this week.

Have a great week and thanks for subscribing!

Rod
RodSte-@vb-helper.com

Books To Keep: http://www.BooksToKeep.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: Let the user move and resize controls at run time in
Visual Basic 6

    VB.NET Contents:
2. New HowTo: Manage the wastebasket in Visual Basic .NET
3. New HowTo: Use My.Computer.Info to display operating system and
memory information in Visual Basic .NET

    Both Contents:
4. New Links
==========
++++++++++
   <VB6>
++++++++++
==========
1. New HowTo: Let the user move and resize controls at run time in
Visual Basic 6
http://www.vb-helper.com/howto_move_resize_at_runtime.html
http://www.vb-helper.com/HowTo/howto_move_resize_at_runtime.zip

This example is from my book:

    Custom Control Library
    http://www.vb-helper.com/ccl.htm

This book includes 101 custom ActiveX controls written for Visual Basic
5 and 6.

This example builds an ActiveX control that allows the user to move and
resize the control at run time. It automatically resizes the control it
contains to fit.

Note that I don't necessarily recommend this strategy. Users will
eventually do something silly like give a control zero size or move it
off the form so be sure you have a way to reset the controls if
necessary.

The UserControl contains a small PictureBox named Corner in its lower
right corner. That control tracks its MouseDown, MouseMove, and MouseUp
events. As you drag that control, the following code resizes the
UserControl, puts Corner back in the lower right corner, and resizes
contained controls to fit.

Private Sub UserControl_Resize()
Dim hgt As Single
Dim ctl As Control

    ' Do nothing at design time.
    If Not Ambient.UserMode Then Exit Sub
    
    ' Position the corner dragger.
    hgt = ScaleHeight - m_HandleSize
    If hgt < 1 Then hgt = 1
    Corner.Move ScaleWidth - m_HandleSize, _
        hgt, m_HandleSize, m_HandleSize
    
    ' Position the contained controls.
    For Each ctl In ContainedControls
        ctl.Move 0, 0, ScaleWidth, hgt
    Next ctl
End Sub

The UserControl arranges the controls it contains so there is a small
gap at the bottom. That lets the UserControl show through and lets you
see the Corner PictureBox.

The UserControl tracks MouseDown, MouseMove, and MouseUp events on its
own surface, too. When you click and drag on the UserControl, the code
figures out where the control should be and calls Extender.Move to move
the UserControl appropriately.

The control also includes routines to save and restore size and position
in the Registry so the program can easily keep its size and position
between program runs.

See the code for additional details.
==========
++++++++++
<VB.NET>
++++++++++
==========
2. New HowTo: Manage the wastebasket in Visual Basic .NET
http://www.vb-helper.com/howto_net_move_file_to_wastebasket.html
http://www.vb-helper.com/HowTo/howto_net_move_file_to_wastebasket.zip

This example uses interop methods to define functions in DLLs so it
imports the System.Runtime.InteropServices namespace.

It then declares the SHQueryRecycleBin and SHEmptyRecycleBin API
functions, and the structures they need.

<StructLayout(LayoutKind.Sequential, Pack:=1)> _
Public Structure SHQUERYRBINFO
    Dim cbSize As Int32
    Dim i64Size As Long
    Dim i64NumItems As Long
End Structure

<DllImport("shell32.dll")> _
Private Shared Function SHQueryRecycleBin(ByVal pszRootPath As String,
ByRef ptSHQueryRBInfo As SHQUERYRBINFO) As Int32
End Function

Private Enum RecycleFlags As Int32
    SHERB_NOCONFIRMATION = &H1
    SHERB_NOPROGRESSUI = &H2
    SHERB_NOSOUND = &H4
End Enum

<DllImport("shell32.dll")> _
Private Shared Function SHEmptyRecycleBin(ByVal hwnd As IntPtr, ByVal
pszRootPath As String, ByVal dwFlags As RecycleFlags) As Int32
End Function

Every second a timer executes the following code. It uses the
SHQueryRecycleBin function to see how many files are in the recycle bin
and how much space they occupy.

Private Sub tmrCheckBin_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmrCheckBin.Tick
    Static had_error As Boolean = False
    If had_error Then Exit Sub

    Try
        Dim info As SHQUERYRBINFO
        info.cbSize = Len(info)
        SHQueryRecycleBin(Nothing, info)
        lblNumItems.Text = info.i64NumItems & " items (" & info.i64Size
& " bytes)"
    Catch ex As Exception
        had_error = True
        MessageBox.Show("Error getting wastebasket information" & vbCrLf
& ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub

When you click the Delete File button, the following code executes. It
examines the form's radio buttons to see whether it should permanently
delete the file or move it to the wastebasket. It examines the
chkConfirmDelete check box to see if it should make the user confirm the
deletion.

The code then calls My.Computer.FileSystem.DeleteFile to delete the
file. (This part of the program is purely .NET. Too bad there aren't
similar methods for checking the wastebasket's size and emptying it.)

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDelete.Click
    Dim opt_recycle As FileIO.RecycleOption
    If radDeletePermanently.Checked Then
        opt_recycle = FileIO.RecycleOption.DeletePermanently
    Else
        opt_recycle = FileIO.RecycleOption.SendToRecycleBin
    End If

    Dim opt_confirm As FileIO.UIOption
    If chkConfirmDelete.Checked Then
        opt_confirm = FileIO.UIOption.AllDialogs
    Else
        opt_confirm = FileIO.UIOption.OnlyErrorDialogs
    End If

    Try
        My.Computer.FileSystem.DeleteFile( _
            txtFile.Text, opt_confirm, opt_recycle)
    Catch ex As Exception
        MessageBox.Show("Error deleting file" & vbCrLf & ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try

    MakeDummyFile()
End Sub

When you click the Empty Wastebasket button, the following code
executes. The code sets appropriate options to optionally display a
progress bar, play the recycling sound, and ask the user for
confirmation. It then calls the SHEmptyRecycleBin API function to empty
the wastebasket.

Private Sub btnEmpty_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEmpty.Click
    Dim options As RecycleFlags = 0

    If Not chkProgress.Checked Then options = options Or
RecycleFlags.SHERB_NOPROGRESSUI
    If Not chkPlaySound.Checked Then options = options Or
RecycleFlags.SHERB_NOSOUND
    If Not chkConfirmEmpty.Checked Then options = options Or
RecycleFlags.SHERB_NOCONFIRMATION

    Try
        SHEmptyRecycleBin(Nothing, Nothing, options)
    Catch ex As Exception
        MessageBox.Show("Error emptying wastebasket" & vbCrLf &
ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub

Unfortunately the SHEmptyRecycleBin function seems to ignore some of
these parameters and does play the recycling sound or display a progress
dialog for me. If you figuer out how to fix this, <A
HREF="mailto:RodSte-@vb-helper.com">please let me know</A>.
==========
3. New HowTo: Use My.Computer.Info to display operating system and
memory information in Visual Basic .NET
http://www.vb-helper.com/howto_net_computer_info.html
http://www.vb-helper.com/HowTo/howto_net_computer_info.zip

When the program loads, it uses the following code to display system
information available in My.Computer.Info.

lblOSFullName.Text = My.Computer.Info.OSFullName
lblOSPlatform.Text = My.Computer.Info.OSPlatform
lblOSVersion.Text = My.Computer.Info.OSVersion
lblTotPhys.Text = FormatNumber(My.Computer.Info.TotalPhysicalMemory, 0)
& " bytes"
lblTotVirt.Text = FormatNumber(My.Computer.Info.TotalVirtualMemory, 0) &
" bytes"
lblAvailPhys.Text =
FormatNumber(My.Computer.Info.AvailablePhysicalMemory, 0) & " bytes"
lblAvailVirt.Text =
FormatNumber(My.Computer.Info.AvailableVirtualMemory, 0) & " bytes"

See also "Get day, month, date, time, and number format information for
the computer's locale in Visual Basic 2005"
(howto_2005_locale_date_info.html), which uses
My.Computer.Info.InstalledUICulture to get date and time format
information.

==========
++++++++++
<Both>
++++++++++
==========
4. New Links
http://www.vb-helper.com/links.html

CodeRush Xpress for C# and VB
http://www.devexpress.com/Products/Visual_Studio_Add-in/CodeRushX
A tool that adds a bunch of refactoring and software development
features to the IDE including: duplicate lines, highlighting references,
create overload, reorder parameters, and much more. Big drawback:
doesn't support Visual Studio Express Editions. (Ironic since the word
"Xpress" is in this product's name.)

Refactor! Pro for Visual Studio
http://www.devexpress.com/Products/Visual_Studio_Add-in/Refactoring
Refactoring tools for Visual Studio including: case to conditional,
extract method, For to For Each, create setter, etc. $99.
==========
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.