E
E
Evgeny Ivanov2021-07-20 10:06:53
C++ / C#
Evgeny Ivanov, 2021-07-20 10:06:53

How to supplement the code of one method with code from another?

There is a class with two methods.
Class: WindowActions - actions on a window.
Methods:
SetWindowSizeToContent - set window size by content.
SetWindowCenterAndSizeToContent - set window size to center and content.
(that is, this method is an exact copy of the method above + 1 line of new code)

You need to supplement the code of the second method with the code from the first. Of course, without copying, i.e. how to "inherit" a method (like a class). (Clearly, there is no method inheritance.)

public static class WindowActions
    {
        public static void SetWindowSizeToContent(Window window)
        {
            // Manually alter window height and width
            window.SizeToContent = SizeToContent.Manual;

            // Automatically resize width relative to content
            window.SizeToContent = SizeToContent.Width;

            // Automatically resize height relative to content
            window.SizeToContent = SizeToContent.Height;

            // Automatically resize height and width relative to content
            window.SizeToContent = SizeToContent.WidthAndHeight;
        }

        public static void SetWindowCenterAndSizeToContent(Window window) //:SetWindowSizeToContent;
        {
        // Добавить сюда код из метода выше
            window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
        }

    }


How to supplement the code of one method with code from another?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2021-07-20
@logpol32

Call it from the second method

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question