Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake ListBox and TextBox extension methods that set tab stops in Visual Basic .NET
DescriptionThis example shows how to make ListBox and TextBox extension methods that set tab stops in Visual Basic .NET.
KeywordsListBox, TextBox, set tabs, tabs, tab stops, set tab stops, Visual Basic .NET, VB.NET
CategoriesControls, Controls, Software Engineering
 

This example uses the following code to define extension methods that set tab stops for ListBox and TextBox controls.

 
Imports System.Runtime.InteropServices
Imports System.Runtime.CompilerServices

Module ListBoxExtensions
    ' Set tab stops inside a ListBox.
    <Extension()> _
    Public Sub SetTabs(ByVal lst As ListBox, ByVal tabs As _
        IList(Of Integer))
        ' Make sure the control will use them.
        lst.UseTabStops = True
        lst.UseCustomTabOffsets = True

        ' Get the control's tab offset collection.
        Dim offsets As ListBox.IntegerCollection = _
            lst.CustomTabOffsets

        ' Define the tabs.
        For Each tab As Integer In tabs
            offsets.Add(tab)
        Next tab
    End Sub

    <DllImport("user32.dll", SetLastError:=True, _
        CharSet:=CharSet.Auto)> _
    Private Function SendMessage(ByVal hWnd As IntPtr, ByVal _
        Msg As UInteger, ByVal wParam As Integer, ByVal _
        lParam As Integer()) As IntPtr
    End Function

    Private Const EM_SETTABSTOPS As Integer = &HCB

    ' Set tab stops inside a TextBox.
    <Extension()> _
    Public Sub SetTabs(ByVal txt As TextBox, ByVal tabs As _
        Integer())
        SendMessage(txt.Handle, EM_SETTABSTOPS, tabs.Length, _
            tabs)
    End Sub
End Module
 
The main program uses the following code to set tab stops for a ListBox and a TextBox.
 
lstCars.SetTabs(New Integer() {120, 170, 220})
txtCars.SetTabs(New Integer() {120, 170, 220})
 
 
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated