首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gambas3设置光标位置

Gambas3设置光标位置
EN

Stack Overflow用户
提问于 2022-06-10 19:02:08
回答 1查看 35关注 0票数 0

我正在为富文本使用qt5 TextEdit in Gambas3。

请考虑守则:

代码语言:javascript
复制
    Dim cursorpos As Integer

  If Key.Code = Key.Left Or Key.Code = Key.Up Or Key.code = Key.Right Or Key.Code = Key.Down Or Key.Code = Key.Delete Or Key.Code = Key.Backspace Then
    
    cursorpos = TextEdit1.Pos ' just pick the position
    Print cursorpos
    
  Else 
    cursorpos = TextEdit1.Pos
    Print cursorpos
    TextEdit1.RichText = "<font color = \"#224444\">" & Replace(TextEdit1.Text, gb.NewLine, "<br>") & "</font>" ' this preserves the newlines, and replaces them with a <br> for the rich text
    Print "setting : ", cursorpos ' prints the correct value
    TextEdit1.Pos = cursorpos ' does not work
    Print "got : ", TextEdit1.Pos ' jumps to the end of the string
  Endif

现在,我写道:

代码语言:javascript
复制
This si a line
this is a second line

我在第一行有个错误。我用我的箭钥匙到达那里。我点击了两次backspace,并删除了单词si。一切都很好。现在我希望输入字符i,光标应该停留在字符i之后,但是一旦输入了正确的位置,光标就会跳到文本的末尾。

请帮帮忙。如何将光标位置保持在正确的位置?谢谢。

EN

回答 1

Stack Overflow用户

发布于 2022-10-19 02:02:57

你的错误是这一行..。

代码语言:javascript
复制
TextEdit1.RichText = "<font color = \"#224444\">" & Replace(TextEdit1.Text, gb.NewLine, "<br>") & "</font>" 
' this preserves the newlines, and replaces them with a <br> for the rich text

实际上,它删除了隐藏的原始RichText格式。

在不改变内部RichText格式的情况下,更改文本内联颜色的最佳方法是这样做.

代码语言:javascript
复制
TextEdit1.Format.Color = Color.Red

然后在那个位置输入的文本将是红色的。

这样您就可以监视Delete / Backspace,然后在当前位置将格式颜色设置为红色。

gambaswiki.org/wiki/comp/gb.qt4.ext/textedit

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72578815

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档