Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Search” and”Print” buttons in Web Browser Control Application using C# .net 2.0

Author: Zunnair
Download Source Code : 819_Search Print.zip

In this simple article you will learn that how to make “Search” and ”Print” buttons in Web Browser Application (Web Browser Control Application)

 Create new c# project. Drag one Textbox control, Label, Web Browser control, and three buttons on the windows form.

·         One button will use for loading page which I have discuss in one of my previous articles.

·         Other two buttons will be used to open a search page and print the current page.

 

Now write the following code on Form Load event:

C#

private void LoadFrom_Broswer(object sender, EventArgs e)

        {

            this.Text = "DevAsp WebBrowser Application";

            this.txt_url.Text = "www.devasp.net";

            wbBrwsr.Navigate(txt_url.Text);

 

        }

VB

Private Sub LoadFrom_Broswer(ByVal sender As Object, ByVal e As EventArgs)

        Me.Text = "DevAsp WebBrowser Application"

        Me.txt_url.Text = "www.devasp.net"

        wbBrwsr.Navigate(txt_url.Text)

 

    End Sub

 

Now write the following code on button click event:

For Search button:

C#

private void btn_Search_Click(object sender, EventArgs e)

        {

            wbBrwsr.GoSearch();

        }

VB

 

Private Sub btn_Search_Click(ByVal sender As Object, ByVal e As EventArgs)

        wbBrwsr.GoSearch()

    End Sub

For Print button:

C#

private void btn_Print_Click(object sender, EventArgs e)

        {

             wbBrwsr.Print();

        }

VB

 

Private Sub btn_Print_Click(ByVal sender As Object, ByVal e As EventArgs)

        wbBrwsr.Print()

    End Sub

This code will load default search page sat buy window or internet explorer.

You can also ask user before printing the page that user wants to print the page or not.

 

Code:

C#

 

private void btn_Print_Click(object sender, EventArgs e)

        {

            DialogResult answer = MessageBox.Show("Do you want to print the page", "caption", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (answer == DialogResult.Yes)

                wbBrwsr.Print();

        }

VB

 

Private Sub btn_Print_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim answer As DialogResult = MessageBox.Show("Do you want to print the page", "caption", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

        If answer = DialogResult.Yes Then

            wbBrwsr.Print()

        End If

    End Sub

You can set your own search page by typing following code.

C#

private void btn_Print_Click(object sender, EventArgs e)

        {

            DialogResult answer = MessageBox.Show("Do you want to print the page", "caption", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (answer == DialogResult.Yes)

                wbBrwsr.Print(“www.google.com”);

        }

 

 

 

VB

 

Private Sub btn_Print_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim answer As DialogResult = MessageBox.Show("Do you want to print the page", "caption", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

        If answer = DialogResult.Yes Then

            wbBrwsr.Print(“www.google.com”);

        End If

    End Sub

 

You can also set Search page at run time. For this you will have to take address from user on run time as a string and pass the string as parameter in the above code.

This is the simple code for adding Search and print buttons in web Browser control application.

Article Comments
this is gud example bt i need code of search and primt button in c#2008

Posted on 4/14/2010 1:15:39 AM by tanzila

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Refresh” and”Stop” in Web Browser Control Application using C# .net 2.0

Disclaimer - Privacy
© 2002-2017 DevASP.net