532695 (1) [Avatar] Offline
#1
Hi,

I started reading the Windows Forms Programming in C# book first edition and in Chapter 3 the loaded image cannot change the scale when I hit the Scale to Fit Menu button.


So the main problem is the ChildClick

ChildClick method placed in the MainForm() partial class


        private void menuImage_ChildClick(object sender, EventArgs e)
        {
            if (sender is MenuItem)
            {
                MenuItem mi = (MenuItem)sender;

                _selectedImageMode = mi.Index;
                pictureBox1.SizeMode = modeMenuArray[mi.Index];

                pictureBox1.Invalidate();
            }
        }


Variables Placed before private void InitializeComponent()


///<summary> Mode settings for the View->Image submenu. 
        ///The order here must correspond to the order of menus 
        ///in the submenu.</summary>
        private PictureBoxSizeMode[] modeMenuArray = {
                    PictureBoxSizeMode.StretchImage,
                    PictureBoxSizeMode.Normal };
        //This variable will hold the currently selected display mode for the image.
        private int _selectedImageMode = 0;


Could you tell me what is the issue. I use Visual Studio 2015 Community;

I also noticed that VS 2015 does not apply
menuView.Index = 1;
as well.


I downloaded the source code of Windos Forms in Action however has been coded completely different way.

Another thing when I opened the MyPhoto 4.2, in the MainForm [Design] window the sub-menu items under Image main menu are hidden. ChildClick method is also missing.