Sabtu, 03 Maret 2012

SQL SERVER CLASS

PREVIEW :

DOWNLOAD CONTOH PROJECT 




























CLASS :

Imports System.Data.SqlClient

Public Class clsSQL

    Public Enum XmlType As Short
        Normal = 0
        Schema = 1
    End Enum

    Private m_StrConnectionString As String = String.Empty
    Private m_Tag As String = String.Empty

    Public Event OnError(ByVal strProced As String, ByVal objEx As Exception)

    Public Sub New(ByVal strConnectionString As String)
        m_StrConnectionString = strConnectionString
    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub

    Public ReadOnly Property About() As String
        Get
            Return "KABEH WONG BAKAL MATI" & vbNewLine & _
                   "GARI OPO SING AREP DITINGGAL" & vbNewLine & _
                   "ORA USAH NGAREP WONG ELING MARANG TINGGALANE DEWE" & vbNewLine & _
                   "NGAREPO PENGERAN BAKAL NOMPO" & vbNewLine & _
                   "MUNG KUI SING GAWE MESEM NALIKO SEDO"
        End Get
    End Property

    Public Property ConnectionString() As String
        Get
            Return m_StrConnectionString
        End Get
        Set(ByVal strValue As String)
            m_StrConnectionString = strValue
        End Set
    End Property

    Public Property Tag() As String
        Get
            Return m_Tag
        End Get
        Set(ByVal strValue As String)
            m_Tag = strValue
        End Set
    End Property

    Public Function TestConnection() As Boolean
        Try
            Dim objConnection As New SqlConnection(m_StrConnectionString)
            objConnection.Open()

            Select Case objConnection.State
                Case ConnectionState.Broken, ConnectionState.Closed : TestConnection = False
                Case Else : TestConnection = True
            End Select

            objConnection.Close()
            objConnection.Dispose()
            objConnection = Nothing

        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function Execute(ByVal strQuery As String) As Boolean
        Try
            Dim objConnection As New SqlConnection(m_StrConnectionString)
            Dim objCommand = New SqlCommand(strQuery, objConnection)

            objConnection.Open()

            objCommand.ExecuteNonQuery()

            objConnection.Close()
            objConnection.Dispose()
            objConnection = Nothing
            objCommand = Nothing

            Return True

        Catch ex As Exception
            RaiseEvent OnError("Execute", ex)
            Return False
        End Try
    End Function

    Public Function ToDataReader(ByVal strQuery As String) As SqlDataReader
        Try
            Dim objDR As System.Data.SqlClient.SqlDataReader
            Dim objConnection As New SqlConnection(m_StrConnectionString)
            'Abre a coneção
            objConnection.Open()
            'Define o comando
            Dim objSqlCommand As New System.Data.SqlClient.SqlCommand(strQuery, objConnection)
            'Executa o reader
            objDR = objSqlCommand.ExecuteReader
            Return objDR
        Catch ex As Exception
            RaiseEvent OnError("KeDataReader", ex)
            Return Nothing
        End Try
    End Function

    Public Function ToDataSet(ByVal strQuery As String, _
                     Optional ByVal strTable As String = "") As DataSet
        Try
            Dim objConnection As New SqlConnection(m_StrConnectionString)
            'Cria o objecto
            Dim objCommand = New SqlCommand(strQuery, objConnection)
            Dim objDataSet As New DataSet
            'Cria o sql DataAdapter
            Dim objSqlDataAdapter As SqlDataAdapter = New SqlDataAdapter(objCommand)

            'Verifica se foi defenido a tabela
            If strTable = "" Then _
                 objSqlDataAdapter.Fill(objDataSet) _
            Else objSqlDataAdapter.Fill(objDataSet, strTable)

            objConnection.Close()
            objConnection.Dispose()

            objConnection = Nothing
            objCommand = Nothing

            Return objDataSet

        Catch ex As Exception
            RaiseEvent OnError("KeDataSet", ex)
            Return Nothing
        End Try
    End Function

    Public Function ToDataSetFromXML(ByVal strPath As String, _
                                     ByVal iXmlType As XmlType) As DataSet
        Try
            'Cria o objecto
            Dim objDataSet As New DataSet

            If iXmlType = XmlType.Normal Then
                objDataSet.ReadXml(strPath)
            ElseIf iXmlType = XmlType.Schema Then
                objDataSet.ReadXmlSchema(strPath)
            End If

            Return objDataSet

        Catch ex As Exception
            RaiseEvent OnError("KeDataSetFromXML", ex)
            Return Nothing
        End Try
    End Function

    Public Function ToXML(ByVal strQuery As String, _
                          ByVal strOutPut As String, _
                          ByVal iXmlType As XmlType, _
                 Optional ByVal strTable As String = "", _
                 Optional ByVal strNamespace As String = "", _
                 Optional ByVal strDataSetName As String = "") As Boolean
        Try
            Dim objDataSet As New DataSet

            Dim objConnection As New SqlConnection(m_StrConnectionString)
            Dim objCommand = New SqlCommand(strQuery, objConnection)
            Dim objSqlDataAdapter As SqlDataAdapter = New SqlDataAdapter(objCommand)

            If Not strNamespace = "" Then objDataSet.Namespace = strNamespace
            If Not strDataSetName = "" Then objDataSet.DataSetName = strDataSetName

            'Verifica se foi defenido a tabela
            If strTable = "" Then _
                 objSqlDataAdapter.Fill(objDataSet) _
            Else objSqlDataAdapter.Fill(objDataSet, strTable)

            If iXmlType = XmlType.Normal Then
                objDataSet.WriteXml(strOutPut)
            ElseIf iXmlType = XmlType.Normal Then
                objDataSet.WriteXmlSchema(strOutPut)
            End If

            objConnection.Close()
            objDataSet.Dispose()
            objConnection.Dispose()

            objConnection = Nothing
            objCommand = Nothing
            objDataSet = Nothing

            Return True

        Catch ex As Exception
            RaiseEvent OnError("KEXML", ex)
            Return False
        End Try
    End Function

    Public Function ToDataGrid(ByVal objDataGrid As DataGridView, _
                               ByVal strQuery As String, _
                      Optional ByVal strTable As String = "") As Boolean
        Try
            Dim objConnection As New SqlConnection(m_StrConnectionString)
            Dim objCommand = New SqlCommand(strQuery, objConnection)
            Dim objSqlDataAdapter As SqlDataAdapter = New SqlDataAdapter(objCommand)
            Dim objDataSet As New DataSet

            'Verifica se foi defenido a tabela
            If strTable = "" Then _
                 objSqlDataAdapter.Fill(objDataSet) _
            Else objSqlDataAdapter.Fill(objDataSet, strTable)

            objDataGrid.DataSource = objDataSet.Tables(0)

            objConnection.Close()
            objConnection.Dispose()
            objDataSet.Dispose()

            objConnection = Nothing
            objCommand = Nothing
            objDataSet = Nothing

            Return True

        Catch ex As Exception
            RaiseEvent OnError("KEDataGrid", ex)
            Return False
        End Try

    End Function

    Public Function ToListView(ByVal objListView As ListView, _
                               ByVal strQuery As String, _
                      Optional ByVal strTable As String = "", _
                      Optional ByVal intDefautColumSize As Integer = 100) As Boolean
        Try
            Dim objConnection As New SqlConnection(m_StrConnectionString)
            Dim objCommand = New SqlCommand(strQuery, objConnection)
            Dim objSqlDataAdapter As SqlDataAdapter = New SqlDataAdapter(objCommand)
            Dim objDataSet As New DataSet

            'Verifica se foi defenido a tabela
            If strTable = "" Then _
                 objSqlDataAdapter.Fill(objDataSet) _
            Else objSqlDataAdapter.Fill(objDataSet, strTable)

            If objDataSet.Tables(0).Rows.Count > 0 Then
                objListView.Items.Clear()
                objListView.Columns.Clear()
                Dim i, y As Integer
                Dim intColCount As Integer
                intColCount = objDataSet.Tables(0).Columns.Count - 1
                'Adiciona as colunas
                For i = 0 To intColCount
                    objListView.Columns.Add(objDataSet.Tables(0).Columns(i).ToString, intDefautColumSize)
                Next
                'Adiciona os registos
                Dim objLVWItem As ListViewItem
                For i = 1 To objDataSet.Tables(0).Rows.Count - 1
                    'Tem em conta valores NULL
                    If Not IsDBNull(objDataSet.Tables(0).Rows.Item(i).Item(0)) Then _
                         objLVWItem = objListView.Items.Add(objDataSet.Tables(0).Rows.Item(i).Item(0).ToString) _
                    Else objLVWItem = objListView.Items.Add("")
                    'Tem em conta valores NULL
                    For y = 1 To intColCount
                        If Not IsDBNull(objDataSet.Tables(0).Rows.Item(i).Item(y).ToString) Then _
                             objLVWItem.SubItems.Add(objDataSet.Tables(0).Rows.Item(i).Item(y).ToString) _
                        Else objLVWItem.SubItems.Add("")
                    Next
                Next
            End If

            objConnection.Close()
            objDataSet.Dispose()
            objConnection.Dispose()
            objSqlDataAdapter.Dispose()

            objCommand = Nothing
            objDataSet = Nothing
            objConnection = Nothing
            objSqlDataAdapter = Nothing

            Return True

        Catch ex As Exception
            RaiseEvent OnError("KeListView", ex)
            Return False
        End Try
    End Function

    Public Function ToTextBox(ByVal objTextBox As TextBox, _
                              ByVal strQuery As String, _
                     Optional ByVal strTable As String = "", _
                     Optional ByVal intSepTabs As Integer = 1) As Boolean
        Try
            Dim objConnection As New SqlConnection(m_StrConnectionString)
            Dim objCommand = New SqlCommand(strQuery, objConnection)
            Dim objSqlDataAdapter As SqlDataAdapter = New SqlDataAdapter(objCommand)
            Dim objDataSet As New DataSet

            'Verifica se foi defenido a tabela
            If strTable = "" Then _
                 objSqlDataAdapter.Fill(objDataSet) _
            Else objSqlDataAdapter.Fill(objDataSet, strTable)

            Dim strTabs As String = String.Empty
            Dim strTemp As String = String.Empty
            Dim x As Integer

            For x = 1 To intSepTabs
                strTabs &= vbTab
            Next

            If objDataSet.Tables(0).Rows.Count > 0 Then
                Dim i, y As Integer
                Dim intColCount As Integer

                objTextBox.Text = ""

                intColCount = objDataSet.Tables(0).Columns.Count - 1
                'Adiciona as colunas
                For i = 0 To intColCount
                    strTemp &= objDataSet.Tables(0).Columns(i).ToString & strTabs
                Next
                strTemp &= vbNewLine
                'For i = 0 To intColCount
                '    strTemp &= "---" & strTabs & vbTab
                'Next
                strTemp &= vbNewLine

                'Adiciona os registos
                For i = 1 To objDataSet.Tables(0).Rows.Count - 1
                    'Tem em conta valores NULL
                    If Not IsDBNull(objDataSet.Tables(0).Rows.Item(i).Item(0)) Then _
                         strTemp &= objDataSet.Tables(0).Rows.Item(i).Item(0).ToString & strTabs _
                    Else strTemp &= " " & strTabs
                    'Tem em conta valores NULL
                    For y = 1 To intColCount
                        If Not IsDBNull(objDataSet.Tables(0).Rows.Item(i).Item(y).ToString) Then _
                             strTemp &= objDataSet.Tables(0).Rows.Item(i).Item(y).ToString & strTabs _
                        Else strTemp &= " " & strTabs
                    Next
                    strTemp &= vbNewLine
                Next
                objTextBox.Text = strTemp
            End If

            objConnection.Close()
            objDataSet.Dispose()
            objConnection.Dispose()
            objSqlDataAdapter.Dispose()

            objCommand = Nothing
            objDataSet = Nothing
            objConnection = Nothing
            objSqlDataAdapter = Nothing

            Return True

        Catch ex As Exception
            RaiseEvent OnError("KeListView", ex)
            Return False
        End Try

    End Function

