Winforms Webbrowser Control : 모든 링크가 새 (IE) 창에서 외부에서 열도록 강제

StackOverflow https://stackoverflow.com/questions/600564

문제

제목이 모든 것을 다루고 있다고 생각합니다. 컨트롤을 사용하여 일부 마크 업이있는 기본 HTML을 표시하며 링크가있을 수 있습니다. 내가하고 싶은 것은 링크를 클릭 하여이 링크를 컨트롤 자체의 해당 페이지로 탐색하는 대신 새 IE 창 에이 링크를 열게하는 것입니다.

아이디어가 있습니까?

도움이 되었습니까?

해결책

탐색 이벤트를 처리하고 WebBrowserNavigatingEventArgs의 취소 속성을 True로 설정하고 Process.Start를 사용하여 IE에서 URL을 열 수 있습니다.

이 같은:

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();
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top