WinForms عناصر WebBrowser التحكم: فرض جميع الروابط لفتح خارجيا في نافذة جديدة (IE)
-
03-07-2019 - |
سؤال
وأعتقد أن العنوان يشمل كل شيء. يمكنني استخدام عنصر التحكم إلى عرض بعض HTML الأساسية مع بعض هوامش الربح، وهناك ربما يربط أيضا هناك. ما أريد القيام به، هو اجبار النقر على أي رابط للحصول على هذا الرابط فتح في IE نافذة جديدة بدلا من التنقل إلى تلك الصفحة في التحكم نفسه.
وأي فكرة؟
المحلول
ويمكنك التعامل مع هذا الحدث التصفح، تعيين الغاء خاصية WebBrowserNavigatingEventArgs إلى true، واستخدام Process.Start لفتح URL في IE.
وشيء من هذا القبيل:
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
// prevents WebBrowser to navigate
if (e.Url.Host.Length > 0) // Otherwise the default about:blank when you init the control doesn't work
{
e.Cancel = true;
// Open the URL in an IE window
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = e.Url.ToString();
process.Start();
}
}
لا تنتمي إلى StackOverflow