一、cba賽程
在開發過程中,獲取相關信息是必須的。對於賽事信息,我們可以通過瀏覽器打開相關網頁,或者通過webview2控制項進行開發。下面的代碼段演示了如何在webview2中載入中國籃球聯賽的賽程網頁。
private void LoadCbaSchedule()
{
webview2.Source = new Uri("https://cba.sports.sina.com.cn/schedule");
}
二、clash
現在,遊戲類app越來越流行,而有些遊戲需要使用代理才能訪問。這時,我們可以使用clash代理進行開發。下面的代碼展示了如何在webview2中使用clash代理。
private async void LoadPageWithClashProxy()
{
var wk = WebView2Environment.GetAvailableBrowserVersionString();
var proxy = new ProxyRules
{
Rules = @"PROXY 127.0.0.1:7890", //這裡修改成自己的clash代理埠
Bypass = "",
};
var options = new BrowserViewOptions
{
Proxy = proxy,
};
using (var browserView = new BrowserView(options))
{
browserView.Bounds = webView2.Bounds;
webView2.Parent.Controls.Add(browserView);
await browserView.EnsureBrowserWindowReadyAsync();
browserView.Navigate("https://www.google.com.hk/");
}
}
三、cba總決賽
有時我們需要在webview2頁面中嵌入一些特定的內容,比如視頻。下面的代碼展示了如何在webview2控制項中播放優酷上的cba總決賽視頻。
private void LoadCbaFinalsVideo()
{
var html = @"<!DOCTYPE html>
<html>
<body>
<iframe height='100%' width='100%' src='https://player.youku.com/embed/XNDI5MTcxNTEyMA==' frameborder='0' allowfullscreen></iframe>
</body>
</html>";
webview2.NavigateToString(html);
}
四、c開頭的火車是什麼車
對於一些難以確定的問題,我們可以直接使用webview2進行搜索。下面的代碼展示了如何使用Bing搜索引擎搜索「c開頭的火車是什麼車」這個問題。
private void LoadTrainQuestion()
{
webview2.NavigateToString("<!DOCTYPE html><html><head></head><body><form id='form1' action='https://www.bing.com/search' method='get'><div><input id='sb_form_q' name='q' type='text' value='c開頭的火車是什麼車'><input type='submit' value='Search'></div></form></body></html>");
}
五、cctv5在線直播
有時我們需要在webview2頁面中直接展示視頻源,比如CCTV5直播。下面的代碼展示了如何在webview2頁面中嵌入CCTV5直播地址。
private void LoadCctv5Live()
{
var html = @"<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
</head>
<body>
<iframe src='http://tv.cctv.com/live/cctv5/' height='100%' width='100%'></iframe>
</body>
</html>";
webview2.NavigateToString(html);
}
六、cctv5體育節目表
有時候我們需要在webview2中顯示一些數據,比如CCTV5的體育節目表。下面的代碼展示了如何在webview2中嵌入CCTV5的體育節目表頁面。
private void LoadCctv5ProgramSchedule()
{
webview2.Source = new Uri("https://tv.cctv.com/program/sports/05/");
}
七、c1駕照能開什麼車
我們也可以在webview2中嵌入問答頁面,展示用戶所需要的信息。下面的代碼展示了如何在webview2頁面中搜索「c1駕照能開什麼車」這個問題,並將搜索結果展示出來。
private void LoadC1DriverLicenseInfo()
{
webview2.NavigateToString("<!DOCTYPE html><html><head></head><body><form id='form1' action='https://www.baidu.com/s' method='get'><div><input name='wd' type='text' value='c1駕照能開什麼車'><input type='submit' value='Search'></div></form></body></html>");
}
八、c反應蛋白高說明什麼
我們也可以在webview2頁面中嵌入醫學頁面,獲取醫學知識。下面的代碼展示了如何在webview2頁面中搜索「c反應蛋白高說明什麼」這個問題,並將搜索結果展示出來。
private void LoadCReactiveProteinInfo()
{
webview2.NavigateToString("<!DOCTYPE html><html><head></head><body><form id='form1' action='https://www.baidu.com/s' method='get'><div><input name='wd' type='text' value='c反應蛋白高說明什麼'><input type='submit' value='Search'></div></form></body></html>");
}
以上就是c#webview2的完整指南。通過以上代碼示例,我們學習了如何在webview2中載入不同類型的內容,並演示了一些webview2常用的操作。希望本文對大家的學習和開發工作有所幫助。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/251021.html
微信掃一掃
支付寶掃一掃