Pages

Sunday, 14 October 2012

Create a VB.NET application displaying the use of dialog control. Include all the five dialog controls like OpenFileDialog,SaveFileDialog,FolderBrowserDialog,FontDialog,ColorDialog.

Create a VB.NET application displaying the use of dialog control. Include all the five dialog controls like OpenFileDialog,SaveFileDialog,FolderBrowserDialog,FontDialog,ColorDialog.

Description:
In this post we are going to learn the use of dialog control. Include all the five dialog controls like OpenFileDialog,SaveFileDialog,FolderBrowserDialog,FontDialog,ColorDialog.

Open Microsoft visual studio
File-> New -> Project -> visual vb -> Windows Forms Application.

Program:
Take 6 button on the top.
now drag and drop all five dialog OpenFileDialog,SaveFileDialog,FolderBrowserDialog,FontDialog,ColorDialog on the form it will automatically go to bellow as shown in figure.



Create a VB.NET application displaying the use of dialog control. Include all the five dialog controls like OpenFileDialog,SaveFileDialog,FolderBrowserDialog,FontDialog,ColorDialog.
Create a VB.NET application displaying the use of dialog control. Include all the five dialog controls like OpenFileDialog,SaveFileDialog,FolderBrowserDialog,FontDialog,ColorDialog.



take text field and PictureBox as shown in figure.

now double click on all button turn by turn and paste the code as shown in below. 


Public Class Form1

    Private Sub btnopen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnopen.Click
        OpenFileDialog1.Title = "open"
        OpenFileDialog1.InitialDirectory = "D:\"
        If OpenFileDialog1.ShowDialog() <> Windows.Forms.DialogResult.Cancel Then
            PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
        End If
    End Sub

    Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
        SaveFileDialog1.Title = "Save As"
        SaveFileDialog1.Filter = "TXT Files (*.txt*)|*.txt*"
        If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, TextBox1.Text, True)

        End If

    End Sub

    Private Sub btnbrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbrowse.Click
        FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer
        FolderBrowserDialog1.SelectedPath = "D:\"
        If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            TextBox1.Text = FolderBrowserDialog1.SelectedPath
        End If
    End Sub

    Private Sub btnfont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfont.Click
        If FontDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
            TextBox1.Font = FontDialog1.Font
            TextBox1.ForeColor = FontDialog1.Color
        End If
    End Sub

    Private Sub btncolor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncolor.Click
        If ColorDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
            TextBox1.BackColor = ColorDialog1.Color
        End If
    End Sub

    Private Sub btnuser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnuser.Click
        Dim frm As Form2 = New Form2
        frm.TextBox1.Text = Me.TextBox1.Text
        frm.ShowDialog()
    End Sub
End Class


Write a program in asp.net C# to create read only properties & write only properties i.e public,private.

Write a program in  asp.net C# to create read only properties & write only properties i.e public,private.

Description:
In this post we are going to learn read only properties & write only properties i.e public,private. 

Open Microsoft visual studio
File-> New -> Project -> visual c#-> console Application

Program:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace readandwrite
{
    class Program
    {
        static void Main(string[] args)
        {
            select choice = new select();
            choice.name1 = "sizar";
            choice.age1 = 21;
            Console.WriteLine("My Name is: " + choice.name1);
            Console.WriteLine("My Age is:" + choice.age1);
            choice.age1++;
            Console.WriteLine("AGE is Incremented");
            Console.WriteLine("My Name is: " + choice.name1);
            Console.WriteLine("My Age is:" + choice.age1);
            Console.ReadLine();
        }
    }
}
public class select
{
    private String name;
    private int age;
    public String name1
    {
        get
        {
            return name;
        }
        set
        {
            name = value;
        }
    }

    public int age1
    {
        get
        {
            return age;
        }
        set
        {
            age = value;
        }

    }
}

Demo:


Write a program in  asp.net C# to create read only properties & write only properties i.e public,private.
Write a program in  asp.net C# to create read only properties & write only properties i.e public,private.






Write a C# program to demonstrate function overloading

Write a C# program to demonstrate function overloading

Description:
In this post we are going to learn function overloading.

Open Microsoft visual studio
File-> New -> Project -> visual c#-> console Application

Program:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _6.FunctionOverloading
{
    class Program
    {
        static void Main(string[] args)
        {
            shape s = new shape();
            s.area(5);
            s.area(5, 2);
        }
    }
    class shape
    {
        public void area(int a)
        {
            int c = a * a;
            Console.WriteLine("Square  area:{0}",c);
            Console.ReadLine();
        }

        public void area(int a,int b)
        {
            int d = a * b;
            Console.WriteLine("Rectangle area:{0}",d);
            Console.ReadLine();
        }
    }
}

Demo:

Write a C# program to demonstrate function overloading
Write a C# program to demonstrate function overloading




Write a C# program to print student details using constructor and destructor.

Write a C# program to print student details using constructor and destructor.

Description:
In this post we are going to learn constructor and destructor.

Open Microsoft visual studio
File-> New -> Project -> visual c#-> console Application

