How do I (elegantly) transpose textbox over label at specific part of string?

前端 未结 10 405
谎友^
谎友^ 2020-12-16 11:54

I\'ll be feeding a number of strings into labels on a Windows Form (I don\'t use these a lot). The strings will be similar to the following:

\"The qui

10条回答
  •  时光说笑
    2020-12-16 12:20

    One option is to use a Masked Textbox.

    In your example, you would set the mask to:

    "The quick brown fox jLLLed over the l\azy hound"
    

    Which would appear as:

    "The quick brown fox j___ed over the lazy hound"
    

    And only allow 3 characters (a-z & A-Z) to be entered into the gap. And the mask could be easily changed via code.

    EDIT: For convenience...

    Here is a list and description of masking characters

    (taken from http://www.c-sharpcorner.com/uploadfile/mahesh/maskedtextbox-in-C-Sharp/).

    0 - Digit, required. Value between 0 and 9.
    9 - Digit or space, optional.
    # - Digit or space, optional. If this position is blank in the mask, it will be rendered as a space in the Text property.
    L - Letter, required. Restricts input to the ASCII letters a-z and A-Z.
    ? - Letter, optional. Restricts input to the ASCII letters a-z and A-Z.
    & - Character, required.
    C - Character, optional. Any non-control character.
    A - Alphanumeric, required.
    a - Alphanumeric, optional.
    .  - Decimal placeholder.
    , - Thousands placeholder.
    : - Time separator.
    / - Date separator.
    $ - Currency symbol.
    < - Shift down. Converts all characters that follow to lowercase.
    > - Shift up. Converts all characters that follow to uppercase.
    | - Disable a previous shift up or shift down.
    \ - Escape. Escapes a mask character, turning it into a literal. "\\" is the escape sequence for a backslash.
    

    All other characters - Literals. All non-mask elements will appear as themselves within MaskedTextBox. Literals always occupy a static position in the mask at run time, and cannot be moved or deleted by the user.

提交回复
热议问题