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

前端 未结 10 440
谎友^
谎友^ 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:23

    This may be overkill depending on how complex you want this to be, but a winforms web browser control (which is essentially MSIE running inside your Winforms app) can work as an editor where you control which parts are editable.

    Load your content with the editable parts tagged as such, e.g.:

    
    
    
    
    
    
    
    The quick brown fox j___ed over the l__y hound

    Another option, a bit more work to code but more lightweight in terms of memory/resources, would be to use a FlowLayoutPanel, add normal panels to the FlowLayoutPanel, and then put either labels or textboxes on those panels depending on if a panel represent a fixed or editable portion, and resize them to match the length of the content. You can use MeasureString to find out the width of the content in each label/textbox for resizing purposes.

提交回复
热议问题