新しいセクションを追加しながら、大きな(レガシー)フォームを部分クラスに分割した後、今日この問題が発生しました。これは古い質問ですが、元の質問に対する回答の多くが間違っているため、投稿しています。具体的には、それらの多くは、VisualStudioがダブルクリックせずにこれらを生成できる方法はないと主張しています。VSが特定の状況でこれを行うことを確認したいと思います。
私の特定の状況では、タブコントロールに新しいタブを追加し、新しいタブのイベントとコードを新しいクラスに配置しました。もともと、私はこのコード(イベントを含む)をメインフォームの最後に配置していましたが、これは問題に関係している可能性があります。コードを移動した後、メインフォームの任意の部分(たとえば、別のタブ)にコントロールを追加すると、完全なイベントハンドラーがあるにもかかわらず、VSは新しい部分クラスにある3つのイベントに対して空のイベントハンドラーを生成しますクラス。
今のところ私が持っている唯一の解決策は、問題が発生したときにメインフォームコードの下部から空のハンドラーを削除することです。ソリューションのクリーニングでは、これらの空白のハンドラーは削除されません。
3つすべてが毎回一貫して生成され、テストコントロールを追加するとメインフォームの後ろに隠れているタブ上にあるため(ダブルクリックの可能性はなく、3つすべてをダブルクリックする可能性はありません)、次のように言うことができますこれがVisualStudioのバグであるという確信(私の場合はVS 2013)。
更新24/9/15:ハンドラーの削除にうんざりした後、さらに検索を行い、問題の解決策を見つけました。MSフォーラム( https://social.msdn.microsoft.com/Forums/windows/en-US/79910eaa-84e7-472d-95ee-4b8ddfbf99f0/multiple-partial-class-files-cause)からのmustiyのソリューションのテキストは次のとおりです。 -problems-with-forms-designer?forum = winforms&prof = required)。この修正は私にとってはうまくいきますが、クリック作成イベントはまだ間違ったクラスでそれらを作成しますが、それらを移動した後、それらは正しく機能します。また、無効なイベントハンドラーが作成されるのを防ぎます。
i had same problem and came accross your post, but i wasn't sattisfied. It had to be a solution for this because VS IDE does it.
Here is the solution :
Open the .csproj project file with notepad and let's say for a Form1.cs file you will see a configuration like
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
If you create a new file called Form1Events.cs and put another partial class of Form1 and move the events to the new partial class. In the new .csproj file you the new file like this below
<Compile Include="Form1Events.cs">
<SubType>Form</SubType>
</Compile>
Something is missing you have to tell the VS IDE that this Form1Events.cs file is dependent to Form1.cs. As the IDE do this for Form1.Designer.cs file make the same with Form1Events.cs and put a "DependentUpon" tag into Form1Events.cs. Last the .csproj file look like this below
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Form1Events.cs">
<DependentUpon>Form1.cs</DependentUpon>
<SubType>Form</SubType>
</Compile>
And if you save the .csproj file the IDE reloads the project and on the Solution exlorer tree you see that the new partial class is put below Form1.cs file. And if you open the designer and double click a previous decalred and moved event it will navigate to the new file.