End Class


PENGGUNAAN :


Public Class frmMain

    Private WithEvents mSQL As clsSQL

    Private Sub btnAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbout.Click
        If IsNothing(mSQL) Then
            mSQL = New clsSQL(txtConnString.Text.ToString)
        End If
        MsgBox(mSQL.About, MsgBoxStyle.Information)
    End Sub

    Private Sub SetIDE(ByVal oObject As Object)
        txtGrid1.Visible = False
        lstView1.Visible = False
        dgView1.Visible = False
        oObject.Visible = True
    End Sub

    Private Sub mSQL_OnError(ByVal strProced As String, ByVal objEx As System.Exception) Handles mSQL.OnError
        MsgBox(objEx.Message, MsgBoxStyle.Exclamation, strProced)
    End Sub

    Private Sub btnTestConn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTestConn.Click
        If Not IsNothing(mSQL) Then
            mSQL = Nothing
        End If

        mSQL = New clsSQL(txtConnString.Text.ToString)

        If mSQL.TestConnection Then
            MsgBox("Test Koneksi OK", MsgBoxStyle.Information)
            grpOp.Enabled = True
        Else
            MsgBox("Test Koneksi Gagal", MsgBoxStyle.Exclamation)
            grpOp.Enabled = False
        End If
        'Set object visible ..
        SetIDE(Me)
    End Sub

    Private Sub btnToDataGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToDataGrid.Click
        Try
            mSQL.ToDataGrid(dgView1, txtQuery.Text.ToString)
            'Set object visible ..
            SetIDE(dgView1)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnToListView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToListView.Click
        Try
            mSQL.ToListView(lstView1, txtQuery.Text.ToString)
            'Set object visible ..
            SetIDE(lstView1)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnToTextBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToTextBox.Click
        Try
            mSQL.ToTextBox(txtGrid1, txtQuery.Text.ToString)
            'Set object visible ..
            SetIDE(txtGrid1)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnExecute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExecute.Click
        Try
            If mSQL.Execute(txtQuery.Text.ToString) Then
                MsgBox("Perintah SQL Error.", MsgBoxStyle.Information)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnToXML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToXML.Click
        Dim strTemp As String
        Try
            ofdSave.FileName = "MASSEMAR"
            ofdSave.Filter = "SEMAR XML (*.xml)|*.xml"
            If Me.ofdSave.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
                strTemp = ofdSave.FileName
            Else
                Exit Sub
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try

        Try
            If mSQL.ToXML(txtQuery.Text.ToString, strTemp, clsSQL.XmlType.Normal) Then
                MsgBox("XML file exported with success.", MsgBoxStyle.Information)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnToDataReader_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToDataReader.Click
        Dim objDR As System.Data.SqlClient.SqlDataReader
        Try
            objDR = mSQL.ToDataReader(txtQuery.Text.ToString)

            Do While objDR.Read()
                txtGrid1.Text &= vbCrLf & objDR.Item(0)
            Loop

            objDR.Close()
            objDR = Nothing

            SetIDE(txtGrid1)

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnToDataSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToDataSet.Click
        Dim objDataSet As New DataSet
        Try
            objDataSet = mSQL.ToDataSet(txtQuery.Text.ToString)
            If Not IsNothing(objDataSet) Then

                txtGrid1.Text = "KeDataSet - " & objDataSet.Tables(0).Rows.Count & " row(s) affected"
                SetIDE(txtGrid1)

                objDataSet.Dispose()
                objDataSet = Nothing
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnToDataSetFromXML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToDataSetFromXML.Click
        Dim strTemp As String
        Try
            ofdOpen.FileName = "MASSEMAR"
            ofdOpen.Filter = "SEMAR XML (*.xml)|*.xml"
            If Me.ofdOpen.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
                strTemp = ofdOpen.FileName
            Else
                Exit Sub
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try

        Dim objDataSet As New DataSet
        Try
            objDataSet = mSQL.ToDataSetFromXML(strTemp, clsSQL.XmlType.Normal)
            If Not IsNothing(objDataSet) Then

                txtGrid1.Text = "KeDataSetFromXML - " & objDataSet.Tables(0).Rows.Count & " row(s) affected"
                SetIDE(txtGrid1)

                objDataSet.Dispose()
                objDataSet = Nothing
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

