如何使上下文项目以垂直线显示? [英] How do make context items to display in a vertical line?

查看:78
本文介绍了如何使上下文项目以垂直线显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使ContextMenu在VB.NET中以垂直线显示项目?



我的问题是当项目是在上下文中显示,它们每行显示一个字符。





这是我的问题代码:



How do make a ContextMenu to display items in a vertical line in VB.NET?

My problem is that when items are displayed in the context, they are displayed one character per line.


Here is my problem code:

Public Class Form1
    Friend WithEvents RichTextBox1 As New RichTextBox With {.Dock = DockStyle.Fill}
    Friend WithEvents ReplaceMenu As New ContextMenuStrip

    Private replacements As New Dictionary(Of String, String)


    Private nextCheckIndex As Integer

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Controls.Add(RichTextBox1)


        replacements.Add("a bad advice", "a bad suggestion")
        replacements.Add("antelope", "gazelle")
        replacements.Add("awkward", "clumsy")
        replacements.Add("anxiety", "stress")


        RichTextBox1.Text = "You are anxiety a bad antelope, irregardless of your a bad advice. You provided a bad advice, irregardless of your intention. "
    End Sub

推荐答案

在您的例程 CheckForReplacementText 中放置一个断点,并检查
Put a breakpoint inside your routine CheckForReplacementText and examine what is returned by
For Each replacement In replacements(checkWord)

替换(checkWord)返回一个字符串 - 第一次绕它返回一个错误的建议。所以对于每个循环循环遍历该字符串中的各个字符,而不是您所相信的,字典中的每个条目。



你也有一些关于如何跟踪你已经提出的建议的问题......不确定为什么你认为递归是必要的,但如果你打算使用它,记得增加 nextCheckIndex 适当地



- 如何 checkWord 应添加到上下文菜单

replacements(checkWord) returns a single String - first time around it returns "a bad advice". So that For Each loop is looping around the individual characters in that string, not as you believed, each of the entries in the Dictionary.

You also have some issues around how you are keeping track of which suggestions you have already made ... not sure why you think recursion is necessary, but if you are going to use it remember to increment nextCheckIndex appropriately

- how checkWord should be added to the context menu

With ReplaceMenu.Items.Add(replacements(checkWord))
    .AutoToolTip = True
    .ToolTipText = replacements(checkWord)
End With


这篇关于如何使上下文项目以垂直线显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