【问题标题】:How to change cursor in custom control?如何更改自定义控件中的光标?
【发布时间】:2013-04-25 05:48:20
【问题描述】:

这是我的自定义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");
}
}

如何将这个controlcursor 更改为我的embedded .ico。我用谷歌搜索了custom controls,找不到任何东西。

谢谢。

【问题讨论】:

  • 你的问题是改变ICON,而不是(鼠标)-CURSOR?
  • 如何将默认光标替换为资源中的自定义 .ICO 文件,因为 WebBrowser 控件只有默认图标可用。

标签: c# .net winforms cursor browser


【解决方案1】:

光标始终由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;

【讨论】:

  • “WebBrowser 控件不支持 Cursor 属性。”我该如何解决这个问题?
  • 我的错。 this 是包含 WebBrowser 控件的表单。所以你可以使用this.TopLevelControl.Cursor来改变光标。
  • 感谢您的帮助;但是,它不起作用。当鼠标在 WebBrowser 控件之外时,它可以工作,但是,当鼠标放在 WebBrowser 控件上时,它会切换回默认光标。 **编辑:this.TopLevelControl.Cursor 也不行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多