Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2 simple and quick C# specific Visual Studio questions?

Just a quick one really, I've tried googling and searching through the visual studio tools but I seem to be having no luck, so I know I'll get a quick answer on here!

I've been developing in vb.net for a while using visual studio and just moved back to c# and I'm irritated by a few things that I'm sure just need a check box ticking or unticking somewhere.

Firstly, when I created an event in C# I have to write out the event and then add it to the markup code, in vb I used to be able to select the control from the top left drop down (when in code behind) and then select the event from the top right dropdown, this would automatically create the event for me and attach it to the control. I can't find the setting for this to be turned on!

Secondly, when I create classes in a sub folder, the namespace for that class is given the folder name as a sub namespace. I just want it to use the namespace of the project by default, it's just getting a bit annoying!

E.G.

MyProject has MyProject namespace

MyProject --> MyFolder --> MyClass has the name space MyProject.MyFolder ....

Sorry for the outrageously basic question.

Regards

like image 950
Lloyd Powell Avatar asked Jan 19 '23 12:01

Lloyd Powell


1 Answers

1) C# and VB handle event handler subscriptions quite differently so there is no direct equivilent of this in C#. You can do this by switching to the events tab of the properties window, and double clicking on the event you want to handle (in design view). From code view, simply type "myControl.EventIWantToHandle +=" and then double hit tab, which will generate the event handler method for you. The best place to do this is most likely in the constructor, right below the InitializeComponent call.

2) Highlight the folder in solution explorer, and in the properties window set the 'NamespaceProvider' property to false*

*It's actually a Best Practice™ for the folder stucture to match the namespace stucture - C# is helping you out by doing this (I'm a little surprised that VB doesn't)

like image 157
MattDavey Avatar answered Jan 30 '23 20:01

MattDavey