Pages

Thursday, 11 December 2014

Visual Basic .Net Window Programming

Horizontal and Vertical Scroll Bar,Numeric Scroll Bar,Progress Bar and Domain Name Scroll Bar Demo


Public Class Form1

    Dim i As Integer

    Private Sub VScrollBar1_Scroll_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll
        lblR.Text = VScrollBar1.Value
        Me.BackColor = Color.FromArgb(VScrollBar1.Value, VScrollBar2.Value, VScrollBar3.Value)
    End Sub


    Private Sub VScrollBar2_Scroll_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar2.Scroll
        lblG.Text = VScrollBar2.Value
        Me.BackColor = Color.FromArgb(VScrollBar1.Value, VScrollBar2.Value, VScrollBar3.Value)
    End Sub

    Private Sub VScrollBar3_Scroll_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar3.Scroll
        lblB.Text = VScrollBar3.Value
        Me.BackColor = Color.FromArgb(VScrollBar1.Value, VScrollBar2.Value, VScrollBar3.Value)
    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblHR.Click

    End Sub

    Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
        lblHR.Text = HScrollBar1.Value
        Me.BackColor = Color.FromArgb(HScrollBar1.Value, HScrollBar2.Value, HScrollBar3.Value)
    End Sub


    Private Sub HScrollBar2_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar2.Scroll
        lblHG.Text = HScrollBar2.Value
        Me.BackColor = Color.FromArgb(HScrollBar1.Value, HScrollBar2.Value, HScrollBar3.Value)
    End Sub

    Private Sub HScrollBar3_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar3.Scroll
        lblHB.Text = HScrollBar3.Value
        Me.BackColor = Color.FromArgb(HScrollBar1.Value, HScrollBar2.Value, HScrollBar3.Value)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        DomainUpDown1.Items.Add(TextBox1.Text)
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        i = i + 10
        If i <= 100 Then
            ProgressBar1.Value = i
        Else
            i = 0
        End If
    End Sub

    Private Sub ProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgressBar1.Click

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        MsgBox(NumericUpDown1.Value)
    End Sub
End Class

Gridview Connectivity using VB.Net

Imports System.Data.OleDb

Public Class Form1
    Dim con As New OleDbConnection()
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim con As New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=bsw.mdb")
        Dim com As New OleDbCommand
        com.Connection = con
        Try
            con.Open()
            com.CommandText = "insert into stu values(" & Val(TextBox1.Text) & ",'" & TextBox2.Text & "','" & TextBox3.Text & "')"
            com.ExecuteNonQuery()
            MsgBox("Save")
            fill_grid()

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

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MsgBox(Application.StartupPath.ToString())
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=bsw.mdb"
        fill_grid()
    End Sub
    Private Sub fill_grid()
        Dim da As New OleDbDataAdapter("select * from stu", con)
        Dim ds As New DataSet
        da.Fill(ds, "girfa")
        DataGridView1.DataSource = ds.Tables("Girfa")
    End Sub
End Class

Add Custom Cursor to control (VB.Net)

Cursor is a small graphic image that we used as mouse pointer. When we move our mouse over a  control an image is moved which is cursor. you can change any control pointer when user hover the mouse on a particular control here is coding which enable you to change cursor pointer of button. In VB.net every control has a property cursor which has predefined set of cursor So I am making code for apply your default cursor

You can get many cursor form C:\Windows\Cursors


Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button1.Cursor = New Cursor("test.cur")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    End Sub
End Class

DataTable Class

   Represents one table of in-memory data.

Remarks

The DataTable is a central object in the ADO.NET library. Other objects that use the DataTable include the DataSet and the DataView.

When accessing DataTable objects, note that they are conditionally case sensitive. For example, if one DataTable is named "mydatatable" and another is named "Mydatatable", a string used to search for one of the tables is regarded as case sensitive. However, if "mydatatable" exists and "Mydatatable" does not, the search string is regarded as case insensitive. A DataSet can contain two DataTable objects that have the same TableName property value but different Namespace property values. For more information about working with DataTable objects, see Creating a DataTable (ADO.NET).

If you are creating a DataTable programmatically, you must first define its schema by adding DataColumn objects to the DataColumnCollection (accessed through the Columns property). For more information about adding DataColumn objects, see Adding Columns to a DataTable (ADO.NET).

To add rows to a DataTable, you must first use the NewRow method to return a new DataRow object. The NewRow method returns a row with the schema of the DataTable, as it is defined by the table's DataColumnCollection. The maximum number of rows that a DataTable can store is 16,777,216. For more information, see Adding Data to a DataTable.
The DataTable also contains a collection of Constraint objects that can be used to ensure the integrity of the data. For more information, see DataTable Constraints (ADO.NET).
There are many DataTable events that can be used to determine when changes are made to a table. These include RowChanged, RowChanging, RowDeleting, and RowDeleted. For more information about the events that can be used with a DataTable, see DataTable Event Handling.



