using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; public partial class FullKeyboardForm : Form { public string Caption { set => lblCaption.Text = value; } public bool ValueChanged { get; set; } public string Value { get; set; } public char PasswordChar { set => txtPreview.PasswordChar = txtInput.PasswordChar = value; } public FullKeyboardForm() { InitializeComponent(); } public FullKeyboardForm(string currentString):this() { txtPreview.Text = currentString; Value=currentString; } private void FullKeyboardForm_Load(object sender, EventArgs e) { doubleCharButtons = Controls .Cast() .Where(c => c.Name.Contains("DoubleChar")) .Select(c => (Button)c) .ToList(); } private void FullKeyboardForm_Shown(object sender, EventArgs e) { txtInput.Focus(); txtInput.SelectAll(); } public bool IsPassword { set { if (value) txtInput.PasswordChar = '*'; } } bool isCaps = false; bool isShift = false; bool isCtrl = false; bool isAlt = false; private void btnCharKey_Click(object sender, EventArgs e) { if (sender is Button button) { string stringToAdd; if (!isCaps) { stringToAdd = button.Text.ToLower().Replace("&&", "&"); } else { stringToAdd = button.Text.ToUpper().Replace("&&", "&"); } InsertOneChar(stringToAdd); } } int selectionStartSaved = 0; void InsertOneChar(string s) { if (selectionStartSaved != txtInput.SelectionStart) selectionStartSaved = txtInput.SelectionStart; if (txtInput.SelectionLength > 0) { txtInput.Text = txtInput.Text.Remove(selectionStartSaved, txtInput.SelectionLength); } txtInput.Text = txtInput.Text.Insert(selectionStartSaved, s); selectionStartSaved = selectionStartSaved + s.Length; txtInput.Focus(); txtInput.SelectionStart = selectionStartSaved; txtInput.SelectionLength = 0; } private void btnShift_Click(object sender, EventArgs e) { isShift = !isShift; foreach (var item in doubleCharButtons) { if (isShift) { btnShift1.Text = btnShift2.Text = "Shift"; item.Text = item.Tag.ToString().Split(' ')[0]; } else { btnShift1.Text = btnShift2.Text = "shift"; item.Text = item.Tag.ToString().Split(' ')[1]; } } } List