Saturday, December 19, 2015

Print Screen Of Windows Form

Declare Auto Function SendMessage Lib "user32" ( _
           ByVal hWnd As IntPtr, _
           ByVal Msg As Integer, _
           ByVal wParam As IntPtr, _
           ByVal lParam As Integer) As Integer
    Private Enum EDrawingOptions As Integer
        PRF_CHECKVISIBLE = &H1
        PRF_NONCLIENT = &H2
        PRF_CLIENT = &H4
        PRF_ERASEBKGND = &H8
        PRF_CHILDREN = &H10
        PRF_OWNED = &H20
    End Enum
    Private Sub Button6_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button6.Click
        Const WM_PRINT As Integer = &H317
        Dim myBmp As Bitmap
        Dim myGraphics As Graphics
        Dim hdc As System.IntPtr
        myBmp = New Bitmap( _
            Me.DisplayRectangle.Width, _
            Me.DisplayRectangle.Height)
        myGraphics = Graphics.FromImage(myBmp)
        hdc = myGraphics.GetHdc
        Call SendMessage(Me.Handle, WM_PRINT, hdc, _
            EDrawingOptions.PRF_CHILDREN Or _
            EDrawingOptions.PRF_CLIENT Or _
            EDrawingOptions.PRF_NONCLIENT Or _
            EDrawingOptions.PRF_OWNED)
        myGraphics.ReleaseHdc(hdc)
        myBmp.Save("D:\out.bmp")
        myGraphics.Dispose()
        myGraphics = Nothing
        myBmp = Nothing
    End Sub

Wednesday, August 13, 2014

Wednesday, July 30, 2014

Scan Document using vb.net code

Private Sub btnScanPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScanPage.Click
        btnScanPage.Text = "Scanning Page, Please wait..."
        Me.Cursor = Cursors.WaitCursor
        If scan() = True Then
            btnScanPage.Text = "Scan Page"
            UgcDetails.lstattach.Items.Add(fileName)
            Me.Cursor = Cursors.Default
            Me.Close()
            Me.Dispose()
        End If
    End Sub
-------------------------------------------------------------------
--------------------------------Function scan-------------------
Private Function scan() As Boolean
        Try
            Dim commonDialogClass As New CommonDialogClass()
            Dim scannerDevice As Device = commonDialogClass.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, False, False)
            If scannerDevice IsNot Nothing Then
                Dim scannnerItem As Item = scannerDevice.Items(1)
                AdjustScannerSettings(scannnerItem, 100, 0, 0, 850, 1150, 0, 0)
                Dim scanResult As Object = commonDialogClass.ShowTransfer(scannnerItem, WIA.FormatID.wiaFormatPNG, False)
                If scanResult IsNot Nothing Then
                    Dim image As ImageFile = DirectCast(scanResult, ImageFile)
                    Dim path1 As String = "D:\scan\" & Me.Tag & "\"
                    My.Computer.FileSystem.CreateDirectory(path1)
                    fileName = path1 & Now.ToString.Replace("/", "").Replace("-", "").Replace(":", "") & ".jpg"
                    If SaveImageToFile(image, fileName) = True Then
                        PictureBox1.ImageLocation = fileName
                        Return True
                    End If
                End If
            End If
        Catch ex As Exception
            Return False
        End Try
    End Function

Tuesday, July 29, 2014

Add multiply Files at List box

 OpenFileDialog1.Multiselect = True
            OpenFileDialog1.Title = "Attach File"
            OpenFileDialog1.Filter = "All Files|*.*"
            If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
                For Each fname As String In OpenFileDialog1.FileNames
                    lstattach.Items.Add(fname)
                Next
            End If

Thursday, July 17, 2014

For SMS

If Len(smscelno) = 10 Then
                    Dim convid As String = txtstate.Tag & "-" & Me.Tag
                  Dim smstxt As String = "Your complaint has been successfully registered.Your complaint No is " & convid " &
                    WebBrowsersms.Navigate("http://?uname= & pass= & send= & dest=91" & smscelno & "&msg=" & smstxt)
                    Do Until WebBrowsersms.ReadyState = WebBrowserReadyState.Complete
                        Application.DoEvents()
                    Loop
                End If

Friday, July 4, 2014

How, can i get forms name from vb.net ?

private sub proshowformnames()
  For Each FRM As Form In Application.OpenForms
     MsgBox(FRM.Name)
  Next
end sub

Friday, April 4, 2014

Read & Write Txt File in vb.net

Add class form in vb.net project

Imports System
Imports System.IO
Imports System.Text
Imports System.Collections.Generic
Imports Scripting
Public Class Testwrite
    Public Sub DeleteFile(ByVal mydocpath As String, ByVal filename As String)
        Dim fso As FileSystemObject = New FileSystemObject
        If fso.FileExists(mydocpath + "\" & filename & ".set") = True Then
            fso.DeleteFile(mydocpath + "\" & filename & ".set", True)
        End If
    End Sub
    Public Sub WriteToFile(ByVal mydocpath As String, ByVal filename As String, ByVal datastring As String)
        Dim sb As New StringBuilder()
        sb.AppendLine(datastring)
        Using outfile As StreamWriter = New StreamWriter(mydocpath + "\" & filename & ".Txt", True)
            outfile.Write(sb.ToString())
        End Using
    End Sub
    Public Function ReadFromSetFile(ByVal mydocpath As String, ByVal filename As String, ByVal key As String) As String
        Dim txtbox As String = Nothing
        Try
            Using sr As StreamReader = New StreamReader(mydocpath + "\" & filename & ".set")
                While Not sr.EndOfStream
                    Dim line = sr.ReadLine()
                    Dim seppos As Integer = InStr(line, "|")
                    If seppos > 0 Then
                        If line Like key & "*" Then
                            txtbox = Trim(Mid(line, seppos + 1))
                            Exit While
                        End If
                    End If
                End While
            End Using
        Catch ex As Exception
            txtbox = ""
        End Try
        Return txtbox
    End Function
    Public Function ReadFromFile(ByVal mydocpath As String, ByVal title As Boolean) As String
        Dim line As String = Nothing
        Try
            Using sr As StreamReader = New StreamReader(mydocpath)
                If title = True Then
                    line = sr.ReadLine
                    line = Nothing
                End If
                While Not sr.EndOfStream
                    line = sr.ReadLine()
                End While
            End Using
        Catch
            line = ""
        End Try
        Return line
    End Function
End Class

Wednesday, April 2, 2014

Remove Last Character From String

 Dim str As String
        str = TextBox1.Text
        str = str.Remove(str.Length - 1)
        MsgBox(str)

Saturday, March 29, 2014

Check And Uncheck DataGridView Cell

If DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = "P" Then
                DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = ""
            Else
                DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.Font = New Font("Wingdings 2", 14, FontStyle.Bold)
                DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = "P"
            End If