Пример #1
0
        /// <summary>
        /// Txt_HeightPix_TextChanged()
        /// This method will update the percentage and pixel text boxes if they are valid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Txt_HeightPix_TextChanged(object sender, EventArgs e)
        {
            //before processing make sure the text box is not empty
            if (txt_HeightPix.Text.Length <= 0)
            {
                return;
            }
            //please note that Util_UI.ParseOnlyInt will always return an int
            string s_NewText = Util_UI.ParseOnlyInt(txt_HeightPix);
            int    i_NewPix  = int.Parse(s_NewText); //parse out the pixel to an int

            if (i_NewPix <= 0)
            {
                //then you cannot adjust the percentage, the user should be stopped and a ding should be played
                using (SoundPlayer sp_Bonk = new SoundPlayer("./audio/Windows Ding.wav"))
                {
                    sp_Bonk.Play();
                }
                return;
            }
            int i_NewPerc = (int)Math.Round((double)i_NewPix / (double)i_HeightOrig * 100);     //calculate the new percentage

            txt_HeightPerc.TextChanged -= Txt_HeightPerc_TextChanged;
            txt_HeightPix.TextChanged  -= Txt_HeightPix_TextChanged;
            txt_HeightPix.Text          = s_NewText;                  //set the height new pixels
            txt_HeightPerc.Text         = i_NewPerc.ToString() + "%"; //set the height new percentage
            txt_HeightPerc.TextChanged += Txt_HeightPerc_TextChanged;
            txt_HeightPix.TextChanged  += Txt_HeightPix_TextChanged;
        }
Пример #2
0
        /// <summary>
        /// Txt_WidthPix_TextChanged()
        /// This method gets called whenever the text changes in the width text box
        /// The percentage and pixel text boxes get changed similtaneously
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Txt_WidthPix_TextChanged(object sender, EventArgs e)
        {
            if (txt_WidthPix.Text.Length <= 0)
            {
                return;
            }
            //please note that the Util_UI.ParseOnlyInt will always return an int
            string s_NewText = Util_UI.ParseOnlyInt(txt_WidthPix);
            int    i_NewPix  = int.Parse(s_NewText);    //parse out the pixel width to an int

            if (i_NewPix <= 0)
            {
                //then you cannot adjust the percent because of a divide by 0, the user should be stopped and ding should be played
                using (SoundPlayer sp_Bonk = new SoundPlayer("./audio/Windows Ding.wav"))
                    sp_Bonk.Play();
                return;
            }
            int i_NewPerc = (int)Math.Round((double)i_NewPix / (double)i_WidthOrig * 100);      //calculate the new percentage

            txt_WidthPix.TextChanged  -= Txt_WidthPix_TextChanged;
            txt_WidthPerc.TextChanged -= Txt_WidthPerc_TextChanged;
            txt_WidthPix.Text          = s_NewText;                  //set the new text of the height pixels text box
            txt_WidthPerc.Text         = i_NewPerc.ToString() + "%"; //set the new width of the percentage box
            txt_WidthPix.TextChanged  += Txt_WidthPix_TextChanged;
            txt_WidthPerc.TextChanged += Txt_WidthPerc_TextChanged;
        }
Пример #3
0
        /// <summary>
        /// txt_WidthPerc_TextChanged()
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Txt_WidthPerc_TextChanged(object sender, EventArgs e)
        {
            //please note that Util_UI.ParseOnlyInt will always return an int, exclude the percentage from the function call
            string s_NewText = Util_UI.ParseOnlyInt(txt_HeightPerc, txt_HeightPerc.Text.Length - 1); //get the new text, which will be used for calculating the new pixel value
            int    i_Perc    = int.Parse(s_NewText);                                                 //parse the text so that the percentage is an int so we can utilize it

            if (i_Perc <= 0)
            {
                //then the percentage is invalid, play a sound and return
                using (SoundPlayer sp_Bonk = new SoundPlayer("./audio/Windows Ding.wav"))
                    sp_Bonk.Play();
                return;
            }
            int i_NewWidth = (int)Math.Round((double)i_WidthOrig * (double)i_Perc / 100.0); //calculate the new width

            txt_WidthPix.TextChanged  -= Txt_WidthPix_TextChanged;                          //unregister the text changed event so changes can manually be done
            txt_WidthPerc.TextChanged -= Txt_WidthPerc_TextChanged;
            txt_WidthPerc.Text         = s_NewText + "%";                                   //set the new width parsed text, tack ap ercentage onto the end
            txt_WidthPix.Text          = i_NewWidth.ToString();                             //set the text of the width pixel box
            txt_WidthPix.TextChanged  += Txt_WidthPix_TextChanged;                          //register the text changed event so changes can manually be done
            txt_WidthPerc.TextChanged += Txt_WidthPerc_TextChanged;
        }