Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my main window fit all resolution expect 1280X600.my some control location(Y-axis) is above 600. help me.

What I have tried:

if(Screen.PrimaryScreen.Bounds.Width==1280 && Screen.PrimaryScreen.Bounds.Height==600)
            {
                float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
                float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
                int newWidth = (int)(600 * xRatio);
                int newHeight = (int)(400 * yRatio);
                int newInspectionWidth = (int)(201 * xRatio);
                int newInspectionHeight = (int)(136 * yRatio);
                int newshiftWidth = (int)(368 * xRatio);
                int newshiftHeight = (int)(134 * yRatio);
                int newgb1Width = (int)(24 * xRatio);
                int newgb1Height = (int)(134 * yRatio);
                 pictureBox1.Size = new Size(newWidth, newHeight);
                gb_InspectionStatistics.Size = new Size(newInspectionWidth, newInspectionHeight);
                groupBoxShift.Size = new Size(newshiftWidth, newshiftHeight);
                groupBox1.Size = new Size(newgb1Width, newgb1Height);

               // MessageBox.Show(pictureBox1.Size.ToString());

            }

private void btnsettings()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
        /*  int newWidth = (int)(147 * xRatio);
          int newHeight = (int)(47 * yRatio);*/
          int newX = (int)(22 * xRatio);
          int newY = (int)(21 * yRatio);
          //btnSettings.Size = new Size(newWidth, newHeight);
          btnSettings.Size = new Size(147, 47);
          btnSettings.Location = new Point(newX + 192, newY);
      }
      private void TeachModuleResize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
       /*   int newWidth = (int)(147 * xRatio);
          int newHeight = (int)(47 * yRatio);*/
          int newX = (int)(22 * xRatio);
          int newY = (int)(21 * yRatio);
         // TeachModule.Size = new Size(newWidth, newHeight);
          TeachModule.Size = new Size(147, 47);
          TeachModule.Location = new Point(newX + 383, newY);
      }
      private void btnModelResize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
        /*  int newWidth = (int)(147 * xRatio);
          int newHeight = (int)(47 * yRatio);*/
          int newX = (int)(22 * xRatio);
          int newY = (int)(21 * yRatio);
         // btnModel.Size = new Size(newWidth, newHeight);
          btnModel.Size = new Size(147, 47);
          btnModel.Location = new Point(newX + 569, newY);
      }
      private void btnStartResize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
       /*   int newWidth = (int)(147 * xRatio);
          int newHeight = (int)(47 * yRatio);  */
          int newX = (int)(22 * xRatio);
          int newY = (int)(95 * yRatio);
       //   btnStart.Size = new Size(newWidth, newHeight);
          btnStart.Size = new Size(147, 47);
          btnStart.Location = new Point(newX, newY);
      }
      private void btnnewUserResize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
       /*   int newWidth = (int)(147 * xRatio);
          int newHeight = (int)(47 * yRatio);*/
          int newX = (int)(22 * xRatio);
          int newY = (int)(95 * yRatio);
        //  btnnewuser.Size = new Size(newWidth, newHeight);
          btnnewuser.Size = new Size(147, 47);
          btnnewuser.Location = new Point(newX + 192, newY);
      }
      private void btnReportResize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
        /*  int newWidth = (int)(147 * xRatio);
          int newHeight = (int)(47 * yRatio);*/
          int newX = (int)(22 * xRatio);
          int newY = (int)(95 * yRatio);
         // btnReport.Size = new Size(newWidth, newHeight);
          btnReport.Size = new Size(147, 47);
          btnReport.Location = new Point(newX + 383, newY);
      }
      private void btnExitResize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
       /*   int newWidth = (int)(147 * xRatio);
          int newHeight = (int)(47 * yRatio);  */
          int newX = (int)(22 * xRatio);
          int newY = (int)(95 * yRatio);
        //  btnExit.Size = new Size(newWidth, newHeight);
          btnExit.Size = new Size(147, 47);
          btnExit.Location = new Point(newX + 569, newY);
      }
      private void picturebox2Resize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
        /*  int newWidth = (int)(240 * xRatio);
          int newHeight = (int)(122 * yRatio);*/
          int newX = (int)(772 * xRatio);
          int newY = (int)(53 * yRatio);
        //  pictureBox2.Size = new Size(newWidth, newHeight);
          pictureBox2.Size = new Size(240, 122);
          pictureBox2.Location = new Point(newX, newY);
      }
      private void picturebox3Resize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
        /*  int newWidth = (int)(132 * xRatio);
          int newHeight = (int)(77 * yRatio);*/
          int newX = (int)(639 * xRatio);
          int newY = (int)(675 * yRatio);
         // pictureBox3.Size = new Size(newWidth, newHeight);
          pictureBox3.Size = new Size(132, 77);
          pictureBox3.Location = new Point(newX, newY);
      }
      private void picturebox4Resize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
       /*   int newWidth = (int)(132 * xRatio);
          int newHeight = (int)(77 * yRatio);*/
          int newX = (int)(639 * xRatio);
          int newY = (int)(675 * yRatio);
        //  pictureBox4.Size = new Size(newWidth, newHeight);
          pictureBox4.Size = new Size(132, 77);
          pictureBox4.Location = new Point(newX, newY);
      }
      private void pieControlResize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
         /* int newWidth = (int)(220 * xRatio);
          int newHeight = (int)(115 * yRatio); */
          int newX = (int)(784 * xRatio);
          int newY = (int)(639 * yRatio);
          pieChartControl2.Size = new Size(220, 115);
         // pieChartControl2.Size = new Size(newWidth, newHeight);
          pieChartControl2.Location = new Point(newX, newY);
      }
      private void picturebox1Resize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
        /*  int newWidth = (int)(600 * xRatio);
          int newHeight = (int)(400 * yRatio); */
          int newX = (int)(64 * xRatio);
          int newY = (int)(182 * yRatio);
        //  pictureBox1.Size = new Size(newWidth, newHeight);
          pictureBox1.Size = new Size(600, 400);
          pictureBox1.Location = new Point(newX, newY);
      }
      private void UserAuthResize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
        /*  int newWidth = (int)(235 * xRatio);
          int newHeight = (int)(52 * yRatio);*/
          int newX = (int)(771 * xRatio);
          int newY = (int)(574 * yRatio);
        //  UserAuth.Size = new Size(newWidth, newHeight);
          UserAuth.Size = new Size(235, 52);
          UserAuth.Location = new Point(newX, newY);
      }
      private void lable1Resize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
       /*   int newWidth = (int)(118 * xRatio);
          int newHeight = (int)(23 * yRatio);*/
          int newX = (int)(771 * xRatio);
          int newY = (int)(218 * yRatio);
        //  label1.Size = new Size(newWidth, newHeight);
          label1.Size = new Size(118, 23);
          label1.Location = new Point(newX, newY);
      }
      private void lblmodelnameResize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
        /*  int newWidth = (int)(50 * xRatio);
          int newHeight = (int)(19 * yRatio);*/
          int newX = (int)(886 * xRatio);
          int newY = (int)(222 * yRatio);
        //  lblModelNameFetched.Size = new Size(newWidth, newHeight);
          lblModelNameFetched.Size = new Size(50, 19);
          lblModelNameFetched.Location = new Point(newX, newY);
      }
      private void lbltimeResize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
        /*  int newWidth = (int)(240 * xRatio);
          int newHeight = (int)(47 * yRatio);*/
          int newX = (int)(770 * xRatio);
          int newY = (int)(3 * yRatio);
        //  lblTime.Size = new Size(newWidth, newHeight);
          lblTime.Size = new Size(240, 47);
          lblTime.Location = new Point(newX, newY);
      }
      private void groupbox1Resize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
        /*  int newWidth = (int)(24 * xRatio);
          int newHeight = (int)(134 * yRatio);*/
          int newX = (int)(593 * xRatio);
          int newY = (int)(621 * yRatio);
        //  groupBox1.Size = new Size(newWidth, newHeight);
          groupBox1.Size = new Size(24, 134);
          groupBox1.Location = new Point(newX, newY);
      }
      private void groupShiftResize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
       /*   int newWidth = (int)(368 * xRatio);
          int newHeight = (int)(134 * yRatio); */
          int newX = (int)(223 * xRatio);
          int newY = (int)(618 * yRatio);
         // groupBoxShift.Size = new Size(newWidth, newHeight);
          groupBoxShift.Size = new Size(368, 134);
          groupBoxShift.Location = new Point(newX, newY);
      }
      private void groupInspectionResize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
        /*  int newWidth = (int)(201 * xRatio);
          int newHeight = (int)(136 * yRatio);*/
          int newX = (int)(16 * xRatio);
          int newY = (int)(618 * yRatio);
         // gb_InspectionStatistics.Size = new Size(newWidth, newHeight);
          gb_InspectionStatistics.Size = new Size(201, 136);
          gb_InspectionStatistics.Location = new Point(newX, newY);
      }
      private void groupbox2Resize()
      {
          float xRatio = (float)(Screen.PrimaryScreen.Bounds.Width) / 1024f;
          float yRatio = (float)(Screen.PrimaryScreen.Bounds.Height) / 768f;
       /*   int newWidth = (int)(234 * xRatio);
          int newHeight = (int)(300 * yRatio);  */
          int newX = (int)(772 * xRatio);
          int newY = (int)(254 * yRatio);
         // groupBox2.Size = new Size(newWidth, newHeight);
          groupBox2.Size = new Size(234, 300);
          groupBox2.Location = new Point(newX, newY);
      }