Program:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _5.Constructor
{
    class Program
    {
        static void Main(string[] args)
        {
            student s = new student("sizar",21);                                                                    
            Console.ReadKey();
   }
    }
    public class student
    {
        String name;
        int id;
        public student(String name, int id)
        {
            this.name = name;
            this.id = id;
            Console.WriteLine("\n Constructor Called..!\n");
            Console.WriteLine("Student Name:{0}",name);
            Console.WriteLine("Student id:{0}", id);
        }
        ~student()
        {
            Console.WriteLine("\nDestructor Called..!");
            Console.ReadLine();
        }
    }


Demo:
Write a C# program to print student details using constructor and destructor.
Write a C# program to print student details using constructor and destructor.
                              

Write a C# program to print student details using constructor and destructor.
Write a C# program to print student details using constructor and destructor.
                     



Download Code:

Saturday, 13 October 2012

Design form to create calculator application in VB

Design form to create calculator application in VB

Description:

In this post we are going to learn how to make a calculator in vb 
Open Microsoft visual studio
File-> New -> Project -> visual vb ->  Windows Application

Program:

Design a window form as shown in figure in vb


Design form to create calculator application in VB
Design form to create calculator application in VB

now double click on 1 button. code file will open with this code.

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
       
    End Sub

add code 

 txtans.Text = txtans.Text + "1"

 above " End Sub " as shown below do this for all button.


Imports System.Math
Public Class Form1
    Dim s As String
    Dim a As Double
    Dim x As Double
    Dim b As Double
    Dim c As Double
    Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
        txtans.Text = txtans.Text + "1"
    End Sub

    Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
        txtans.Text = txtans.Text + "2"
    End Sub

    Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
        txtans.Text = txtans.Text + "3"
    End Sub

    Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
        txtans.Text = txtans.Text + "4"
    End Sub

    Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
        txtans.Text = txtans.Text + "5"
    End Sub

    Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
        txtans.Text = txtans.Text + "6"
    End Sub

    Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
        txtans.Text = txtans.Text + "7"
    End Sub

    Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
        txtans.Text = txtans.Text + "8"
    End Sub

    Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
        txtans.Text = txtans.Text + "9"
    End Sub

    Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
        txtans.Text = txtans.Text + "0"
    End Sub

    Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
        a = Convert.ToDouble(txtans.Text)
        txtans.Text = ""
        x = 1
    End Sub

    Private Sub btnsub_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsub.Click
        a = Convert.ToDouble(txtans.Text)
        txtans.Text = ""
        x = 2
    End Sub

    Private Sub btnmul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmul.Click
        a = Convert.ToDouble(txtans.Text)
        txtans.Text = ""
        x = 3
    End Sub

    Private Sub btndiv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndiv.Click
        a = Convert.ToDouble(txtans.Text)
        txtans.Text = ""
        x = 4
    End Sub

    Private Sub btneql_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneql.Click
        b = Convert.ToDouble(txtans.Text)
        txtans.Text = ""
        Select Case x
            Case 1
                c = a + b
                txtans.Text = c
            Case 2
                c = a - b
                txtans.Text = c
            Case 3
                c = a * b
                txtans.Text = c
            Case 4
                c = a / b
                txtans.Text = c
            Case 5
                c = a * a
                txtans.Text = c
            Case 6
                c = a
                txtans.Text = c
            Case Else
        End Select
    End Sub

    Private Sub btnsquare_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsquare.Click
        a = Convert.ToDouble(txtans.Text)
        x = 5
    End Sub

    Private Sub btbdot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btbdot.Click
        txtans.Text = txtans.Text + "."

    End Sub

    Private Sub btnsqrt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsqrt.Click
        a = Convert.ToDouble(txtans.Text)
        a = Sqrt(a)
        x = 6
    End Sub

    Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click
        a = 0
        b = 0
        c = 0
        x = 0
        s = ""
        txtans.Text = ""
    End Sub

    
End Class

Demo:

Design form to create calculator application in VB
Design form to create calculator application in VB

Design form to create calculator application in VB
Design form to create calculator application in VB

Design form to create calculator application in VB
Design form to create calculator application in VB

Design form to create calculator application in VB
Design form to create calculator application in VB




Write a program in C# to create a base class shape and derived classes i.e., Rectangle, Circle, and Triangle. Invoke the method from base class shape using polymorphism

Write a program in C# to create a base class shape and derived classes i.e., Rectangle, Circle, and Triangle. Invoke the method from base class shape using polymorphism

Description:

In this post we are going to learn Polymorphism and call base class from derived class.
Open Microsoft visual studio
File-> New -> Project -> visual c#-> console Application

Program:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Polymorphism
{
    class shape
    {
  public void Callme()
        {
           Console.WriteLine("Shape is called");
        }
    }
    class rect:shape
    {
        public void Callme()
{
        Console.WriteLine("Rectangle is called");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            shape s = new shape();
            rect a = new rect();
            a.Callme();
            Console.Read();
        }
    }
}

Demo:

Write a program in C# to create a base class shape and derived classes i.e., Rectangle, Circle, and Triangle. Invoke the method from base class shape using polymorphism
Write a program in C# to create a base class shape and derived classes i.e., Rectangle, Circle, and Triangle. Invoke the method from base class shape using polymorphism