2 quick and easy questions about Visual Studio in C #?

It’s just that in fact, I tried searching on the Internet and searching through visual studio tools, but it seems to me that I’m out of luck, so I know that I will get a quick answer here.

I have been developing at vb.net for some time using visual studio, and have just returned to C #, and I am annoyed by some things that I'm sure just need a checkbox, ticking somewhere or disconnecting somewhere.

Firstly , when I created the event in C #, I need to record the event, and then add it to the markup code, in vb I used the ability to select the control from the upper left (when in the code behind), and then select the event from the drop-down list top right, this will automatically create an event for me and bind it to the control. I can not find the settings for this!

Secondly , when I create classes in a subfolder, the namespace for this class gets the name of the folder as a namespace. I just want it to use the default project namespace, it's just a little annoying!

eg.

MyProject has a namespace MyProject

MyProject β†’ MyFolder β†’ MyClass has a namespace MyProject.MyFolder ....

Sorry for the ugly core question.

Hello

+4
source share
2 answers

1) C # and VB handle event handler subscribers in a completely different way, so there is no direct equivalent in C #. You can do this by going to the events tab of the properties window and double-clicking on the event you want to process (in design mode). From the code view, simply enter "myControl.EventIWantToHandle + =" and then double-click the tab that will generate the event handler method for you. The best place for this is likely to be in the constructor, right under the call to InitializeComponent.

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

* This is actually Best Practice β„’ so that the folder structure matches the structure of the namespace. C # helps you do this (I'm a little surprised that VB doesn't)

+9
source
  • It is not available in C #. If you want to add an event, you can do it from the designer. First select a control, view the events of the control in the Properties dialog box, and then double-click the name of the event to create the code.

  • This is by design. Folders are internally viewed as hierarchies in your namespace.

Sorry to be upset, but believe me, there are many benefits to learning C # over VB.NET.

0
source

All Articles