|
Search and Print buttons in Web Browser Control Application using C# .net |
|
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
- 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 = "It Projects For You WebBrowser Application";
this.txt_url.Text = "www.itprojectsforyou.com";
wbBrwsr.Navigate(txt_url.Text);
}
|
VB.Net
|
|
|
|
Private Sub LoadFrom_Broswer(ByVal sender As Object,ByVal e As EventArgs)
{
Me.Text = "It Projects For You WebBrowser Application";
Me.txt_url.Text = "www.itprojectsforyou.com";
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.Net |
|
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.Net |
|
Private Sub btn_Print_Click(ByVal sender As Object,ByVal e As EventArgs)
wbBrwsr.Print()
End Sub
|
|
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.Net
|
|
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.Net
|
|
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
|
|
This is the simple code for adding Search and print buttons in web Browser control application.
|