End Class


Jumat, 02 Maret 2012

Print Nota LX 300 vb 6

CLASS :

DOWNLOAD CONTOH PROJECT 



Option Explicit


Public Enum PrinterErrors
vbPE_CantOpenPrinter = 2000 ' Can't Open the printer device.
vbPE_CantStartJob ' Can't Start the print job.
vbPE_CantStartPage ' Can't start printing a page.
vbPE_UnSentBytes ' Some bytes were not successfully sent to the printer.
vbPE_KillDocFailed ' Could not cancel the print job.
vbPE_CantChangeName ' Can't change document name.
vbPE_FailedWrite ' Failed write to printer.
vbPE_ReadFileError ' Could not read from file.
vbPE_CantEndPage ' Call to end page failed.
vbPE_CantEndDoc ' Call to close doc failed.
vbPE_CantChangeDevice ' Can't change device while printing.
vbPE_CantCreateDC ' Can't create a device context.
End Enum

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)

Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
"OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
pDefault As Any) As Long

Private Declare Function StartDocPrinter Lib "winspool.drv" Alias _
"StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
pDocInfo As Any) As Long

Private Declare Function StartPagePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long

Private Declare Function ClosePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long

Private Declare Function EndDocPrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long

Private Declare Function EndPagePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long

Private Type DOC_INFO_1
pDocName As String
pOutputFile As String
pDatatype As String
End Type

Private Declare Function SetJob Lib "winspool.drv" Alias _
"SetJobA" (ByVal hPrinter As Long, ByVal JobId As Long, _
ByVal Level As Long, pJob As Any, _
ByVal Command As Long) As Long

Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Private Type JOB_INFO_1
JobId As Long
pPrinterName As String
pMachineName As String
pUserName As String
pDocument As String
pDatatype As String
pStatus As String
Status As Long
Priority As Long
Position As Long
TotalPages As Long
PagesPrinted As Long
Submitted As SYSTEMTIME
End Type

Private Const JOB_POSITION_UNSPECIFIED = 0

Private Declare Function GetJob Lib "winspool.drv" Alias "GetJobA" _
(ByVal hPrinter As Long, ByVal JobId As Long, ByVal Level As Long, _
pJob As Any, ByVal cdBuf As Long, pcbNeeded As Long) As Long

Private Const MAX_PRIORITY = 99
Private Const MIN_PRIORITY = 1
Private Const DEF_PRIORITY = 1


Private Declare Function WritePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long, pBuf As Any, _
ByVal cdBuf As Long, pcWritten As Long) As Long


Private Const JOB_CONTROL_PAUSE = 1
Private Const JOB_CONTROL_RESUME = 2
Private Const JOB_CONTROL_CANCEL = 3
Private Const JOB_CONTROL_RESTART = 4
Private Const JOB_CONTROL_DELETE = 5


Private lPrinter As Long ' Printer handle
Private lBytesWritten As Long ' Number of bytes written
Private lBytesSent As Long ' Number of bytes that should have been written.
Private lJob As Long ' Print job handle
Private sDocName As String ' Name of the document
Private sDeviceName As String ' Device name.

Private bJobStarted As Boolean ' Have we started a print job.

Public Sub NewPage()
If Not bJobStarted Then
NewDoc
Else
'end last page
If EndPagePrinter(lPrinter) <= 0 Then
Call EndDocPrinter(lPrinter)
Call ClosePrinter(lPrinter)
bJobStarted = False
Err.Raise vbPE_CantEndPage, "RAWPrinter", "Can't end page."
Exit Sub
End If

If StartPagePrinter(lPrinter) <= 0 Then
Call EndDocPrinter(lPrinter)
Call ClosePrinter(lPrinter)
bJobStarted = False
Err.Raise vbPE_CantStartPage, "RAWPrinter", "Can't start page."
Exit Sub
End If
End If
End Sub

Public Sub NewDoc(Optional DocName As String = "", Optional FileName As String = vbNullString)
Dim di As DOC_INFO_1

If bJobStarted Then
EndDoc
End If

If OpenPrinter(sDeviceName, lPrinter, ByVal 0&) <= 0 Then
Err.Raise vbPE_CantOpenPrinter, "RAWPrinter", "Can't Open Printer Device"
Exit Sub
End If

If DocName <> "" Then
sDocName = DocName
End If

di.pDocName = sDocName & vbNullChar
If FileName = vbNullString Then
di.pOutputFile = FileName
Else
di.pOutputFile = FileName & vbNullChar
End If
di.pDatatype = "RAW" & vbNullChar

lJob = StartDocPrinter(lPrinter, 1, di)

If lJob <= 0 Then
Call ClosePrinter(lPrinter)
Err.Raise vbPE_CantStartJob, "RAWPrinter", "Can't start print job."
Exit Sub
End If

If StartPagePrinter(lPrinter) <= 0 Then
Call EndDocPrinter(lPrinter)
Call ClosePrinter(lPrinter)
Err.Raise vbPE_CantStartPage, "RAWPrinter", "Can't start page."
Exit Sub
End If

lBytesWritten = 0
lBytesSent = 0
bJobStarted = True
End Sub

Public Sub KillDoc()
Dim b As Long

If bJobStarted Then
b = SetJob(lPrinter, lJob, 0, ByVal 0&, JOB_CONTROL_CANCEL)
Call EndPagePrinter(lPrinter)
Call EndDocPrinter(lPrinter)
Call ClosePrinter(lPrinter)
bJobStarted = False
Else
b = 0
End If

If b <= 0 Then
Err.Raise vbPE_KillDocFailed, "RAWPrinter", "Could not cancle the print job."
End If
End Sub

Public Sub EndDoc()
If Not bJobStarted Then
Exit Sub
End If

If EndPagePrinter(lPrinter) <= 0 Then
Call EndDocPrinter(lPrinter)
Call ClosePrinter(lPrinter)
bJobStarted = False
Err.Raise vbPE_CantEndPage, "RAWPrinter", "Can't end page."
Exit Sub
End If