Public Class Form1
    Dim dt As New DataTable
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim c1 As New DataColumn()
        Try
            c1.DataType = System.Type.GetType("System.Int32")
            c1.ColumnName = "roll"
            c1.AutoIncrement = True
            c1.AutoIncrementSeed = 1
            c1.AutoIncrementStep = 1
            dt.Columns.Add(c1)
            c1 = New DataColumn
            c1.DataType = System.Type.GetType("System.String")
            c1.ColumnName = "name"
            dt.Columns.Add(c1)
            DataGridView1.DataSource = dt
            c1 = New DataColumn
            c1.DataType = System.Type.GetType("System.String")
            c1.ColumnName = "city"
            dt.Columns.Add(c1)
        Catch ex As Exception
            MsgBox("Error in form load " & vbCrLf & ex.Message)
        End Try
    
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        If txtName.Text = "" Or txtCity.Text = "" Then
            MsgBox("plz fill all fields properly")
        Else
            Dim dr As DataRow
            dr = dt.NewRow
            'dr(0) = Val(txtRoll.Text)
            dr(1) = txtName.Text
            dr(2) = txtCity.Text
            dt.Rows.Add(dr)
            DataGridView1.DataSource = dt
        End If
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click



    End Sub

    Private Sub txtRoll_HelpRequested(ByVal sender As System.Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs) Handles txtRoll.HelpRequested
        Help.ShowPopup(txtRoll, "User is restricted to enter value in this field,because it is setup to auto increment", hlpevent.MousePos)
    End Sub
End Class


HelpButton

When this property is set to true, a small button with a question mark appears in the caption bar to the left of the Close button. You can use this button to display help for your application. You can create an event handler for the HelpRequested event of the Control class to display Help information to the user when the Help button of the form is clicked.
The value of the HelpButton property is ignored if the Maximize or Minimize buttons are shown.

HelpRequested Event


Occurs when the user requests help for a control. The HelpRequested event is commonly raised when the user presses the F1 key or an associated context-sensitive help button is clicked.


Public Class Form1

    Private Sub Button1_HelpRequested(ByVal sender As System.Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs) Handles Button1.HelpRequested
        Help.ShowPopup(Button1, "Button is most useful control" & vbCrLf & "to implement some action on click", hlpevent.MousePos)

    End Sub

    Private Sub CheckBox1_HelpRequested(ByVal sender As System.Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs) Handles CheckBox1.HelpRequested
        Help.ShowPopup(CheckBox1, "This is check box " & vbCrLf & "A GUI control that enable you to " & vbCrLf & _
               "select more than one option from multiple choice", hlpevent.MousePos)
    End Sub

    Private Sub DateTimePicker1_HelpRequested(ByVal sender As System.Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs) Handles DateTimePicker1.HelpRequested
        Help.ShowPopup(DateTimePicker1, "This is DateTimePicker " & vbCrLf & "Enable you to select a date", hlpevent.MousePos)
    End Sub

    Private Sub ListBox1_HelpRequested(ByVal sender As System.Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs) Handles ListBox1.HelpRequested
        Help.ShowPopup(ListBox1, "A Windows Forms ListBox control displays" & vbCrLf & " a list of items from which" & vbCrLf & _
                " can select one or more.", hlpevent.MousePos)

    End Sub

    Private Sub RadioButton1_HelpRequested(ByVal sender As System.Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs) Handles RadioButton1.HelpRequested
        Help.ShowPopup(RadioButton1, "Radio Button enables you to " & vbCrLf & "Select one option at a time " & vbCrLf & _
               "From multiple option", hlpevent.MousePos)

    End Sub

    Private Sub PictureBox1_HelpRequested(ByVal sender As System.Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs) Handles PictureBox1.HelpRequested
        Help.ShowPopup(PictureBox1, "This is picture box used to display image on form", hlpevent.MousePos)

    End Sub
End Class


Multiple Tables in Gridview


Gridview a control that is used to display records on form you can show more one table data in grid view by making some tricks.Gridview use data source properties for display records its uses data table . Dataset a class design to hold more that table simultaneously so I setup dataset with more than one table and setup table index to Gridview by combobox.



Imports System.Data.OleDb
Public Class Form1
    Dim con As New OleDbConnection
    Dim ds As New DataSet
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=bsw.mdb"
        Try
            con.Open()
            com.Connection = con
            Dim da As New OleDbDataAdapter("select * from stu", con)

            da.Fill(ds, "stu")
            da = New OleDbDataAdapter("select * from emp", con)
            da.Fill(ds, "emp")

        Catch ex As Exception
            MsgBox("Error form load " & vbCrLf & ex.Message)
        End Try
    End Sub


    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

        DataGridView1.DataSource = ds.Tables(ComboBox1.Text)

    End Sub
End Class


NotifyIcon Class

Specifies a component that creates an icon in the notification area. This class cannot be inherited.

Remarks

Icons in the notification area are shortcuts to processes that are running in the background of a computer, such as a virus protection program or a volume control. These processes do not come with their own user interfaces. The NotifyIcon class provides a way to program in this functionality. The Icon property defines the icon that appears

Controls

1)Notification Icon    2) Button

Properties Setting

Notification Icon
BalloonTipIcon=info

BalloonTipText=This is demo text for notification

BalloonTipTitle=”Girfa”

Text=Girfa Application

Coding


   Private Sub NotifyIcon1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NotifyIcon1.Click
        MsgBox("clicked on notification icon")
    End Sub

    Private Sub NotifyIcon1_BalloonTipClicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NotifyIcon1.BalloonTipClicked
        MsgBox("clicked on icon")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        NotifyIcon1.ShowBalloonTip(2000)
    End Sub

No comments:

Post a Comment