예제 #1
0
    private void inBox_KeyDown(object sender, KeyEventArgs e)
    {
        getIndex();
        if (intype == 0)   //normal mode
        {
            if (multiline) //single mode
            {
                if ((e.KeyCode == Keys.Enter) || ((e.Control) && (e.KeyCode == Keys.R)))
                {
                    e.Handled = true;
                }
                if (((e.Control) && (e.KeyCode == Keys.V)) || ((e.Shift) && (e.KeyCode == Keys.Insert)))
                {
                    e.Handled = true;
                    string      clipstr = "";
                    IDataObject data    = Clipboard.GetDataObject();
                    if (data.GetDataPresent(typeof(string)))
                    {
                        clipstr = (string)data.GetData(typeof(string));
                    }
                    if (clipstr != "")
                    {
                        clipstr = clipstr.Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "");
                        if (rang != 0)
                        {
                            _inBox.Text = _inBox.Text.Remove(selx, rang);
                        }
                        _inBox.Text           = _inBox.Text.Insert(selx, clipstr);
                        _inBox.SelectionStart = selx + clipstr.Length;
                    }
                }
            }
        }

        if (intype == 1)                                                                                                                                                    //pasword mode
        {
            if ((e.KeyCode == Keys.Enter) || ((e.Control) && (e.KeyCode == Keys.V)) || ((e.Shift) && (e.KeyCode == Keys.Insert)) || ((e.Control) && (e.KeyCode == Keys.X))) //disable key
            {
                e.Handled = true;
            }
            if (e.KeyCode == Keys.Delete)
            {
                if ((selx != 0) || (rang != 0))
                {
                    if (rang == 0)
                    {
                        pasword = pasword.Remove(selx, 1);
                    }
                    else
                    {
                        pasword = pasword.Remove(selx, rang);
                    }

                    getPasword = UiControlsMethod.GetMd5Str32(pasword);
                }
            }
        }
    }
예제 #2
0
    private void inBox_KeyPress(object sender, KeyPressEventArgs e)
    {
        e.Handled = true;
        if (e.KeyChar == Convert.ToChar(Keys.Back))
        {
            if ((selx != 0) || (rang != 0))
            {
                if (rang == 0)
                {
                    pasword = pasword.Remove(selx - 1, 1);
                }
                else
                {
                    pasword = pasword.Remove(selx, rang);
                }

                getPasword = UiControlsMethod.GetMd5Str32(pasword);
            }
        }
        else
        {
            if (
                (e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z') ||
                (e.KeyChar == '!') || (e.KeyChar == '@') || (e.KeyChar == '#') || (e.KeyChar == '$') || (e.KeyChar == '%') || (e.KeyChar == '^') || (e.KeyChar == '&') || (e.KeyChar == '(') || (e.KeyChar == ')') ||
                (e.KeyChar == '_') || (e.KeyChar == '+') || (e.KeyChar == '-') || (e.KeyChar == '=') || (e.KeyChar == '[') || (e.KeyChar == ']') || (e.KeyChar == '{') || (e.KeyChar == '}') ||
                (e.KeyChar == '`') || (e.KeyChar == '~') || (e.KeyChar == '|') || (e.KeyChar == '\\') || (e.KeyChar == ';') || (e.KeyChar == ':') || (e.KeyChar == '"') || (e.KeyChar == '\'') ||
                (e.KeyChar == ',') || (e.KeyChar == '<') || (e.KeyChar == '.') || (e.KeyChar == '>') || (e.KeyChar == '/') || (e.KeyChar == '?')
                )
            {
                if (rang != 0)
                {
                    pasword = pasword.Remove(selx, rang);
                    pasword = pasword.Insert(selx, e.KeyChar.ToString());
                }
                else
                {
                    pasword = pasword.Insert(selx, e.KeyChar.ToString());
                }

                getPasword = UiControlsMethod.GetMd5Str32(pasword);

                string code = "";
                for (int i = 0; i < pasword.Length; i++)
                {
                    code += paswordmask;
                }
                _inBox.Text           = code;
                _inBox.SelectionStart = selx + 1;
            }
        }
    }