Không có gì tuyệt vời hơn là luyện tập với ví dụ thực tế. Nào cùng nhau thử thách bản thân với một ứng dụng thú vị: Từ điển nói.
Code file Form1.designer.cs
namespace WebB
{
partial class Form1
{
private System.ComponentModel.IContainer components = null ;
protected override void Dispose (bool disposing)
{
if (disposing && (components != null ))
{
components.Dispose();
}
base .Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent ()
{
this .btnAdd = new System.Windows.Forms.Button();
this .btnGo = new System.Windows.Forms.Button();
this .txbAddress = new System.Windows.Forms.TextBox();
this .pnlWeb = new System.Windows.Forms.Panel();
this .SuspendLayout();
this .btnAdd.Location = new System.Drawing.Point(12 , 12 );
this .btnAdd.Name = "btnAdd" ;
this .btnAdd.Size = new System.Drawing.Size(108 , 23 );
this .btnAdd.TabIndex = 0 ;
this .btnAdd.Text = "Add WebBrowser" ;
this .btnAdd.UseVisualStyleBackColor = true ;
this .btnAdd.Click += new System.EventHandler(this .btnAdd_Click);
this .btnGo.Location = new System.Drawing.Point(126 , 12 );
this .btnGo.Name = "btnGo" ;
this .btnGo.Size = new System.Drawing.Size(42 , 23 );
this .btnGo.TabIndex = 1 ;
this .btnGo.Text = "Go" ;
this .btnGo.UseVisualStyleBackColor = true ;
this .btnGo.Click += new System.EventHandler(this .btnGo_Click);
this .txbAddress.Location = new System.Drawing.Point(174 , 15 );
this .txbAddress.Name = "txbAddress" ;
this .txbAddress.Size = new System.Drawing.Size(701 , 20 );
this .txbAddress.TabIndex = 2 ;
this .pnlWeb.Location = new System.Drawing.Point(12 , 41 );
this .pnlWeb.Name = "pnlWeb" ;
this .pnlWeb.Size = new System.Drawing.Size(863 , 418 );
this .pnlWeb.TabIndex = 3 ;
this .AutoScaleDimensions = new System.Drawing.SizeF(6 F, 13 F);
this .AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this .ClientSize = new System.Drawing.Size(896 , 471 );
this .Controls.Add(this .pnlWeb);
this .Controls.Add(this .txbAddress);
this .Controls.Add(this .btnGo);
this .Controls.Add(this .btnAdd);
this .Name = "Form1" ;
this .Text = "Form1" ;
this .ResumeLayout(false );
this .PerformLayout();
}
#endregion
private System.Windows.Forms.Button btnAdd;
private System.Windows.Forms.Button btnGo;
private System.Windows.Forms.TextBox txbAddress;
private System.Windows.Forms.Panel pnlWeb;
}
}
Code Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WebB
{
public partial class Form1 : Form
{
WebBrowser wb;
public Form1 ()
{
InitializeComponent();
}
private void btnAdd_Click (object sender, EventArgs e)
{
wb = new WebBrowser();
wb.Width = 900 ;
wb.Height = 400 ;
wb.DocumentCompleted += wb_DocumentCompleted;
pnlWeb.Controls.Add(wb);
}
void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
MessageBox.Show("Done" );
}
private void btnGo_Click (object sender, EventArgs e)
{
string link = txbAddress.Text;
wb.Navigate(link);
}
}
}
Code DictionaryData.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpeakDictionary
{
public class DictionaryData
{
private string key;
public string Key
{
get { return key; }
set { key = value ; }
}
private string meaning;
public string Meaning
{
get { return meaning; }
set { meaning = value ; }
}
private string explaination;
public string Explaination
{
get { return explaination; }
set { explaination = value ; }
}
}
}
Bài sau chúng ta sẽ cùng nhau thực hiện chức năng nói cho từ điển.
Đừng quên: “Luyện tập – Thử thách – Không ngại khó ”
Tải xuống
Tài liệu
Nhằm phục vụ mục đích học tập Offline của cộng đồng, Kteam hỗ trợ tính năng lưu trữ nội dung bài học Sử dụng webBrowser C# Winform dưới dạng file PDF trong link bên dưới.
Ngoài ra, bạn cũng có thể tìm thấy các tài liệu được đóng góp từ cộng đồng ở mục TÀI LIỆU trên thư viện Howkteam.com
Đừng quên like và share để ủng hộ Kteam và tác giả nhé!
Thảo luận
Nếu bạn có bất kỳ khó khăn hay thắc mắc gì về khóa học, đừng ngần ngại đặt câu hỏi trong phần BÌNH LUẬN bên dưới hoặc trong mục HỎI & ĐÁP trên thư viện Howkteam.com để nhận được sự hỗ trợ từ cộng đồng.
Cho em hỏi khi gọi
string link = txbAddress.Text; wb.Navigate(link);
Không muốn hiện wb lên có được không ạ