L
L
libera2015-12-11 16:57:19
C++ / C#
libera, 2015-12-11 16:57:19

C# calling private?

Tell me how to call private in the button.

private void pole_zapol(object sender, EventArgs e)

need to call, tell me how.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
ar4ebaldello, 2015-12-11
@ar4ebaldello

If you do not use arguments in the pole_zapol method, then in another non-static method of the form class, you can write pole_zapol(null, null);

M
MonkAlex, 2015-12-11
@MonkAlex

call private in the button.
What does it mean? Should the method be triggered when the button is clicked? Look for the button's Clicked event and attach a method to it.
Call without a button? Either like any other method, or reflection.

D
Daniil Demidko, 2015-12-12
@Daniro_San

For starters, you should not call the event handler a transliteration.
Secondly, if you are using WPF, then the private handler is simply specified in the XAML markup or when creating the button in a class method.
For example:

class Example : Window
{
    // Обработчик события
    private void ExampleButtonClick ( Object sender, RoutedEventArgs e )
    {
        //код
    }
    
    // Конструктор
    public Example()
    {
      // Создаем кнопку
         Button exampleButton = new Button();

      // Привязываем к ней приватный обработчик
         exampleButton.Click += ExampleButtonClick;
    }
}

With WinForms, the situation is about the same.
Another thing is if you want to bind a private instance method to an event of another class - this is not allowed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question