第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

右鍵單擊單詞建議(Hunspell)

右鍵單擊單詞建議(Hunspell)

C#
慕標(biāo)琳琳 2022-07-23 08:57:13
我有一個(gè) Richtextbox 和 ContextMenuStrip,它們可以剪切、復(fù)制、過去和選擇所有它們都可以在沒有問題的情況下工作,但現(xiàn)在我嘗試添加單詞建議,比如用戶選擇一個(gè)單詞并右鍵單擊它應(yīng)該向他顯示的 Richtextbox:詞建議詞建議詞建議...ETC“越線”切復(fù)制過去的“越線”全選這是應(yīng)該的,但問題是建議列表在每次右鍵單擊時(shí)都會(huì)保持重復(fù)(在我選擇單詞之后)這是代碼:ContextMenuStrip cms = new ContextMenuStrip { ShowImageMargin = true };public void AddContextMenu(RichTextBox rtb)    {       if (rtb.ContextMenuStrip == null)        {            ToolStripMenuItem tsmiCut = new ToolStripMenuItem("Cut");            tsmiCut.Image = msg.Properties.Resources.cut;            tsmiCut.Click += (sender, e) => rtb.Cut();            cms.Items.Add(tsmiCut);            ToolStripMenuItem tsmiCopy = new ToolStripMenuItem("Copy");            tsmiCopy.Image = msg.Properties.Resources.copy;            tsmiCopy.Click += (sender, e) => rtb.Copy();            cms.Items.Add(tsmiCopy);            ToolStripMenuItem tsmiPaste = new ToolStripMenuItem("Paste");            tsmiPaste.Image = msg.Properties.Resources.paste;            tsmiPaste.Click += (sender, e) => rtb.Paste();            cms.Items.Add(tsmiPaste);            cms.Items.Add("-");            ToolStripMenuItem sALL = new ToolStripMenuItem("Select All");            sALL.Image = msg.Properties.Resources.select_all;            sALL.Click += (sender, e) => rtb.SelectAll();            cms.Items.Add(sALL);            rtb.ContextMenuStrip = cms;        }    }private void richTextBox_MouseDown(object sender, MouseEventArgs e)    {        Hunspell hunspell = new Hunspell("en_US.aff", "en_US.dic");        hunspell.Spell(richTextBox.SelectedText);        List<string> suggestions = hunspell.Suggest(richTextBox.SelectedText);        ToolStripSeparator line = new ToolStripSeparator();        AddContextMenu(richTextBox);
查看完整描述

1 回答

?
皈依舞

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超3個(gè)贊

您需要一個(gè)契約來區(qū)分建議菜單項(xiàng)和其余菜單項(xiàng),然后在添加建議時(shí),首先刪除現(xiàn)有建議項(xiàng),然后添加新項(xiàng)。


這里作為一個(gè)例子,我使用Tag的屬性ToolStripMenuItem作為合同,并且所有suggestion在其標(biāo)簽中的菜單條項(xiàng)目都被視為建議:


public void Suggest(List<string> words, ContextMenuStrip menu)

{

    string suggestion = "suggestion";

    menu.Items.Cast<ToolStripItem>().Where(x => x.Tag == (object)suggestion)

        .ToList().ForEach(x => menu.Items.Remove(x));


    words.ToList().ForEach(x =>

    {

        var item = new ToolStripMenuItem(x);

        item.Tag = suggestion;

        item.Click += (s, e) => MessageBox.Show(x);

        menu.Items.Insert(0, item);

    });

}

作為用法,一句話:


Suggest(new List<string> { "something", "something else" }, contextMenuStrip1);

換個(gè)說法:


Suggest(new List<string> { "another", "another one" }, contextMenuStrip1);


查看完整回答
反對(duì) 回復(fù) 2022-07-23
  • 1 回答
  • 0 關(guān)注
  • 113 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)