Here I showed how to format code using shortcuts in Visual Studio 2022. But especially I can forget hotkey and I prefer to have a ‘Format Selection’ in the context menu. Check these steps to add the ‘Format Selection’ option to your context menu:
Step 1 – Menu Tools -> Customize
Step 2 – Commands Tab -> Context Menu -> Editor Context Menu -> Code Window -> Add Command
Step 3 – Edit -> Selection Format
Format Selection in Context Menu
Hope it was useful. Enjoy!