iT邦幫忙

0

[winform] richtextbox 游標移除

  • 分享至 

  • twitterImage

大家好:

我用richtextbox用enabled disable 游標不會顯示,但背景會是灰的不是白的
https://ithelp.ithome.com.tw/upload/images/20201020/20097057HyhYa97f2s.png
請問要如何禁止打字,但按附加檔案鈕時可以把附件路徑插入,刪除可以用滑鼠點要刪的檔案然後按鍵盤delete掉就可以。

目前只做到可以將檔案路徑寫入,但按Backsapce刪除就刪掉路徑,但加下一筆時,會跳空白一行
https://ithelp.ithome.com.tw/upload/images/20201020/20097057sG1CC8Pvph.png

public class Submethod
        {
            public void Attachment(Form3 f2) //建構函式
            {
                long totalsize = 0;
                OpenFileDialog file = new OpenFileDialog();
                file.Multiselect = true;
                file.Title = "開啟";
                if (file.ShowDialog() == DialogResult.OK)
                {
                    String[] filename = file.FileNames;
                    
                    foreach (string item in filename) { 
                    totalsize += new FileInfo(item).Length;
                    f2.label1.Text = (totalsize + Convert.ToInt32(f2.label1.Text)).ToString();//只有增加沒辦法減少
    
                    f2.AttachText.AppendText(item+"("+new FileInfo(item).Length/1024+"kB)"+ Environment.NewLine);

                    }

                    if (Convert.ToInt32(f2.label1.Text) > 15000000)
                    {
                        MessageBox.Show("總檔案超過20M,請刪除附件");
                    }
                }
            }
        }
        private void AttachBn_Click(object sender, EventArgs e)
        {
            Form3 fm1 = this;
            Submethod Obj = new Submethod();
            Obj.Attachment(fm1);
        }

謝謝

mayyola iT邦研究生 2 級 ‧ 2020-10-20 20:14:35 檢舉
好像改成listbox就達到我想要的..
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
japhenchen
iT邦超人 1 級 ‧ 2020-10-21 08:02:51
最佳解答

在不改變RichTextBox的情況下,不用enabled = false 也能達到無法打字的目的

private void Form1_Load(object sender, EventArgs e)
{
    richTextBox1.KeyDown += (s, ev) => 
        { ev.Handled = true; };
    richTextBox1.KeyPress += (s, ev) => 
        { ev.Handled = true; };
            
    richTextBox1.Text = "test12345";
}

mayyola iT邦研究生 2 級 ‧ 2020-10-21 09:07:05 檢舉

謝謝您 晚點來試試!!

我要發表回答

立即登入回答