If EndDocPrinter(lPrinter) <= 0 Then
Call ClosePrinter(lPrinter)
bJobStarted = False
Err.Raise vbPE_CantEndDoc, "RAWPrinter", "Can't end print job."
Exit Sub
End If

Call ClosePrinter(lPrinter)

bJobStarted = False

If lBytesWritten <> lBytesSent Then
Err.Raise vbPE_UnSentBytes, "RAWPrinter", "Some data was not sent to the printer."
End If
End Sub

Public Property Let DeviceName(Name As String)
If bJobStarted Then
Err.Raise vbPE_CantChangeDevice, "RAWPrinter", "Can't change device while printing."
Else
sDeviceName = Name
End If
End Property

Public Property Get DeviceName() As String
DeviceName = sDeviceName
End Property

'
' Bug... this doesn't work
'
Public Property Let DocumentName(DocName As String)
Dim di As JOB_INFO_1

If bJobStarted Then
di.pDocument = DocName & vbNullChar

If SetJob(lPrinter, lJob, 1, di, 0&) <= 0 Then
Err.Raise vbPE_CantChangeName, "RAWPrinter", "Failed to change document name."
Exit Property
End If
End If

sDocName = DocName
End Property

Public Property Get DocumentName() As String
DocumentName = sDocName
End Property

Public Sub PrintText(txt As String)
Dim i As Long

If Not bJobStarted Then
NewDoc
End If

lBytesSent = lBytesSent + Len(txt)

If WritePrinter(lPrinter, ByVal txt, Len(txt), i) = 0 Then
Call EndPagePrinter(lPrinter)
Call EndDocPrinter(lPrinter)
Call ClosePrinter(lPrinter)
bJobStarted = False
Err.Raise vbPE_FailedWrite, "RAWPrinter", "Failed write to printer."
Exit Sub
End If

lBytesWritten = lBytesWritten + i
End Sub

Public Sub PrintFile(fname As String)
Dim fh As Long
Dim Buffer As String
Dim fl As Long
Dim r As Long
Dim i As Long
Dim bs As Long

If Not bJobStarted Then
NewDoc
End If

fh = FreeFile(0)
bs = 8192
Buffer = String(bs, 0)

Open fname For Binary Access Read As fh
fl = LOF(fh)
r = 0

If fl = 0 Then
Close fh
Exit Sub
End If

Do
If fl - r < bs Then
bs = fl - r
Buffer = String(bs, 0)
End If

Get fh, , Buffer

lBytesSent = lBytesSent + bs
r = r + bs

If WritePrinter(lPrinter, ByVal Buffer, bs, i) = 0 Then
Call EndPagePrinter(lPrinter)
Call EndDocPrinter(lPrinter)
Call ClosePrinter(lPrinter)
bJobStarted = False
On Error GoTo 0
Err.Raise vbPE_FailedWrite, "RAWPrinter", "Failed write to printer."
Exit Sub
End If

lBytesWritten = lBytesWritten + i
Loop While r <> fl

Close fh
Exit Sub

PrintFileError:
On Error Resume Next

Call EndPagePrinter(lPrinter)
Call EndDocPrinter(lPrinter)
Call ClosePrinter(lPrinter)
bJobStarted = False
Close fh

On Error GoTo 0
Err.Raise vbPE_ReadFileError, "RAWPrinter", "Could not read from file."
End Sub

Private Sub Class_Initialize()
sDocName = "Cetak Nota"
sDeviceName = Printer.DeviceName
bJobStarted = False
End Sub

Private Sub Class_Terminate()
If bJobStarted Then
EndDoc
End If
End Sub

Public Property Get hPrinter() As Long
hPrinter = lPrinter
End Property

Public Property Get hJob() As Long
hJob = lJob
End Property

Public Property Get Priority() As Long
Dim di As String ' stores JOB_INFO_1
Dim i As Long

Call GetJob(lPrinter, lJob, 1, ByVal di, 0, i)
di = String(i, 0)
Call CopyMemory(i, ByVal (Mid$(di, 33, 4)), 4)

Priority = i
End Property

' Bug: Doesn't work?
Public Property Let Priority(ByVal i As Long)
Dim di As JOB_INFO_1

'JobId, pPrinterName, pMachineName, pDrivername,
'Size, Submitted, and Time are ignored
If i < MIN_PRIORITY Then
i = DEF_PRIORITY
ElseIf i > MAX_PRIORITY Then
i = MAX_PRIORITY
End If

di.Priority = i
di.Position = JOB_POSITION_UNSPECIFIED
di.pUserName = vbNullString
di.pDocument = vbNullString
di.pDatatype = vbNullString
di.pStatus = vbNullString
di.Status = 0
di.TotalPages = 0
di.PagesPrinted = 0

Call SetJob(lPrinter, lJob, 1, di, 0)
End Property


Procedure Printing


Private Sub Printing()
Dim p As New clsRAWPrinter
Open App.Path + "\cetak.txt" For Output As #1
Print #1, Tab(1); Nama
Print #1, Tab(1); Alamat
Print #1, Tab(1); "Telp. " + Telp
Print #1, Tab(1); " "
Print #1, Tab(1); "===================================="
Print #1, Tab(1); "Parkir tanggal "
Print #1, Tab(1); "No. Karcis = "
Print #1, Tab(1); "Nopol = "
Print #1, Tab(1); "Tarif = "
Print #1, Tab(1); "Petugas = "
Print #1, Tab(1); "====> Terima Kasih <==="
Print #1, Tab(1); " "
Print #1, Tab(1); " "
Print #1, Tab(1); " "
Print #1, Tab(1); " "
Print #1, Tab(1); " "
Close #1
p.PrintFile (App.Path + "\cetak.txt")
p.EndDoc
End Sub

source from :  http://www.i-bego.com



Print Nota LX 300 vb.net

CLASS :

Imports System.IO
Imports System.Drawing.Printing
Imports System.Runtime.InteropServices

