Question Put New Code Block at Cursor

jcardana

Old to VB6, New to VB.NET
Joined
Oct 26, 2015
Messages
72
Location
Rio Rancho, NM
Programming Experience
Beginner
I have my code broken down into Regions... Form Events, Form Controls(Menus, Buttons, FileLists) and Routines and Functions.

When I click on a control or use the pulldown menus, the new code block is placed either in the middle of my Functions block or at the end of the entire file.

Isn't there a way to tell VS2022 to add the code block where the cursor is?

Thanks for your time,
Joe
 
I have my code broken down into Regions... Form Events, Form Controls(Menus, Buttons, FileLists) and Routines and Functions.

When I click on a control or use the pulldown menus, the new code block is placed either in the middle of my Functions block or at the end of the entire file.

Isn't there a way to tell VS2022 to add the code block where the cursor is?

Thanks for your time, geometry dash

Here are a few things you can try in Visual Studio 2022 to control where new code blocks are inserted when working with code that is organized into regions:

  • Right click in the editor window and uncheck "Collapse to Definitions" under Outlining. This will disable automatic collapsing of your regions and may help with placing code correctly.
  • Structure your regions using #region and #endregion directives rather than relying on editor outlining. Then new blocks should be inserted where your cursor is within those directives.
  • Install the Visual Studio Marketplace extension called "RegionFolder" - this allows you to create folder-like structures for your regions that can help organize where new code blocks go.
  • When double clicking on an event handler or other auto-generated code, immediately cut and paste it where desired before typing anything. This tricks VS into putting it where you want.
  • Right click the auto-generated code block and select "Move Definition Near Current Location" to have VS insert it where your cursor is.
  • Upgrade to Visual Studio 2022 version 17.1 or later, as some improvements were made to handling regions and code block insertion.
With some tweaking of your region setup and utilization of extensions, you should be able to get Visual Studio to add new code blocks right where you want them when working on event handlers and other logic.
 
Back
Top