A cleaner way to automatically call one method after another?

前端 未结 7 1365
北荒
北荒 2021-01-18 02:28

Is it possible to design a method in such a fashion, that it knows it must automatically call a next method in succession upon exiting?

In the following example, I m

7条回答
  •  悲哀的现实
    2021-01-18 03:02

    You could encapsulate the changes which would cause the form to refresh into form-level properties.

    For instance,

    private bool _showPriorityLine;
    private bool ShowPriorityLine
    {
        get { return _showPriorityLine; }
        set
        {
            _showPriorityLine = value;
            Refresh();
        }
    }
    

    Then your event would just be

    private void PriorityLine_Click(object sender, EventArgs e)
    {
        ShowPriorityLine = !ShowPriorityLine;
    }
    

    Of course, that only cleans up your code if you have several events manipulating the same variables that cause the form to need refreshing.

提交回复
热议问题