日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

限制RICHTEXTBOX的输入的范围

發布時間:2023/12/20 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 限制RICHTEXTBOX的输入的范围 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


?
附件: http://files.cnblogs.com/xe2011/WindowsFormsApplication_LimitRichTextBoxInput.rar

using?System; using?System.Collections.Generic; using?System.ComponentModel; using?System.Data; using?System.Drawing; using?System.Linq; using?System.Text; using?System.Windows.Forms; namespace?WindowsFormsApplication4 { ????public?partial?class?Form1?:?Form ????{ ????????public?Form1() ????????{ ????????????InitializeComponent(); ????????} ??????? #region 設置 和 獲得光標所在的行號///要在本類中初始化 richTextBox1 = this;private int EM_LINEINDEX = 0x00BB;private int EM_LINEFROMCHAR = 0x00C9;[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SendMessage")]public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);/// <summary>/// 獲得光標所在的行號和列號/// </summary>/// <param name="editControl"></param>/// <returns>p.X =列號 p.Y =行號</returns>public Point GetCaretPosition(){int charIndex = (int)SendMessage(richTextBox1.Handle, EM_LINEINDEX, -1, 0);int lineIndex = (int)SendMessage(richTextBox1.Handle, EM_LINEFROMCHAR, charIndex, 0);Point pt = new Point();pt.X = richTextBox1.SelectionStart - charIndex + 1;//Line pt.Y = lineIndex + 1;//Columnreturn pt;}/// <summary>/// 轉到行/// </summary>/// <param name="Line">行號</param>public void jumpLine(int Line){richTextBox1.SelectionStart = SendMessage(richTextBox1.Handle, EM_LINEINDEX, Line - 1, 0);richTextBox1.SelectionLength = 0;richTextBox1.ScrollToCaret();}#endregion 設置 和 獲得光標所在的行號

?

????????//限制文本的能刪除的最小范圍 ????????private?int?nLimiteLength?=?10; ????????private?void?richTextBox1_KeyDown(object?sender,?KeyEventArgs?e) ????????{ ????????????//放置跨行選中文本然后輸入文字 ????????????if?(richTextBox1.SelectedText.IndexOf("\n")?!=?-1) ????????????{ ????????????????Text?=?"MupltiLineSel"; ????????????????e.Handled?=?true; ????????????} ????????????//直接屏蔽的 ????????????//Enter?Ctrl+V?Ctrl+X DEL ????????????if?(e.KeyData?==?Keys.Enter?|| ????????????????e.KeyData?==?(Keys.Control|Keys.V)|| ????????????????e.KeyData?==?(Keys.Control|Keys.X)||          ?e.KeyData?==?Keys.Delete ??       ) ????????????{ ????????????????Text?=?"禁止?Enter?Ctrl+V?Ctrl+X?Space"; ????????????????e.Handled?=?true; ????????????} ????????????int?x?=?GetCaretPosition().X; ???????????? ????????????//BACK? ????????????if?(e.KeyData?==?Keys.Back?) ????????????{ ????????????????if?(x?<?nLimiteLength?+?1) ????????????????{ ????????????????????Text?=?"禁止?Back"; ????????????????????e.Handled?=?true; ????????????????} ????????????} ????????} ??????????? ????????private?void?richTextBox1_KeyPress(object?sender,?KeyPressEventArgs?e) ????????{ ????????????//放置跨行選中文本然后輸入文字 ????????????if?(richTextBox1.SelectedText.IndexOf("\n")?!=?-1) ????????????{ ????????????????Text?=?"MupltiLineSel"; ????????????????e.Handled?=?true; ????????????} ????????????int?x?=?GetCaretPosition().X; ????????????if?(x?<?nLimiteLength) ????????????????e.Handled?=?true; ????????????//space?bar ????????????if?(e.KeyChar?==?'?'?&&?x?<?nLimiteLength) ????????????????e.Handled?=?true; ????????} ????????private?void?timer1_Tick(object?sender,?EventArgs?e) ????????{ ????????????Text?=?String.Format("X={0},Y={1},SelLength={2}",?GetCaretPosition().Y,?GetCaretPosition().X,?richTextBox1.SelectedText.Length); ????????} ????????private?void?Form1_Load(object?sender,?EventArgs?e) ????????{ ????????????//因為輸入漢字能突破上面的限制 ????????????richTextBox1.ImeMode?=?System.Windows.Forms.ImeMode.Off; ????????} ????} }



來自為知筆記(Wiz)



附件列表

?

轉載于:https://www.cnblogs.com/xe2011/p/3780793.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的限制RICHTEXTBOX的输入的范围的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。