【问题标题】:Lyrics for Music Editor音乐编辑器的歌词
【发布时间】:2013-05-23 20:33:35
【问题描述】:

我正在尝试创建一个 neume (gregorian chant) 编辑器。我确实做了很多,但我在乐谱下的歌词主题上卡住了。

基本上我要解决的问题是:有一些独立的用户控件块。在它们下面应该有放置歌词的文本区域。重点是 - 歌词是富文本(但只有文本 - 没有表格、图像等)。

为了让事情变得更有趣 - 我的用户控件呈现的图像必须知道下面文本中的第一个元音(第一个 neume - 我们称之为注意 - 必须正好放在第一个元音上方)。

我真的很难做到这一点。我考虑过使用RTB,但是重新调整它的大小存在整个问题——歌词的长度基本上可以是无限的——(它向下重新调整大小,而不是向右),以及绑定到RTB 是真的有趣交易。

你能告诉我如何解决这个问题吗?这是一张小图,可以解释 - 我希望 - 我的问题。

非常感谢您!

【问题讨论】:

    标签: wpf editor richtextbox rich-text-editor music-notation


    【解决方案1】:

    您看过 TextBox.GetRectFromCharacterIndex 方法吗?

    http://msdn.microsoft.com/en-us/library/ms603094.aspx

    如果我正确理解了您的问题,您应该能够在上面的示例中得到字母“O”的矩形。

    我有一个类似的问题,我需要在给定文本框的装饰层上绘制“红色波浪线”来表示自定义拼写检查器解决方案(WPF 拼写检查器对我们来说太有限了)。

    这是该实现的部分示例,以防万一。

              //loop through the invalid words and draw the squiggilies
          foreach (var word in rslt)
          {
            //find the index of the start of the invalid word
            int idx1 = tbx.Text.ToLower().IndexOf(word.ToLower());
            //find the index of the end of the invalid word
            int idx2 = idx1 + (word.Length);
    
            if (idx1 == -1)
              continue;
    
            //get a rect defining the location in coordinates of the invalid word.
            var rec1 = tbx.GetRectFromCharacterIndex(idx1);
            var rec2 = tbx.GetRectFromCharacterIndex(idx2);
    
            //if the word is not visible or not fully visible, do not show the red line.
            if (tbx.ActualWidth > 0)
            {
              if (rec1.X < 0 || rec2.X > tbx.ActualWidth)
                continue;
            }
    
            if (rec1.Y < 0)
              continue;
    
            //actually draw the line under the word
            SquigglyAdorner ado = new SquigglyAdorner(tbx, word, rec1.X, rec2.X, rec2.Bottom);
            adornerLayer.Add(ado);
          }
    

    然后获取该矩形并将其转换为屏幕坐标(或您需要的任何坐标)

    【讨论】:

    • 感谢您的回答。可悲的是 - 我不能使用它。你指的是一个 TextBox 而我需要一个 RichTextBox 实例,因为我需要能够格式化文本。
    猜你喜欢
    • 2011-08-07
    • 1970-01-01
    • 1970-01-01
    • 2019-12-29
    • 2021-07-26
    • 2012-12-27
    • 1970-01-01
    • 2021-05-05
    • 1970-01-01
    相关资源
    最近更新 更多