퇴근5분전


  컨트롤들을 하나의 판넬에 몰아 넣었을때... 특정 배율에 화면에 꽉 채우기 위해 계산한 방법임.

그러나. 아래 대각선 비율로만 하면 한쪽이 너무 클 경우 꽉찬 배율로 맞출수 없으므로,
가로, 세로를 각각 아래 같은 방법으로 계산 후 가장 좋은 조건으로 선택해서 Zoom 처리 해주어야 했다.




  void AutoSizeFit2()
        {
            try
            {
                Rectangle rct = toolStripContainer1.ContentPanel.ClientRectangle;
                float cx = rct.Width / 2f + rct.Left;
                float cy = rct.Height / 2f + rct.Top;
                toolStripComboBox1.SelectedIndex = 0;                 //Zoom 0번째 부터...
               
area = ContentRegion();

                // 대각선
                //double d1 = rct.Width > rct.Height ? rct.Width : rct.Height;
                //double d2 = area.Width > area.Height ? area.Width : area.Height;
                //double a0 = Math.Sqrt(Math.Pow(d1, 2d) + Math.Pow(d1, 2d));
                //double a1 = Math.Sqrt(Math.Pow(d2, 2d) + Math.Pow(d2, 2d));

                //// a : b = c : d 계산!!    ad = bc
                //double ze = a0 * Factors[0] / a1;
                //int loop = Factors.Length;
                //while (ze <= Factors[--loop] && loop >= 0) ;

                //가로
                //double d1 = rct.Width > rct.Height ? rct.Width : rct.Height;
                //double d2 = area.Width > area.Height ? area.Width : area.Height;
                //double a0 = d1;//Math.Sqrt(Math.Pow(d1, 2d) + Math.Pow(d1, 2d));
                //double a1 = d2;// Math.Sqrt(Math.Pow(d2, 2d) + Math.Pow(d2, 2d));

                //// a : b = c : d 계산!!    ad = bc
                //double ze = a0 * Factors[0] / a1;
                //int loop = Factors.Length;
                //while (ze <= Factors[--loop] && loop >= 0) ;

                //세로
                //double d1 = rct.Height;
                //double d2 = area.Height;
                //double a0 = d1;//Math.Sqrt(Math.Pow(d1, 2d) + Math.Pow(d1, 2d));
                //double a1 = d2;// Math.Sqrt(Math.Pow(d2, 2d) + Math.Pow(d2, 2d));

                //// a : b = c : d 계산!!    ad = bc
                //double ze = a0 * Factors[0] / a1;
                //int loop = Factors.Length;
                //while (ze <= Factors[--loop] && loop >= 0) ;


                #region 가로 / 세로 병행 ( 이게 제일 빠르네!! )
                   // 세로
                    double d1 = rct.Height;
                double d2 = area.Height;
                double ze1 = d1 * Factors[0] / d2;
                int loop1 = Factors.Length;
                while (ze1 <= Factors[--loop1] && loop1 > 0) ;

                // 가로
                double a0 = rct.Width;
                double a1 = area.Width;
                // a : b = c : d 계산!!    ad = bc
                double ze2 = a0 * Factors[0] / a1;
                int loop2 = Factors.Length;
                while (ze2 <= Factors[--loop2] && loop2 > 0) ;
                
                toolStripComboBox1.SelectedIndex = loop1 < loop2 ? loop1 : loop2 ;
                #endregion
            }
            finally
            {
                CenterMove2();
            }
        }

'# 1) 프로그래밍' 카테고리의 다른 글

.Net] 배율 맞추기 II  (0) 2012.03.25
.Net] 가운데 이동  (0) 2012.03.25
.Net] C# 객체 숨기기....  (0) 2012.03.22
C# 포인터...  (0) 2012.03.16
컨트롤 마우스 이동 처리  (0) 2012.03.14