Pages

Monday, December 9, 2013

How to add web browser in C#

The Web Browser control in C# allows you to host Web pages and other web browser enabled documents in your Windows Forms applications. You can add browser control in your C# projects and it displays the web pages like normal commercial web browsers .You can use the Browser control to provide integrated HTML based user assistance or Web browsing capabilities in your application.



The The Web Browser control has several properties, methods, and events related to navigation. The following C# program displays a web page in browser window and also you can retrieve the source code of the same web page with another button click.

using System;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            webBrowser1.Navigate(textBox1.Text );
        }

        private void button2_Click(object sender, EventArgs e)
        {
            String source = ("viewsource.txt");
            StreamWriter writer = File.CreateText(source);
            writer.Write(webBrowser1.DocumentText);
            writer.Close();
            Process.Start("notepad.exe", source);
        }
    }
}

Sunday, December 8, 2013

How to find IP Adress of a computer

Network programming in windows is possible with sockets . C# simplifies network programming through its namespaces like System.Net and System.Net.Sockets . The System.Net classes provide functionalities that is similar to Microsoft WinInet API.

The System.net namespace provides the information about IP Address . The following C# program shows how to find the IP Address of a host.

using System;
using System.Windows.Forms;
using System.Net;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                IPHostEntry hostname = Dns.GetHostByName(textBox1.Text );
                IPAddress[] ip = hostname.AddressList;
                textBox2.Text  = ip[0].ToString(); 
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

How to find hostname of a computer in c#.net

The System.Net classes provide functionalities that is similar to Microsoft WinInet API , it allows classes to communicate with other applications by using the Hypertext Transfer Protocol (HTTP), Transmission Control Protocol (TCP), User Datagram Protocol (UDP), and Socket Internet protocols.
The following C# program show how to find the Host name of a computer.

  Dns.GetHostName()

using System;
using System.Net;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show (Dns.GetHostName());
        }
    }
}

Monday, December 2, 2013

Generating Random date and time




private void button1_Click(object sender, EventArgs e)
{
DateTime dt = new DateTime();
dt=DateTime.Now.AddDays(new Random().Next(1000));
MessageBox.Show(dt.ToString());

}

How to Remove Underline from Link button in asp.net?

It's very easy to remove Underline from Linkbutton. 

We can do it by following ways:- 

1). Write inline style property as 


<asp:LinkButton id="lnk_view" runat="server" Text="View Details" style="text-decoration: none; color: blue;">View Details</asp:LinkButton>


2).We can make a CSS for it 


 <style type="text/css">
        .link_Under_line_Blue
        {
            text-decoration: none;
            color: blue;
        }

    </style>

And in link button we can write as:-

<asp:LinkButton id="lnk_view" runat="server" Text="View Details" CSS="link_Under_line_Blue">View Details</asp:LinkButton>


And also every time you click on Linkbutton,the color of linkbutton will be remain as Blue with the help of "color:blue" style property.

Working with Promt in Javascript


Like Console application in Dot net,we can use the same thing with the help of Prompt in Javascript.Prompt means asking a user to enter something in the input box. 

We can understand it by an example:- 
Make a Javascript function as below:- 

 <script type="text/javascript">
        function prompt_alert() {
            var value = "";
            var name = prompt("Please enter your name", "Nayab");
            if (name != null) {
                value = name;
                alert(value);
            }
        }
    </script>

So,it's easy to understand about Prompt.