Creating a partial class for a form

I would like to create a partial class for my form. I have a lot of events and this is getting messy, so I would like to partition the sections into my own files.

Problem: when I create a partial class of my form, say:

Partial Public Class Form1

End Class

Visual Studio decides I need a different form for this partial class.

Questions:
1. How to create a partial class for a form?
2. If I cannot do this, how can I split all the events in my form into different files?

+3
source share
6 answers

, . phantom, (InitializeComponent), . .NET 1.x, Partial. , . , , .

, , . , .

, , .

, . , , . MVC, . , , , . , , . , Windows Forms , . MVVM- WPF.

-, , - + UserControl. , , .

+4

, . , VS IDE , . , ( VS 2008/2010)

DesignerCategoryAttribute Class

"code".

 <System.ComponentModel.DesignerCategory("code")>
 Partial Class Form1

 End Class

, , . , , . , :

 '<System.ComponentModel.DesignerCategory("code")>

.

+1

, "Visual Studio , ", , , Form1 ?

.NET ( , ).

0

, , /.

#Region "RegionA"

#End Region

"", .

0

, , . , Visual Studio 2010 say Main Main.designer.vb, . "Partial Class Main" . . . , ? "" , , .

, Form Partial, . , Main.designer.vb, .

0

, (VS 2010), Form1, Form1.vb (Form1.Designer.vb) :

Public Class Main 'saved in Form1.vb

VS :

Partial Class Main 'saved in Form1.Designer.vb

" " :

Partial Class Main 'saved in Main.vb

, Form1.vb Main.vb VS, , , , . , , ( , Form1.vb) :

Partial Public Class Main 'in Form1.vb file
    Private Sub SomeControl_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SomeControl.Click
        Call SomeControlClick(sender, e)
    End Sub
End Class

Partial Public Class Main 'then in Main.vb file
    Private Sub SomeControlClick(ByVal sender As Object, ByVal e  As System.EventArgs)
        'blah blah
    End Sub
End Class
0

Source: https://habr.com/ru/post/1777702/


All Articles