다음을 통해 공유


How to: Customize How Visual Studio Creates Captions for Data-bound Controls

A special consideration comes into play when you drag items from the Data Sources Window onto the Windows Forms Designer: the column names in the caption labels are reformatted into a more readable string when two or more words are found to be concatenated together. You can customize the way in which these labels are created by setting the SmartCaptionExpression, SmartCaptionReplacement, and SmartCaptionSuffix values in the HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Data Designers registry key.

Note

This registry key does not exist until you create it.

Smart captioning is controlled by the regular expression entered into the value of the SmartCaptionExpression value. Adding the Data Designers registry key overrides the default regular expression that controls caption labels. For more information about regular expressions, see Using Regular Expressions in Visual Studio.

The following table describes the registry values that control caption labels.

Registry item

Description

SmartCaptionExpression

The regular expression used to match your patterns.

SmartCaptionReplacement

The format to display any groups matched in the SmartCaptionExpression.

SmartCaptionSuffix

An optional string to append to the end of the caption.

The following tables lists the internal default settings for these registry values.

Item

Default Value

Explanation

SmartCaptionExpression

(\\p{Ll})(\\p{Lu})|_+

Matches a lowercase character followed by an uppercase character or an underscore.

SmartCaptionReplacement

$1 $2

$1 represents any characters matched in the first parentheses of the expression, and the $2 represents any characters matched in the second parentheses. The replacement is the first match, a space, and then the second match.

SmartCaptionSuffix

:

Represents a character appended to the returned string. For example, if the caption is Company Name, the suffix makes it Company Name:

Warning

You should be very careful when doing anything in the Registry Editor. Back up the registry before editing it. If you use Registry Editor incorrectly, you can cause serious problems that may require you to reinstall your operating system. Microsoft does not guarantee that problems that you cause by using Registry Editor incorrectly can be resolved. Use Registry Editor at your own risk.

The following KnowledgeBase article contains instructions for backing up, editing, and restoring the registry: Description of the Microsoft Windows registry (https://support.microsoft.com/default.aspx?scid=kb;en-us;256986)

To modify the smart captioning behavior of the Data Sources window

  1. Open a command window by clicking Start and then Run.

  2. Type regedit in the Run dialog box, and click OK.

  3. Expand the HKEY_CURRENT_USER node.

  4. Expand the Software node.

  5. Expand the Microsoft node.

  6. Expand the VisualStudio node.

  7. Right-click the 10.0 node and create a new Key named Data Designers.

  8. Right-click the Data Designers node and create a new String Value named SmartCaptionExpression.

  9. Right-click the Data Designers node and create a new String Value named SmartCaptionReplacement.

  10. Right-click the Data Designers node and create a new String Value named SmartCaptionSuffix.

  11. Right-click the SmartCaptionExpression item and choose Modify.

  12. Enter the regular expression you want the Data Sources window to use.

  13. Right-click the SmartCaptionReplacement item and choose Modify.

  14. Enter the replacement string formatted the way you want to display the patterns matched in your regular expression.

  15. Right-click the SmartCaptionSuffix item and choose Modify.

  16. Enter any characters you want to appear at the end of the caption.

    The next time you drag items from the Data Sources window, the caption labels are created using the new registry values provided.

To turn off the Smart Captioning feature

  1. Open a command window by clicking Start and then Run.

  2. Type regedit in the Run dialog box, and click OK.

  3. Expand the HKEY_CURRENT_USER node.

  4. Expand the Software node.

  5. Expand the Microsoft node.

  6. Expand the VisualStudio node.

  7. Right-click the 10.0 node and create a new Key named Data Designers.

  8. Right-click the Data Designers node and create a new String Value named SmartCaptionExpression.

  9. Right-click the Data Designers node and create a new String Value named SmartCaptionReplacement.

  10. Right-click the Data Designers node and create a new String Value named SmartCaptionSuffix.

  11. Right-click the SmartCaptionExpression item and choose Modify.

  12. Enter (.*) for the value. This will match the entire string.

  13. Right-click the SmartCaptionReplacement item and choose Modify.

  14. Enter $1 for the value. This replaces the string with the matched value, which is the entire string so that it will remain unchanged.

    The next time you drag items from the Data Sources window, the caption labels are created with unmodified captions.

See Also

Concepts

Binding Windows Forms Controls to Data in Visual Studio

Preparing Your Application to Receive Data

Fetching Data into Your Application

Binding Controls to Data in Visual Studio

Editing Data in Your Application

Validating Data

Saving Data

Other Resources

.NET Framework Regular Expressions