Public Class RawPrinterHelper
    ' Structure and API declarions:
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
    Structure DOCINFOW
        <MarshalAs(UnmanagedType.LPWStr)> Public pDocName As String
        <MarshalAs(UnmanagedType.LPWStr)> Public pOutputFile As String
        <MarshalAs(UnmanagedType.LPWStr)> Public pDataType As String
    End Structure

    <DllImport("winspool.Drv", EntryPoint:="OpenPrinterW", _
       SetLastError:=True, CharSet:=CharSet.Unicode, _
       ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
    Public Shared Function OpenPrinter(ByVal src As String, ByRef hPrinter As IntPtr, ByVal pd As Long) As Boolean
    End Function
    <DllImport("winspool.Drv", EntryPoint:="ClosePrinter", _
       SetLastError:=True, CharSet:=CharSet.Unicode, _
       ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
    Public Shared Function ClosePrinter(ByVal hPrinter As IntPtr) As Boolean
    End Function
    <DllImport("winspool.Drv", EntryPoint:="StartDocPrinterW", _
       SetLastError:=True, CharSet:=CharSet.Unicode, _
       ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
    Public Shared Function StartDocPrinter(ByVal hPrinter As IntPtr, ByVal level As Int32, ByRef pDI As DOCINFOW) As Boolean
    End Function
    <DllImport("winspool.Drv", EntryPoint:="EndDocPrinter", _
       SetLastError:=True, CharSet:=CharSet.Unicode, _
       ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
    Public Shared Function EndDocPrinter(ByVal hPrinter As IntPtr) As Boolean
    End Function
    <DllImport("winspool.Drv", EntryPoint:="StartPagePrinter", _
       SetLastError:=True, CharSet:=CharSet.Unicode, _
       ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
    Public Shared Function StartPagePrinter(ByVal hPrinter As IntPtr) As Boolean
    End Function
    <DllImport("winspool.Drv", EntryPoint:="EndPagePrinter", _
       SetLastError:=True, CharSet:=CharSet.Unicode, _
       ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
    Public Shared Function EndPagePrinter(ByVal hPrinter As IntPtr) As Boolean
    End Function
    <DllImport("winspool.Drv", EntryPoint:="WritePrinter", _
       SetLastError:=True, CharSet:=CharSet.Unicode, _
       ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
    Public Shared Function WritePrinter(ByVal hPrinter As IntPtr, ByVal pBytes As IntPtr, ByVal dwCount As Int32, ByRef dwWritten As Int32) As Boolean
    End Function

    ' SendBytesToPrinter()
    ' When the function is given a printer name and an unmanaged array of 
    ' bytes, the function sends those bytes to the print queue.
    ' Returns True on success or False on failure.
    Public Shared Function SendBytesToPrinter(ByVal szPrinterName As String, ByVal pBytes As IntPtr, ByVal dwCount As Int32) As Boolean
        Dim hPrinter As IntPtr      ' The printer handle.
        Dim dwError As Int32        ' Last error - in case there was trouble.
        Dim di As DOCINFOW          ' Describes your document (name, port, data type).
        Dim dwWritten As Int32      ' The number of bytes written by WritePrinter().
        Dim bSuccess As Boolean     ' Your success code.

        ' Set up the DOCINFO structure.
        With di
            .pDocName = "Toko Komputer"
            .pDataType = "RAW"
        End With
        ' Assume failure unless you specifically succeed.
        bSuccess = False
        If OpenPrinter(szPrinterName, hPrinter, 0) Then
            If StartDocPrinter(hPrinter, 1, di) Then
                If StartPagePrinter(hPrinter) Then
                    ' Write your printer-specific bytes to the printer.
                    bSuccess = WritePrinter(hPrinter, pBytes, dwCount, dwWritten)
                    EndPagePrinter(hPrinter)
                End If
                EndDocPrinter(hPrinter)
            End If
            ClosePrinter(hPrinter)
        End If
        ' If you did not succeed, GetLastError may give more information
        ' about why not.
        If bSuccess = False Then
            dwError = Marshal.GetLastWin32Error()
        End If
        Return bSuccess
    End Function ' SendBytesToPrinter()

    ' SendFileToPrinter()
    ' When the function is given a file name and a printer name,
    ' the function reads the contents of the file and sends the
    ' contents to the printer.
    ' Presumes that the file contains printer-ready data.
    ' Shows how to use the SendBytesToPrinter function.
    ' Returns True on success or False on failure.
    Public Shared Function SendFileToPrinter(ByVal szPrinterName As String, ByVal szFileName As String) As Boolean
        ' Open the file.
        Dim fs As New FileStream(szFileName, FileMode.Open)
        ' Create a BinaryReader on the file.
        Dim br As New BinaryReader(fs)
        ' Dim an array of bytes large enough to hold the file's contents.
        Dim bytes(fs.Length) As Byte
        Dim bSuccess As Boolean
        ' Your unmanaged pointer.
        Dim pUnmanagedBytes As IntPtr

        ' Read the contents of the file into the array.
        bytes = br.ReadBytes(fs.Length)
        ' Allocate some unmanaged memory for those bytes.
        pUnmanagedBytes = Marshal.AllocCoTaskMem(fs.Length)
        ' Copy the managed byte array into the unmanaged array.
        Marshal.Copy(bytes, 0, pUnmanagedBytes, fs.Length)
        ' Send the unmanaged bytes to the printer.
        bSuccess = SendBytesToPrinter(szPrinterName, pUnmanagedBytes, fs.Length)
        ' Free the unmanaged memory that you allocated earlier.
        Marshal.FreeCoTaskMem(pUnmanagedBytes)
        Return bSuccess
    End Function ' SendFileToPrinter()

    ' When the function is given a string and a printer name,
    ' the function sends the string to the printer as raw bytes.
    Public Shared Function SendStringToPrinter(ByVal szPrinterName As String, ByVal szString As String)
        Dim pBytes As IntPtr
        Dim dwCount As Int32
        ' How many characters are in the string?
        dwCount = szString.Length()
        ' Assume that the printer is expecting ANSI text, and then convert
        ' the string to ANSI text.
        pBytes = Marshal.StringToCoTaskMemAnsi(szString)
        ' Send the converted ANSI string to the printer.
        SendBytesToPrinter(szPrinterName, pBytes, dwCount)
        Marshal.FreeCoTaskMem(pBytes)
    End Function
End Class
 
 
PROCEDURE CETAK 
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim s As String
        Const sLN As String = ControlChars.CrLf
        Dim pd As New PrintDialog()
        Dim header(2, 2) As String

        header(0, 0) = "Tanggal : "
        header(0, 1) = "12-12-2012 12:30"
        header(0, 2) = String.Format("{0,20}", "Kepada Yth,")
        '------------------------
        header(1, 0) = "Kasir   : "
        header(1, 1) = "Nama Kasir"
        header(1, 2) = String.Format("{0,20}", "Markotel")
        '-----------------------
        header(2, 0) = "Nota    : "
        header(2, 1) = "323232323 " & String.Format("{0,20}", "FAKTUR PENJUALAN")
        header(2, 2) = String.Format("{0,20}", "Alamat")

        s = "ANU Komputer" & sLN & "Kampung Digital" & sLN & "Indonesia."
        s &= " HP :0812111111" & sLN
        s &= header(0, 0) & header(0, 1) & StrDup(50 - Len(header(0, 1)), " ") & header(0, 2) & sLN
        s &= header(1, 0) & header(1, 1) & StrDup(50 - Len(header(1, 1)), " ") & header(1, 2) & sLN
        s &= header(2, 0) & header(2, 1) & StrDup(50 - Len(header(2, 1)), " ") & header(2, 2) & sLN
        s &= StrDup(80, "=") & sLN
        s &= "No.: Nama Produk" & StrDup(27, " ") & ":      HARGA   :  QTY :        JUMLAH" & sLN
        s &= StrDup(80, "=") & sLN
       'Open the printer dialog box, and then allow the user to select a printer.
        pd.PrinterSettings = New PrinterSettings()
        If (pd.ShowDialog() = DialogResult.OK) Then
        RawPrinterHelper.SendStringToPrinter("Epson LX-300+", s) 'perhatikan nama printernya.
        End If
End Sub 



source from : http://www.i-bego.com
 

Rabu, 29 Februari 2012

BIKIN POP UP VB.NET

PREVIEW


CODE :


Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        textBoxContent.Text = "This is a sample content, it can spread on multiple lines"
        textBoxTitle.Text = "Title"
        textBoxDelayShowing.Text = "500"
        textBoxDelayStaying.Text = "3000"
        textBoxDelayHiding.Text = "500"
        checkBoxSelectionRectangle.Checked = True
        checkBoxTitleClickable.Checked = False
        checkBoxContentClickable.Checked = True
        checkBoxCloseClickable.Checked = True
        checkBoxKeepVisibleOnMouseOver.Checked = True
        checkBoxReShowOnMouseOver.Checked = False

        taskbarNotifier1 = New TaskBarNotifier()
        taskbarNotifier1.SetBackgroundBitmap(New Bitmap(MyClass.GetType(), "skin.bmp"), Color.FromArgb(255, 0, 255))
        taskbarNotifier1.SetCloseBitmap(New Bitmap(MyClass.GetType(), "close.bmp"), Color.FromArgb(255, 0, 255), New Point(127, 8))
        taskbarNotifier1.TitleRectangle = New Rectangle(40, 9, 70, 25)
        taskbarNotifier1.TextRectangle = New Rectangle(8, 41, 133, 68)

        taskbarNotifier2 = New TaskBarNotifier()
        taskbarNotifier2.SetBackgroundBitmap(New Bitmap(MyClass.GetType(), "skin2.bmp"), Color.FromArgb(255, 0, 255))
        taskbarNotifier2.SetCloseBitmap(New Bitmap(MyClass.GetType(), "close2.bmp"), Color.FromArgb(255, 0, 255), New Point(300, 74))
        taskbarNotifier2.TitleRectangle = New Rectangle(123, 80, 176, 16)
        taskbarNotifier2.TextRectangle = New Rectangle(116, 97, 197, 22)

        taskbarNotifier3 = New TaskBarNotifier()
        taskbarNotifier3.SetBackgroundBitmap(New Bitmap(MyClass.GetType(), "skin3.bmp"), Color.FromArgb(255, 0, 255))
        taskbarNotifier3.SetCloseBitmap(New Bitmap(MyClass.GetType(), "close.bmp"), Color.FromArgb(255, 0, 255), New Point(280, 57))
        taskbarNotifier3.TitleRectangle = New Rectangle(150, 57, 125, 28)
        taskbarNotifier3.TextRectangle = New Rectangle(75, 92, 215, 55)

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer. 
    'Do not modify it using the code editor.
    Friend WithEvents groupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents label2 As System.Windows.Forms.Label
    Friend WithEvents label1 As System.Windows.Forms.Label
    Friend WithEvents textBoxContent As System.Windows.Forms.TextBox
    Friend WithEvents textBoxTitle As System.Windows.Forms.TextBox
    Friend WithEvents groupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents label5 As System.Windows.Forms.Label
    Friend WithEvents label4 As System.Windows.Forms.Label
    Friend WithEvents label3 As System.Windows.Forms.Label
    Friend WithEvents textBoxDelayShowing As System.Windows.Forms.TextBox
    Friend WithEvents textBoxDelayStaying As System.Windows.Forms.TextBox
    Friend WithEvents textBoxDelayHiding As System.Windows.Forms.TextBox
    Friend WithEvents groupBox3 As System.Windows.Forms.GroupBox
    Friend WithEvents checkBoxCloseClickable As System.Windows.Forms.CheckBox
    Friend WithEvents checkBoxContentClickable As System.Windows.Forms.CheckBox
    Friend WithEvents checkBoxTitleClickable As System.Windows.Forms.CheckBox
    Friend WithEvents checkBoxSelectionRectangle As System.Windows.Forms.CheckBox
    Friend WithEvents ButtonShowPopup2 As System.Windows.Forms.Button
    Friend WithEvents ButtonShowPopup1 As System.Windows.Forms.Button
    Friend WithEvents ButtonShowPopup3 As System.Windows.Forms.Button
    Friend WithEvents checkBoxKeepVisibleOnMouseOver As System.Windows.Forms.CheckBox
    Friend WithEvents checkBoxReShowOnMouseOver As System.Windows.Forms.CheckBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.groupBox1 = New System.Windows.Forms.GroupBox()
        Me.label2 = New System.Windows.Forms.Label()
        Me.label1 = New System.Windows.Forms.Label()
        Me.textBoxContent = New System.Windows.Forms.TextBox()
        Me.textBoxTitle = New System.Windows.Forms.TextBox()
        Me.groupBox2 = New System.Windows.Forms.GroupBox()
        Me.label5 = New System.Windows.Forms.Label()
        Me.label4 = New System.Windows.Forms.Label()
        Me.label3 = New System.Windows.Forms.Label()
        Me.textBoxDelayShowing = New System.Windows.Forms.TextBox()
        Me.textBoxDelayStaying = New System.Windows.Forms.TextBox()
        Me.textBoxDelayHiding = New System.Windows.Forms.TextBox()
        Me.groupBox3 = New System.Windows.Forms.GroupBox()
        Me.checkBoxCloseClickable = New System.Windows.Forms.CheckBox()
        Me.checkBoxContentClickable = New System.Windows.Forms.CheckBox()
        Me.checkBoxTitleClickable = New System.Windows.Forms.CheckBox()
        Me.checkBoxSelectionRectangle = New System.Windows.Forms.CheckBox()
        Me.ButtonShowPopup2 = New System.Windows.Forms.Button()
        Me.ButtonShowPopup1 = New System.Windows.Forms.Button()
        Me.ButtonShowPopup3 = New System.Windows.Forms.Button()
        Me.checkBoxKeepVisibleOnMouseOver = New System.Windows.Forms.CheckBox()
        Me.checkBoxReShowOnMouseOver = New System.Windows.Forms.CheckBox()
        Me.groupBox1.SuspendLayout()
        Me.groupBox2.SuspendLayout()
        Me.groupBox3.SuspendLayout()
        Me.SuspendLayout()
        '
        'groupBox1
        '
        Me.groupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.label2, Me.label1, Me.textBoxContent, Me.textBoxTitle})
        Me.groupBox1.Location = New System.Drawing.Point(4, 4)
        Me.groupBox1.Name = "groupBox1"
        Me.groupBox1.Size = New System.Drawing.Size(296, 88)
        Me.groupBox1.TabIndex = 8
        Me.groupBox1.TabStop = False
        Me.groupBox1.Text = "Text"
        '
        'label2
        '
        Me.label2.Location = New System.Drawing.Point(12, 52)
        Me.label2.Name = "label2"
        Me.label2.Size = New System.Drawing.Size(48, 16)
        Me.label2.TabIndex = 10
        Me.label2.Text = "Content"
        '
        'label1
        '
        Me.label1.Location = New System.Drawing.Point(12, 20)
        Me.label1.Name = "label1"
        Me.label1.Size = New System.Drawing.Size(40, 16)
        Me.label1.TabIndex = 9
        Me.label1.Text = "Title"
        '
        'textBoxContent
        '
        Me.textBoxContent.Location = New System.Drawing.Point(60, 52)
        Me.textBoxContent.Name = "textBoxContent"
        Me.textBoxContent.Size = New System.Drawing.Size(224, 20)
        Me.textBoxContent.TabIndex = 8
        Me.textBoxContent.Text = "textBoxContent"
        '
        'textBoxTitle
        '
        Me.textBoxTitle.Location = New System.Drawing.Point(60, 20)
        Me.textBoxTitle.Name = "textBoxTitle"
        Me.textBoxTitle.Size = New System.Drawing.Size(224, 20)
        Me.textBoxTitle.TabIndex = 7
        Me.textBoxTitle.Text = "textBoxTitle"
        '
        'groupBox2
        '
        Me.groupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.label5, Me.label4, Me.label3, Me.textBoxDelayShowing, Me.textBoxDelayStaying, Me.textBoxDelayHiding})
        Me.groupBox2.Location = New System.Drawing.Point(4, 100)
        Me.groupBox2.Name = "groupBox2"
        Me.groupBox2.Size = New System.Drawing.Size(296, 88)
        Me.groupBox2.TabIndex = 15
        Me.groupBox2.TabStop = False
        Me.groupBox2.Text = "Animation Delays (ms)"
        '
        'label5
        '
        Me.label5.Location = New System.Drawing.Point(200, 28)
        Me.label5.Name = "label5"
        Me.label5.Size = New System.Drawing.Size(80, 16)
        Me.label5.TabIndex = 19
        Me.label5.Text = "Delay Hiding"
        '
        'label4
        '
        Me.label4.Location = New System.Drawing.Point(112, 28)
        Me.label4.Name = "label4"
        Me.label4.Size = New System.Drawing.Size(80, 16)
        Me.label4.TabIndex = 18
        Me.label4.Text = "Delay Staying"
        '
        'label3
        '
        Me.label3.Location = New System.Drawing.Point(16, 28)
        Me.label3.Name = "label3"
        Me.label3.Size = New System.Drawing.Size(80, 16)
        Me.label3.TabIndex = 17
        Me.label3.Text = "Delay Showing"
        '
        'textBoxDelayShowing
        '
        Me.textBoxDelayShowing.Location = New System.Drawing.Point(24, 52)
        Me.textBoxDelayShowing.Name = "textBoxDelayShowing"
        Me.textBoxDelayShowing.Size = New System.Drawing.Size(56, 20)
        Me.textBoxDelayShowing.TabIndex = 16
        Me.textBoxDelayShowing.Text = "textBoxDelayShowing"
        '
        'textBoxDelayStaying
        '
        Me.textBoxDelayStaying.Location = New System.Drawing.Point(120, 52)
        Me.textBoxDelayStaying.Name = "textBoxDelayStaying"
        Me.textBoxDelayStaying.Size = New System.Drawing.Size(56, 20)
        Me.textBoxDelayStaying.TabIndex = 15
        Me.textBoxDelayStaying.Text = "textBoxDelayStaying"
        '
        'textBoxDelayHiding
        '
        Me.textBoxDelayHiding.Location = New System.Drawing.Point(208, 52)
        Me.textBoxDelayHiding.Name = "textBoxDelayHiding"
        Me.textBoxDelayHiding.Size = New System.Drawing.Size(56, 20)
        Me.textBoxDelayHiding.TabIndex = 14
        Me.textBoxDelayHiding.Text = "textBoxDelayHiding"
        '
        'groupBox3
        '
        Me.groupBox3.Controls.AddRange(New System.Windows.Forms.Control() {Me.checkBoxReShowOnMouseOver, Me.checkBoxKeepVisibleOnMouseOver, Me.checkBoxCloseClickable, Me.checkBoxContentClickable, Me.checkBoxTitleClickable, Me.checkBoxSelectionRectangle})
        Me.groupBox3.Location = New System.Drawing.Point(4, 192)
        Me.groupBox3.Name = "groupBox3"
        Me.groupBox3.Size = New System.Drawing.Size(296, 116)
        Me.groupBox3.TabIndex = 16
        Me.groupBox3.TabStop = False
        Me.groupBox3.Text = "Options"
        '
        'checkBoxCloseClickable
        '
        Me.checkBoxCloseClickable.Location = New System.Drawing.Point(16, 48)
        Me.checkBoxCloseClickable.Name = "checkBoxCloseClickable"
        Me.checkBoxCloseClickable.Size = New System.Drawing.Size(104, 16)
        Me.checkBoxCloseClickable.TabIndex = 3
        Me.checkBoxCloseClickable.Text = "Close Clickable"
        '
        'checkBoxContentClickable
        '
        Me.checkBoxContentClickable.Location = New System.Drawing.Point(128, 24)
        Me.checkBoxContentClickable.Name = "checkBoxContentClickable"
        Me.checkBoxContentClickable.Size = New System.Drawing.Size(112, 16)
        Me.checkBoxContentClickable.TabIndex = 1
        Me.checkBoxContentClickable.Text = "Content Clickable"
        '
        'checkBoxTitleClickable
        '
        Me.checkBoxTitleClickable.Location = New System.Drawing.Point(16, 24)
        Me.checkBoxTitleClickable.Name = "checkBoxTitleClickable"
        Me.checkBoxTitleClickable.Size = New System.Drawing.Size(96, 16)
        Me.checkBoxTitleClickable.TabIndex = 0
        Me.checkBoxTitleClickable.Text = "Title Clickable"
        '
        'checkBoxSelectionRectangle
        '
        Me.checkBoxSelectionRectangle.Location = New System.Drawing.Point(128, 48)
        Me.checkBoxSelectionRectangle.Name = "checkBoxSelectionRectangle"
        Me.checkBoxSelectionRectangle.Size = New System.Drawing.Size(160, 16)
        Me.checkBoxSelectionRectangle.TabIndex = 2
        Me.checkBoxSelectionRectangle.Text = "Show Selection Rectangle"
        '
        'ButtonShowPopup2
        '
        Me.ButtonShowPopup2.Location = New System.Drawing.Point(108, 316)
        Me.ButtonShowPopup2.Name = "ButtonShowPopup2"
        Me.ButtonShowPopup2.Size = New System.Drawing.Size(88, 23)
        Me.ButtonShowPopup2.TabIndex = 18
        Me.ButtonShowPopup2.Text = "Show popup 2"
        '
        'ButtonShowPopup1
        '
        Me.ButtonShowPopup1.Location = New System.Drawing.Point(8, 316)
        Me.ButtonShowPopup1.Name = "ButtonShowPopup1"
        Me.ButtonShowPopup1.Size = New System.Drawing.Size(88, 23)
        Me.ButtonShowPopup1.TabIndex = 17
        Me.ButtonShowPopup1.Text = "Show popup 1"
        '
        'ButtonShowPopup3
        '
        Me.ButtonShowPopup3.Location = New System.Drawing.Point(208, 316)
        Me.ButtonShowPopup3.Name = "ButtonShowPopup3"
        Me.ButtonShowPopup3.Size = New System.Drawing.Size(88, 23)
        Me.ButtonShowPopup3.TabIndex = 19
        Me.ButtonShowPopup3.Text = "Show popup 3"
        '
        'checkBoxKeepVisibleOnMouseOver
        '
        Me.checkBoxKeepVisibleOnMouseOver.Location = New System.Drawing.Point(16, 72)
        Me.checkBoxKeepVisibleOnMouseOver.Name = "checkBoxKeepVisibleOnMouseOver"
        Me.checkBoxKeepVisibleOnMouseOver.Size = New System.Drawing.Size(272, 16)
        Me.checkBoxKeepVisibleOnMouseOver.TabIndex = 4
        Me.checkBoxKeepVisibleOnMouseOver.Text = "Keep Visible when Mouse over window"
        '
        'checkBoxReShowOnMouseOver
        '
        Me.checkBoxReShowOnMouseOver.Location = New System.Drawing.Point(16, 92)
        Me.checkBoxReShowOnMouseOver.Name = "checkBoxReShowOnMouseOver"
        Me.checkBoxReShowOnMouseOver.Size = New System.Drawing.Size(272, 16)
        Me.checkBoxReShowOnMouseOver.TabIndex = 5
        Me.checkBoxReShowOnMouseOver.Text = "Re-show when Mouse over window when hiding"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(304, 349)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ButtonShowPopup3, Me.ButtonShowPopup2, Me.ButtonShowPopup1, Me.groupBox3, Me.groupBox2, Me.groupBox1})
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "VB.NET TaskBarNotifier Demo"
        Me.groupBox1.ResumeLayout(False)
        Me.groupBox2.ResumeLayout(False)
        Me.groupBox3.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private WithEvents taskbarNotifier1 As TaskBarNotifier
    Private WithEvents taskbarNotifier2 As TaskBarNotifier
    Private WithEvents taskbarNotifier3 As TaskBarNotifier


    Private Sub Notifier_CloseButtonClick(ByVal sender As Object, ByVal e As System.EventArgs) _
                                                            Handles taskbarNotifier1.CloseButtonClick, _
                                                                    taskbarNotifier2.CloseButtonClick, _
                                                                    taskbarNotifier3.CloseButtonClick

        Dim taskbarSender As TaskBarNotifier = DirectCast(sender, TaskBarNotifier)

        If taskbarSender.Equals(taskbarNotifier1) Then
            MsgBox("TaskBarNotifier 1: CloseButton was clicked")
        End If

        If taskbarSender.Equals(taskbarNotifier2) Then
            MsgBox("TaskBarNotifier 2: CloseButton was clicked")
        End If

        If taskbarSender.Equals(taskbarNotifier3) Then
            MsgBox("TaskBarNotifier 3: CloseButton was clicked")
        End If

    End Sub

    Private Sub Notifier_TitleClick(ByVal sender As Object, ByVal e As System.EventArgs) _
                                                            Handles taskbarNotifier1.TitleClick, _
                                                                    taskbarNotifier2.TitleClick, _
                                                                    taskbarNotifier3.TitleClick

        Dim taskbarSender As TaskBarNotifier = DirectCast(sender, TaskBarNotifier)

        If taskbarSender.Equals(taskbarNotifier1) Then
            MsgBox("TaskBarNotifier 1: Title was clicked")
        End If

        If taskbarSender.Equals(taskbarNotifier2) Then
            MsgBox("TaskBarNotifier 2: Title was clicked")
        End If

        If taskbarSender.Equals(taskbarNotifier3) Then
            MsgBox("TaskBarNotifier 3: Title was clicked")
        End If

    End Sub

    Private Sub Notifier_TextClick(ByVal sender As Object, ByVal e As System.EventArgs) _
                                                            Handles taskbarNotifier1.TextClick, _
                                                                    taskbarNotifier2.TextClick, _
                                                                    taskbarNotifier3.TextClick

        Dim taskbarSender As TaskBarNotifier = DirectCast(sender, TaskBarNotifier)

        If taskbarSender.Equals(taskbarNotifier1) Then
            MsgBox("TaskBarNotifier 1: TextZone was clicked")
        End If

        If taskbarSender.Equals(taskbarNotifier2) Then
            MsgBox("TaskBarNotifier 2: TextZone was clicked")
        End If

        If taskbarSender.Equals(taskbarNotifier3) Then
            MsgBox("TaskBarNotifier 3: TextZone was clicked")
        End If

    End Sub

    Private Sub ButtonShowPopup1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonShowPopup1.Click

        If (textBoxTitle.Text.Length = 0 OrElse textBoxContent.Text.Length = 0) Then
            MsgBox("Enter a title and a content Text")
            Exit Sub
        End If

        If Not IsNumeric(textBoxDelayShowing.Text) OrElse _
           Not IsNumeric(textBoxDelayStaying.Text) OrElse _
           Not IsNumeric(textBoxDelayHiding.Text) Then
            MsgBox("Enter valid Delays (integers)")
            Exit Sub
        End If

        With taskbarNotifier1
            .CloseButtonClickEnabled = checkBoxCloseClickable.Checked
            .TitleClickEnabled = checkBoxTitleClickable.Checked
            .TextClickEnabled = checkBoxContentClickable.Checked
            .DrawTextFocusRect = checkBoxSelectionRectangle.Checked
            .KeepVisibleOnMouseOver = checkBoxKeepVisibleOnMouseOver.Checked
            .ReShowOnMouseOver = checkBoxReShowOnMouseOver.Checked
            .Show(textBoxTitle.Text, _
                  textBoxContent.Text, _
                  Integer.Parse(textBoxDelayShowing.Text), _
                  Integer.Parse(textBoxDelayStaying.Text), _
                  Integer.Parse(textBoxDelayHiding.Text))
        End With

    End Sub

    Private Sub ButtonShowPopup2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonShowPopup2.Click

        If (textBoxTitle.Text.Length = 0 OrElse textBoxContent.Text.Length = 0) Then
            MsgBox("Enter a title and a content Text")
            Exit Sub
        End If

        If Not IsNumeric(textBoxDelayShowing.Text) OrElse _
           Not IsNumeric(textBoxDelayStaying.Text) OrElse _
           Not IsNumeric(textBoxDelayHiding.Text) Then
            MsgBox("Enter valid Delays (integers)")
            Exit Sub
        End If

        With taskbarNotifier2
            .CloseButtonClickEnabled = checkBoxCloseClickable.Checked
            .TitleClickEnabled = checkBoxTitleClickable.Checked
            .TextClickEnabled = checkBoxContentClickable.Checked
            .DrawTextFocusRect = checkBoxSelectionRectangle.Checked
            .KeepVisibleOnMouseOver = checkBoxKeepVisibleOnMouseOver.Checked
            .ReShowOnMouseOver = checkBoxReShowOnMouseOver.Checked
            .Show(textBoxTitle.Text, _
                  textBoxContent.Text, _
                  Integer.Parse(textBoxDelayShowing.Text), _
                  Integer.Parse(textBoxDelayStaying.Text), _
                  Integer.Parse(textBoxDelayHiding.Text))
        End With
    End Sub

    Private Sub ButtonShowPopup3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonShowPopup3.Click

        'This is an addition TaskbarNotifier window.
        'Made this in order to see how 'easy' it is to create my own custom skin.

        ' Believe me... If you know your way around in a bitmap editor...It's EASY !!! :-)

        If (textBoxTitle.Text.Length = 0 OrElse textBoxContent.Text.Length = 0) Then
            MsgBox("Enter a title and a content Text")
            Exit Sub
        End If

        If Not IsNumeric(textBoxDelayShowing.Text) OrElse _
           Not IsNumeric(textBoxDelayStaying.Text) OrElse _
           Not IsNumeric(textBoxDelayHiding.Text) Then
            MsgBox("Enter valid Delays (integers)")
            Exit Sub
        End If

        With taskbarNotifier3
            .NormalTitleColor = Color.Black
            .HoverTitleColor = Color.Black
            .NormalContentColor = Color.Yellow
            .HoverContentColor = Color.White
            .CloseButtonClickEnabled = checkBoxCloseClickable.Checked
            .TitleClickEnabled = checkBoxTitleClickable.Checked
            .TextClickEnabled = checkBoxContentClickable.Checked
            .DrawTextFocusRect = checkBoxSelectionRectangle.Checked
            .KeepVisibleOnMouseOver = checkBoxKeepVisibleOnMouseOver.Checked
            .ReShowOnMouseOver = checkBoxReShowOnMouseOver.Checked
            .Show(textBoxTitle.Text, _
                  textBoxContent.Text, _
                  Integer.Parse(textBoxDelayShowing.Text), _
                  Integer.Parse(textBoxDelayStaying.Text), _
                  Integer.Parse(textBoxDelayHiding.Text))
        End With

    End Sub

End Class