質問
PasswordBoxのキャレットを非表示にしたり移動したりする方法はありますか?
解決
.NET 3.5 SP1 以前では、WPF TextBox/PasswordBox キャレットの色を指定するきれいな方法はありません。
ただし、(ハッキングによって) ビューからそのキャレットを指定する (この場合は削除する) 方法があります。キャレットの色は、TextBox/PasswordBox の背景色の逆色です。したがって、背景色を「透明な黒」にすることができます。これにより、システムが白いキャレット (表示されません) を使用するようになります。
コードは(単純に)次のとおりです。
<PasswordBox Background="#00000000" />
この問題の詳細については、次のリンクを参照してください。
- http://cloudstore.blogspot.com/2008/09/changing-caret-colour-in-wpf.html
- http://blogs.msdn.com/llobo/archive/2007/02/08/changing-caret-color-in-textbox.aspx
.NET 4.0 では、キャレットがカスタマイズ可能になることに注意してください。
お役に立てれば!
他のヒント
あなたはPasswordBoxでの選択を設定するには、このような何かを試すことができます:
private void SetSelection(PasswordBox passwordBox, int start, int length)
{
passwordBox.GetType()
.GetMethod("Select", BindingFlags.Instance | BindingFlags.NonPublic)
.Invoke(passwordBox, new object[] { start, length });
}
これは、カーソル位置を設定するようにその後、それを呼び出す
// set the cursor position to 2... or lenght of the password
SetSelection( passwordBox1, 2, 0);
// focus the control to update the selection
passwordBox1.Focus();
私はこのコードを使用Passwordboxの選択を取得するには:
private Selection GetSelection(PasswordBox pb)
{
Selection result = new Selection();
PropertyInfo infos = pb.GetType().GetProperty("Selection", BindingFlags.NonPublic | BindingFlags.Instance);
object selection = infos.GetValue(pb, null);
IEnumerable _textSegments = (IEnumerable)selection.GetType().BaseType.GetField("_textSegments", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(selection);
object first_textSegments = _textSegments.Cast<object>().FirstOrDefault();
object start = first_textSegments.GetType().GetProperty("Start", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(first_textSegments, null);
result.start = (int) start.GetType().GetProperty("Offset", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(start, null);
object end = first_textSegments.GetType().GetProperty("End", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(first_textSegments, null);
result.length = (int)start.GetType().GetProperty("Offset", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(end, null) - result.start;
return result;
}
struct Selection
{
public int start;
public int length;
}
、.NET 4.0で、あまりにもあなたのために働く希望をテストされます。
所属していません StackOverflow