4

I am making an application using visual studio and I am making an Excel Addon.
I would like to add a username and password field so I am using Editbox to do this however there doesnt seem to be a passwordChar field.

What could I use instead or how can I hide the text?

I am currently trying to convert the chars to * but its very slow.
Im also working in C#

This is my current solution:

private void ebxPassword_KeyUp(object sender, RibbonControlEventArgs e)
{
    char last = ebxPassword.Text[ebxPassword.Text.Length - 1];
    passwordText += last;
    ebxPassword.Text = ebxPassword.Text.Replace(last.ToString(), "*");
}

My Final Solution:

It cannot be done, there is no simple way around it.
So instead of having these controls in the ribbon, I added a login button and when clicked loads a form with a standard text box and this works perfectly fine.

csharpwinphonexaml
  • 3,659
  • 10
  • 32
  • 63
brian4342
  • 1,265
  • 8
  • 33
  • 69

1 Answers1

3

Sorry for Late answer..Answered for whom check this question to hope to find a solution in future..

With this extension method which i use in my projects when needed..No matter where it called..just string is enough ;) here the solution :

public static string Mask_IT(this string source, char MaskingChar, int AllowedCharCount)
  {
     var cArr = source.ToCharArray();

     if(source.Length - AllowedCharCount >=0)
     {

         for (int i = 0; i < ( cArr.Length - AllowedCharCount; i++ )
         {
          if (cArr[i] != MaskingChar) cArr[i] = MaskingChar;
         }
     }

         return cArr.ToString();
  }

Usage Example :

private void yourTextBasedComponent_TextChanged (object sender, EventArgs e)
{
   return YourTextBasedComponent.Text.Mask_IT('*', 2);
}

Note - 1 : Always Use TextChanged Event..With using Text_Changed event ( or similar event which implemented with your component) you can block unwanted results..as an example if someone try to copy-paste an unwanted string, then your Key-Up or KeyDown events won't work because of their listening characteristics..but Text_Changed always work when the text is changed;)

Note - 2 : In Method There is a parameter named "AllowedCharCount"..This is for "Leave the last (n) chars as not masked"

sihirbazzz
  • 708
  • 4
  • 20