位置、キャレットにMaskedTextbox
-
02-07-2019 - |
質問
いきオーバーライドのデフォルトの行動位置決めのためのキャレット仮面テキストボックス.
デフォルトでは、キャレットのマウスをクリック仮面のテキストボックスがすでに含まれている文字によるマスクです。
知っていることは非表示にすることができ、キャレットとしてこの ポスト, あるので、とても気に入った位置決めのためのキャレットの初めにテキストボックスにはコントロールを返します。
解決
こん:
private void maskedTextBox1_Enter(object sender, EventArgs e)
{
this.BeginInvoke((MethodInvoker)delegate()
{
maskedTextBox1.Select(0, 0);
});
}
他のヒント
の向上にアッバスの溶液に、してみてください:
private void ueTxtAny_Enter(object sender, EventArgs e)
{
//This method will prevent the cursor from being positioned in the middle
//of a textbox when the user clicks in it.
MaskedTextBox textBox = sender as MaskedTextBox;
if (textBox != null)
{
this.BeginInvoke((MethodInvoker)delegate()
{
int pos = textBox.SelectionStart;
if (pos > textBox.Text.Length)
pos = textBox.Text.Length;
textBox.Select(pos, 0);
});
}
}
このイベントハンドラで再配布することができます。複数の箱ではないか、ユーザーの能力の位置にカーソルに入力したデータにおいてeはなく、カーソルがzeroeth時に位置ボックスが空でない).
これと類似の標準テキストボックスに入力します。みねremaining(とき)はその後の入力イベントでは、ユーザーにものを選定することができ残りの(空)マスクの迅速な場合xeの創うやくこれで終了となりました。
これは大きな改善は、デフォルトの挙動のMaskedTextBoxes.よろしく!
また数に変更Ishmaeelの優れた。私は身BeginInvoke場合にのみのカーソルのニーズを動かすことができます。またメソッドを呼び出しから様々なイベントハンドラの入力パラメータの活MaskedTextBox.
private void maskedTextBoxGPS_Click( object sender, EventArgs e )
{
PositionCursorInMaskedTextBox( maskedTextBoxGPS );
}
private void PositionCursorInMaskedTextBox( MaskedTextBox mtb )
{
if (mtb == null) return;
int pos = mtb.SelectionStart;
if (pos > mtb.Text.Length)
this.BeginInvoke( (MethodInvoker)delegate() { mtb.Select( mtb.Text.Length, 0 ); });
}
一部の答え:きの位置、キャレットを配長さ0の選択の制御にMouseClickイベント、例えば:
MaskedTextBox1.Select(5, 0)
についてコンセンサスセットのキャレット5文字の位置にテキストボックス.
その理由をこの答えは部分的であることができるから考えないといけないのは確実な方法を決定する位置、キャレット すべ 位置付け、クリックします。これで一部のマスクが、共通の場合(例えばの電話番号マスクでないと思っている、方法などについては別のマスクと迅速な文字から実際のユーザーの入---
//not the prettiest, but it gets to the first non-masked area when a user mounse-clicks into the control
private void txtAccount_MouseUp(object sender, MouseEventArgs e)
{
if (txtAccount.SelectionStart > txtAccount.Text.Length)
txtAccount.Select(txtAccount.Text.Length, 0);
}
このソリューション作品だった。ぜひ試してみてください下さい。
private void maskedTextBox1_Click(object sender, EventArgs e)
{
maskedTextBox1.Select(maskedTextBox1.Text.Length, 0);
}
私鉱作業をクリックイベント....無呼び出しが必要となります。
private void maskedTextBox1_Click(object sender, EventArgs e)
{
maskedTextBox1.Select(0, 0);
}
このソリューションをクリック法のMaskedTextBoxのようにGman Cornflake用しかし、見つかりませるのに必要な、ユーザがクリックすのMaskedTextBox度で含まれるデータおよびカーソルを同じ場所に設置します。
以下の例では、オフ促し、リテラルでの評価までの長さのデータMaskedTextBoxが0に等しいのカーソルの位置それ以外の場合でfpgaのコードにカーソルの位置にします。
このコードが書かれVB.NET 2017年度までとする。武器agiは、dexで下がらないboxerぐ!
Private Sub MaskedTextBox1_Click(sender As Object, e As EventArgs) Handles MaskedTextBox1.Click
Me.MaskedTextBox1.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals
If Me.MaskedTextBox1.Text.Length = 0 Then
MaskedTextBox1.Select(0, 0)
End If
Me.MaskedTextBox1.TextMaskFormat = MaskFormat.IncludePromptAndLiterals
End Sub