Esempio n. 1
0
        private void ClearSelection()
        {
            if (SelectionLength == 0)
            {
                return;
            }
            if (SelectedText.Length == base.Text.Length)
            {
                base.Text = 0.ToString(m_valueFormatStr);
                return;
            }
            int selLength = SelectedText.Length;

            if (SelectedText.IndexOf(m_decimalSeparator) >= 0)
            {
                selLength--;
            }
            SelectionStart += SelectedText.Length;
            SelectionLength = 0;

            for (int k = 1; k <= selLength; k++)
            {
                DeleteText(Keys.Back);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// clear base.SelectedText
        /// </summary>
        private void ClearSelection()
        {
            if (SelectionLength == 0)
            {
                return;
            }

            if (SelectedText.Length == base.Text.Length)
            {
                base.Text = 0.ToString(m_valueFormatStr);
                return;
            }

            var selLength = SelectedText.Length;

            if (SelectedText.IndexOf(m_decimalSeparator) > -1)
            {
                selLength--; // selected text contains dot(.), selected length minus 1
            }

            SelectionStart += SelectedText.Length; // after selected text
            SelectionLength = 0;

            for (var k = 1; k <= selLength; k++)
            {
                DeleteText(Keys.Back);
            }
        }
Esempio n. 3
0
 bool CheckKey(char _KeyChar)
 {
     if (_KeyChar == 8 || _KeyChar == 13 || _KeyChar >= 48 && _KeyChar <= 57)
     {
         //if (DataType == EnumType.Double)
         //{
         //     if (DisFormat=="0.0"&&Text.IndexOf(".") == Text.Length - 2 && _KeyChar >= 48 && _KeyChar <= 57) return false;
         //     else if (DisFormat == "0.0000" && Text.IndexOf(".") == Text.Length - 5 && _KeyChar >= 48 && _KeyChar <= 57) return false;
         //     return true;
         //}
         //else
         return(true);
     }
     if (DataType == EnumType.Double)
     {
         if (_KeyChar == '.')
         {
             return(Text.IndexOf(".") == -1 || SelectedText.IndexOf(".") != -1);
         }
     }
     if (DataType == EnumType.Double || DataType == EnumType.Integer)
     {
         if (canBeMinus == false)
         {
             return(false);
         }
         if (_KeyChar == '-')
         {
             return(SelectionStart == 0 && Text.IndexOf("-") == -1 || SelectedText.IndexOf("-") != -1);
         }
     }
     return(false);
 }
Esempio n. 4
0
        private void CodeEditor_SelectionChanged(object sender, RoutedEventArgs e)
        {
            TextToHighlight = null;
            //Get caret position and highlight the blocks that are needed
            int caretPosition = CaretIndex;

            //If the caret is not valid, caret reset
            if (caretPosition < 1 || caretPosition >= Text.Length)
            {
                return;
            }
            //Check if the selected text is a word and fi we can highlight it
            if (SelectedText.IndexOf(' ') == -1)
            {
                //If only accepted chars and is there more than once
                if (Regex.IsMatch(SelectedText, @"(?i)^[a-z_\-0-9]+") &&
                    Regex.Matches(Text, SelectedText).Count > 1)
                {
                    TextToHighlight = new Regex(@"\b" + SelectedText + @"\b");
                }
            }
            //if the caret is near an opening bracket, the caret can be before or after the caret
            if (Text.Substring(caretPosition, 1).Contains("{"))
            {
                openBracketPos  = caretPosition;
                closeBracketPos = CodeHelper.getAssociatedClosingBracket(Text, caretPosition);
            }
            else if (Text.Substring(caretPosition - 1, 1).Contains("{"))
            {
                caretPosition  -= 1;
                openBracketPos  = caretPosition;
                closeBracketPos = CodeHelper.getAssociatedClosingBracket(Text, caretPosition);
            }
            //else if the caret is near a closing bracket, the caret can be before or after the caret
            else if (Text.Substring(caretPosition, 1).Contains("}"))
            {
                openBracketPos  = CodeHelper.getAssociatedOpeningBracket(Text, caretPosition);
                closeBracketPos = caretPosition;
            }
            else if (Text.Substring(caretPosition - 1, 1).Contains("}"))
            {
                caretPosition  -= 1;
                openBracketPos  = CodeHelper.getAssociatedOpeningBracket(Text, caretPosition);
                closeBracketPos = caretPosition;
            }
            else
            {
                openBracketPos  = -1;
                closeBracketPos = -1;
            }
            InvalidateBlocks(caretPosition);
            InvalidateVisual();
        }
Esempio n. 5
0
        /// <summary>
        /// Loads top level entry list
        /// </summary>
        /// <history>
        ///     [tamttt] 20/10/2004	Created
        /// </history>
        private void BindListInfo()
        {
            string listName = SelectedText.Substring(SelectedText.IndexOf(":") + 1);
            string parent   = SelectedText.Replace(listName, "").TrimEnd(':');

            this.lblListParent.Text = parent;
            this.lblListName.Text   = listName;

            this.rowListParent.Visible = (selListInfo.Parent.Length > 0); //(parent.Length > 0)
            if (!SystemList)
            {
                this.cmdDeleteList.Visible = true;
                ClientAPI.AddButtonConfirm(cmdDeleteList, Localization.GetString("DeleteItem"));
            }
            else
            {
                this.cmdDeleteList.Visible = false;
            }
        }
Esempio n. 6
0
        private bool EnteringDuplicateChar(char ch)
        {
            bool bResult = false;

            if (base.Text.IndexOf(ch) >= 0)
            {
                if (SelectionLength > 0)
                {
                    if (SelectedText.IndexOf(ch) >= 0)
                    {
                        bResult = true;
                    }
                }
                else
                {
                    bResult = true;
                }
            }

            return(bResult);
        }
Esempio n. 7
0
        /// <summary>
        /// キープレスイベント(キーダウンイベントより後に発生する)
        /// </summary>
        /// <param name="e"></param>
        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            // BackSpaceもしくはDelete(Ctrl+BackSpace)は処理しない。
            if (e.KeyChar == 0x8 || e.KeyChar == 0x7f)
            {
                e.Handled = true;
            }

            switch ((int)e.KeyChar)
            {          // char型をint型にキャストするとASCII文字コードに変換できる
            case 0x30: // 0
            case 0x31: // 1
            case 0x32: // 2
            case 0x33: // 3
            case 0x34: // 4
            case 0x35: // 5
            case 0x36: // 6
            case 0x37: // 7
            case 0x38: // 8
            case 0x39: // 9
                       // もし、選択範囲に":"が含まれていたら、文字列は書き換えない。
                if (SelectedText.IndexOf(":", 0, SelectedText.Length) >= 0)
                {
                    e.Handled = true;
                }

                var Sindex = 0;
                var s      = Text.Split(new char[] { ':' });
                var text   = Text + ":";
                var count  = 0;
                if (SelectionStart > 7)
                {       // 全体で7桁以上の表示はありえない
                    e.Handled = true;
                }
                else
                {
                    while (text.IndexOf(":", Sindex) >= 0)
                    {
                        var Eindex = text.IndexOf(":", Sindex);
                        if (Sindex <= SelectionStart && SelectionStart <= Eindex)
                        {
                            var t = s[count];
                            if (SelectionLength == 0)
                            {
                                if (t.Length >= 2)
                                {       // 各単位で3桁以上の表示はしない
                                    e.Handled = true;
                                }
                            }
                            if (e.Handled == false)
                            {       // 入力値が各単位の上限(時:23 分、秒:59)を超えていた場合、入力を無効にする
                                var after = Text.Remove(SelectionStart, SelectionLength);
                                after = after.Insert(SelectionStart, e.KeyChar.ToString());
                                var tmp = after.Split(new char[] { ':' });
                                if (count == 0 && int.Parse(tmp[count]) > 23)
                                {
                                    e.Handled = true;
                                }

                                if (count > 0 && int.Parse(tmp[count]) > 59)
                                {
                                    e.Handled = true;
                                }
                            }
                        }
                        Sindex = Eindex + 1;
                        count++;
                    }
                }
                break;

            case 0x3:       // Ctrl + C コピーは許可する
                if (SelectionLength == 0)
                {
                    e.Handled       = true;
                    _CopyStartIndex = int.MaxValue;
                    _CopyText       = "";
                    break;
                }
                _CopyStartIndex = SelectionStart;
                _CopyText       = SelectedText;
                break;

            case 0x16:      // Ctrl + V ペーストは許可する
                var str = (string)System.Windows.Forms.Clipboard.GetDataObject().GetData(typeof(string));
                if (SelectionLength == 0 ||
                    (SelectionStart != _CopyStartIndex || SelectionLength != _CopyText.Length || _CopyText != str))
                {       // 他のアプリ(メモ帳やエクセル)からのコピーは受け付けないようにする
                    e.Handled = true;
                }
                break;

            default: e.Handled = true; break;       // それ以外
            }

            base.OnKeyPress(e);
        }