2013-04-25 45 views
1

這是我的自定義WebBrowser control如何更改自定義控件中的光標?

using System; 
using System.Text.RegularExpressions; 
using System.Windows.Forms; 

public class RunescapeClient : WebBrowser 
{ 
    private const string RUNESCAPE_CLIENT_URL = "http://oldschool33.runescape.com/j1"; 

public RunescapeClient() 
{ 
    ScrollBarsEnabled = false; 
    ScriptErrorsSuppressed = true; 
    IsWebBrowserContextMenuEnabled = false; 
    AllowWebBrowserDrop = false; 
    Navigate(RUNESCAPE_CLIENT_URL); 
} 

protected override void OnDocumentCompleted(WebBrowserDocumentCompletedEventArgs e) 
{ 
    if (Document != null && ValidClientUrl(e.Url.ToString())) 
    { 
     HtmlElement tableElement = Document.GetElementsByTagName("table")[1]; 
     tableElement.InnerText = string.Empty; 
    } 
} 

private static bool ValidClientUrl(string url) 
{ 
    return Regex.IsMatch(url, @"http://oldschool\d{1,2}.runescape.com/j1"); 
} 
} 

我怎樣才能改變cursorcontrolembedded .ico。我GOOGLE了一下,找不到任何東西custom controls

謝謝。

+0

你的問題是要改變圖標,而不是(鼠標)-cursor? – joe 2013-04-25 06:21:23

+0

如何將我的資源中的自定義.ICO文件替換爲DEFAULT遊標,因爲WebBrowser控件只有默認圖標可用。 – Andrew 2013-04-25 06:28:04

回答

0

遊標始終由Cursor屬性更改。如果您有自定義控件,則無關緊要。

試試這個:

Icon ico = new Icon(@"C:\temp\someIcon.ico"); 
this.Cursor = new Cursor(ico.Handle); 

靜態類System.Windows.Forms.Cursors包含了所有的系統光標。
要切換回默認的系統光標,使用此:

this.Cursor = System.Windows.Forms.Cursors.Default; 
+0

「WebBrowser控件不支持Cursor屬性。」我將如何解決這個問題? – Andrew 2013-04-25 06:58:56

+0

我的不好。 'this'是包含WebBrowser控件的表單。所以你可以使用'this.TopLevelControl.Cursor'來改變光標。 – joe 2013-04-25 07:20:55

+1

我感謝您的幫助;但是,它不起作用。當鼠標在WebBrowser控件外部時,它可以工作,但是,當鼠標放在WebBrowser控件上時,它會切換回默認光標。 **編輯:this.TopLevelControl.Cursor不如。 – Andrew 2013-04-25 07:26:24