문제

암호 상자의 간병을 숨기거나 움직일 수있는 방법이 있습니까?

도움이 되었습니까?

해결책

.NET 3.5 SP1 또는 이전에는 WPF TextBox/PasswordBox Caret의 색상을 지정할 수있는 깨끗한 방법이 없습니다.

그러나 (해킹을 통해)보기에서 돌보는 것을 지정 (또는이 경우 제거)하는 방법이 있습니다. 캐럿 색상은 TextBox/PasswordBox의 배경색의 역 색상입니다. 따라서, 배경색 "투명한 검은 색"을 만들 수 있으며, 이는 시스템을 흰색 간병으로 사용하는 데 속을 수 있습니다 (보이지 않음).

코드는 다음과 같습니다.

<PasswordBox Background="#00000000" />

이 문제에 대한 자세한 내용은 다음 링크를 확인하십시오.

.NET 4.0에서 간병은 사용자 정의 할 수 있습니다.

도움이 되었기를 바랍니다!

다른 팁

암호 상자에서 선택을 설정하려면 이와 같은 것을 시도 할 수 있습니다.

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(); 

암호 상자를 선택하려면이 코드를 사용합니다.

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에서 테스트 한 바에 따르면, 당신에게도 효과가 있기를 바랍니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top