views:

49

answers:

2

Hi,

When I want to edit/view the code for a winforms control/form i created, I need to right-click in the solution and select "view code". The default action for opening the file is "view designer". This appears to be the case for any C# file containing a class that inherits from a winforms control, even if this is indirectly.

The daft thing is that VS does this if it can't run the designer (for instance when the control is not the first class in the file).

Is there hint or attribute or workaround to stop VS from doing this?

+4  A: 
  • Right-click on a file in your solution
  • Select "Open With..."
  • Select "CSharp Editor"
  • Click "Set as Default".
    (In a web application, you need to select "Web Form Editor")
Spilarix
I might eventually do that, but that affects all controls in all solutions... Ideally I want to decide per file...
jdv
IF you want to decide per file, simply you do the same steps but without "Set as Default". Just choose the editor you want and go with it. Is there a way to make "Open with..." become the default action when you double click a file? I don't think so.
Mohamed Meligy
@Mohamed Meligy: I don't consider that a solution for my question, as this choice is then not persisted at all. The other answer provides a persisted preference for each file.
jdv
@Spiralix: Thanks for a great answer. I will keep my seting like this going forward. I noticed that it is still possible to open the designer via the context menu on demand.
jdv
+6  A: 

Decrotate your Form or Control that should open in code view with [System.ComponentModel.DesignerCategory("Code")]

bitbonk
The other answer fit me slightly better but thanks anyway. This one is appliccable for files that never need to open in the designer, so I can use this to set it for all developers. Pity I can accept only one...
jdv