ComponentOne RichTextBox 实现更改鼠标形状

发布时间:2013/10/13 00:10 发布者:iceman

返回博客中心

在本篇文章中我们将讨论如何在 C1RichBoxTextBox 中实现更改鼠标形状的功能。例如,我们的 RichTextBox 文档中包含 Paragraph 和 Table 。我们想实现当鼠标悬浮在 Table 上时改变鼠标形状,当鼠标离开 Table 时还原鼠标形状。

效果图

MouseCursorChanging

首先需要准备文档中显示的内容:

  1:    string myHTMLString =
  2: @"<html><head><style type='text/css'>.c0 { font-family: 'Verdana'; font-size: 18.6666666666667px } .c1 { margin: 0px 0px 12px } .c2 { font-family: 'Arial'; font-size: 13.3333333333333px } .c3 { margin: 0px 0px 10px } .c4 { border-collapse: collapse; width: 100% } .c5 { width: 33% } .c6 { border-color: Black; border-style: solid; border-width: thin; padding: 0px 7px } .c7 { margin: 0px } .c8 { font-family: 'Arial'; font-size: 13.33px } </style></head><body class='c0'><p class='c1'><span class='c2'>This table has 2 rows and 3 columns. Mouse pointer wil change to hand cursor when hovered over the table text.</span></p><p class='c3'><span class='c2'>&#x200b;</span></p><table class='c4'><col class='c5'/><col class='c5'/><col class='c5'/><tr><td class='c6'><p class='c7'>row1 col1</p></td><td class='c6'><p class='c7'>row1 col2</p></td><td class='c6'><p class='c7'>row1 col3</p></td></tr><tr><td class='c6'><p class='c7'>row2 col1</p></td><td class='c6'><p class='c7'>row2 col2</p></td><td class='c6'><p class='c7'>row2 col3</p></td></tr></table><p class='c3'><span class='c2'>&#x200b;</span></p><div><p class='c1'><span class='c8'>This table has 2 rows and 3 columns. Mouse pointer wil change to hand cursor when hovered over the table text.</span></p></div><p class='c3'><span class='c2'>&#x200b;</span></p></body></html>";

 

通过 ConvertToDocument 方法转换为 C1RichTextBox 文档内容:

  1: C1RichTextBox1.Document = C1RichTextBox1.HtmlFilter.ConvertToDocument(myHTMLString);


通过 ComponentOne RichTextBoxElementMouseMove  事件来实现鼠标形状切换功能:

  1: void C1RichTextBox1_ElementMouseMove(object sender, MouseEventArgs e)
  2:    {
  3:       var element = sender as C1TextElement;
  4:       if (element != null && element.GetParents().Any(p => p is C1Table))
  5:          {
  6:             C1RichTextBox1.Cursor = Cursors.Hand;
  7:          }
  8:       else
  9:          {
 10:              C1RichTextBox1.Cursor = Cursors.IBeam;
 11:          }
 12:    }

 

Demo 下载:

C#+VS2010+WPF+Studio for WPF 2013V2.5 点击下载


关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网