VB.NET中实现函数一键显示/隐藏及分组功能的技术求助
Hey there! I’ve got a couple of straightforward solutions to help you quickly collapse or expand all your VB.NET functions, or group them for targeted show/hide actions. Let’s dive in:
1. Use Visual Studio’s Built-In Outlining (No Extra Tools Needed)
Visual Studio has native support for code outlining, which works perfectly for your functions.
Collapse/Expand All Functions at Once
Use these keyboard shortcuts to handle all functions in your file:
- Collapse everything: Press
Ctrl+Mfollowed byCtrl+O - Expand everything: Press
Ctrl+Mfollowed byCtrl+X
You can also do this via the menu: Right-click anywhere in the code editor → select Outlining → choose Collapse All or Expand All.
Group Functions for Targeted Show/Hide
If you want to group related functions (like all your SQL stored procedure name functions), wrap them in #Region blocks. This lets you collapse/expand entire groups with one click.
Here’s how to modify your code with regions:
#Region "SQL Stored Procedure Name Functions" Private Function sqlConfirmTopup(ByVal appType As String) As String Dim result As String = "ERR" Try Select Case appType.ToUpper.Trim Case "ONLINE" result = "STP_CONFIRM_TOPUP" Case "TEST" result = "STP_CONFIRM_TOPUP_TEST" Case Else result = "STP_CONFIRM_TOPUP_TEST" End Select Catch ex As Exception result = "STP_CONFIRM_TOPUP_TEST" End Try Return result End Function Private Function sqlInsertSendSMS(ByVal appType As String) As String Dim result As String = "ERR" Try Select Case appType.ToUpper.Trim Case "ONLINE" result = "STP_INSERT_SEND_SMS" Case "TEST" result = "STP_INSERT_SEND_SMS_TEST" Case Else result = "STP_INSERT_SEND_SMS_TEST" End Select Catch ex As Exception result = "STP_INSERT_SEND_SMS_TEST" End Try Return result End Function Private Function sqlConfirmSendSMS(ByVal appType As String) As String Dim result As String = "ERR" Try Select Case appType.ToUpper.Trim Case "ONLINE" result = "STP_CONFIRM_SEND_SMS" Case "TEST" result = "STP_CONFIRM_SEND_SMS_TEST" Case Else result = "STP_CONFIRM_SEND_SMS_TEST" End Select Catch ex As Exception result = "STP_CONFIRM_SEND_SMS_TEST" End Try Return result End Function #End Region
Once you add the region, you’ll see a small +/- icon next to the #Region line—click it to collapse or expand the entire group. You can also use the same Ctrl+M shortcuts to handle all regions at once.
2. Tweak Outlining Settings (Optional)
If you want to customize how outlining behaves, go to:Tools → Options → Text Editor → Basic → Advanced
Look for the Outlining section—here you can enable/disable automatic outlining, choose to collapse regions by default when opening a file, and more.
3. Use Visual Studio Extensions (For Extra Power)
If you want more advanced control (like custom grouping rules or one-click buttons), check out productivity extensions in the Visual Studio Marketplace. Extensions like Productivity Power Tools add enhanced outlining features, but the built-in tools should cover your basic needs perfectly.
内容的提问来源于stack exchange,提问作者Boualy Thippavong