Posted
Updated 14-Mar-21 4:43am
Comments
Ralf Meier 13-Mar-21 7:06am    
I don't understand the calculation within your provided code. I suppose you try a kind of scaling.
But when you ask for Screen.PrimaryScreen.Bounds.Height==600 - why do you divide inside your scaling with 768 to get your faktor ?

You should design your form using the lowest resolution, an alternative might be to activate scrollbars, see: c# - Enable scroll bars in windows forms - Stack Overflow[^]
 
Share this answer
 
Make your form scrollable, or change to a tab-base system where some of the controls are on one tab, and other controls are on another.
 
Share this answer
 
Comments
Member 15099068 13-Mar-21 6:10am    
without any form scrollable, any other solution?
#realJSOP 13-Mar-21 6:55am    
I mentioned an alternative - use tabs.
I think it's a mistake to try and handle arbitrary Form resizing by calculating ratios for each Control:

1 Fonts: smaller sizes are "optically adjusted" for readability at certain fixed sizes.

2 Recursion: doing it for top-level Controls requires doing it for contained Controls; potentially a lot of calculation; high chance of distracting visual artifacts as multiple resize events are triggered.

If you really require arbitrary resizing, use WPF.

What you can do in WinForms:

1 use Control Anchor and Dock Properties to automatically handle resizing.

2 use Container Controls that have inherent layout structure like: TabControl, TableLayoutPanel, etc.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900