Window shapes form code

Well, this is my first application for Windows forms, and I have to face some difficulties restructuring my code. started putting everything in a class Form1that was provided by default, it quickly became too big. I know that this is a pretty bad programming practice, so I started cleaning and made different classes to satisfy the principle of single responsibility. however, since some button-related and network-related events work well in the classroom Form1, fetching them from the outside causes them to fail, and I don't know how this should be done.

public partial class Form1
{


    public Form1()
    {
        InitializeComponent();

    }

    private void method1(object sender, EventArgs e)
    {
            //CODE
    }



    private void method2(object sender, DataGridViewCellEventArgs e)
    {
           //CODE
    }



    private void method3(object sender, EventArgs e)
    {
          //CODE
    }

}

method1, method2, method3 .. ( ), , , . , private , , Form1. , , onClick: Newclass.method1(), . , , Form1 onClick: thisMethodCallsTheOneINeedInADifferentClass(), ... , , , . , .

+4
2

, . , . - :

YourClass class1 = new YourClass(); 

, .

private static YourClass class1 = new YourClass();

:

class1.YourMethod();
+3

. , , .

, - :

button1.Click += new System.EventHandler(method1);

, , - , . , .

, Form1.cs, .

0

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


All Articles