Screen dimensions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lupus
    New Member
    • Feb 2007
    • 6

    Screen dimensions

    Hi!
    I need to create a form and fill it with a number of button decided at run-time..then I need to create this buttons according to their number such that they adapt on the whole screen dimension..
    Is there any property or anything that tells me this?
    Thanx!!!
    Davide
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    This post is very vague and lacks useful information. It is also very similar to your first post. Please state clearly the problem or error you are having. State the programming language, whether it is windows or web etc. I realise that you may have difficulty with English, but more info at the start should mean a faster response. Thanks.

    Comment

    • george1106
      New Member
      • Oct 2006
      • 14

      #3
      Hi.

      look, there are a few Objects in the framework... you can use them to know about your screen..

      the main object to do it is the Screen Object. I use it to create a form that should not move out the screen...

      if (this.Left > Screen.AllScree ns[Screen.AllScree ns.Length - 1].Bounds.Right - Properties.Sett ings.Default.ta manno.Width)
      this.Left = Screen.AllScree ns[Screen.AllScree ns.Length - 1].Bounds.Right - (Properties.Set tings.Default.t amanno.Width + 10);
      //deja de ser visible del lado izquierdo
      if (this.Left < 0)
      this.Left = 10;
      //no es visible la parte superior
      if (this.Top < 0)
      this.Top = 10;
      //no es visible la parte inferior
      if (this.Bottom > Screen.AllScree ns[Screen.AllScree ns.Length - 1].Bounds.Bottom)
      this.Top = Screen.AllScree ns[Screen.AllScree ns.Length - 1].Bounds.Bottom - (Properties.Set tings.Default.t amanno.Height + 10 + (Screen.Primary Screen.Bounds.H eight - Screen.PrimaryS creen.WorkingAr ea.Height));
      //inicializar combo
      for (int i = 0; i < Screen.AllScree ns.Length; i++)
      this.comboBox1. Items.Add(Scree n.AllScreens[i].DeviceName);

      this is part of my code.. I wope it help you
      the screeen object is also an array of screens if you have more than one.

      Comment

      • lupus
        New Member
        • Feb 2007
        • 6

        #4
        You are right, I should specify a bit better!
        I'm working on a Windows app, not Web, with C# language.
        The fact is I need this property or something that tells me width and height of the screen I'm using, including the Windows taskbar (I think this is the name in English, meaning the bar at the bottom, with start button, open applications, ...)

        Thanx George, but: the Screen you mean is a class of System.Windows. Forms or a property of Microsoft.Visua lBasic.Devices. Computer?

        If it's the second, I think I can't use it in C# program, can I?
        If it's the first, I tried to call the property Screen.Bounds but it's not static so the compiler asks me to give an object reference..whic h object should I use? Is there anything similar to ThisComputerWor king.Screen.Bou nds?

        I'll attach my piece of code:

        internal void placeButtons(in t[] dimensions)
        {
        int i = 0;
        int[] dim = dimensions;
        Button[,] buttons = new Button[dim[0], dim[1]];

        for (int r = 0; r < dim[0]; r++)
        {
        for (int c = 0; c < dim[1]; c++)
        {
        //string str = CreateStrName(i );
        buttons[r, c] = new Button();
        i++;
        }
        }
        this.SuspendLay out();
        i = 0;
        for (int r = 0; r < dim[0]; r++)
        {
        for (int c = 0; c < dim[1]; c++)
        {
        string str = CreateStrName(i );
        //int buttH = SystemInformati on.PrimaryMonit orMaximizedWind owSize.Height / dim[0];
        //int buttW = SystemInformati on.PrimaryMonit orMaximizedWind owSize.Width / dim[1];
        //********trov come indicare le dim del tutto schermo
        Rectangle rect = Screen.Bounds;
        int buttH = rect.Height / dim[0];
        int buttW = rect.Width / dim[1];
        int x = buttW * c;
        int y = buttH * r;

        buttons[r, c].Location = new System.Drawing. Point(x, y);
        buttons[r, c].Name = str;
        buttons[r, c].Size = new System.Drawing. Size(buttW, buttH);
        buttons[r, c].TabIndex = i;
        buttons[r, c].Text = str;
        buttons[r, c].UseVisualStyle BackColor = true;
        Console.WriteLi ne(buttons[r, c].Name + " placed at coordinates: (" + x + "," + y + ")");
        i++;
        }
        }
        for (int r = 0; r < dim[0]; r++)
        {
        for (int c = 0; c < dim[1]; c++)
        {
        this.Controls.A dd(buttons[r, c]);
        }
        }
        }

        Comment

        • george1106
          New Member
          • Oct 2006
          • 14

          #5
          you can't use it like that.. you should specify the screen.

          ej.

          Rectangle rect = Screen.AllScree ns[0].Bounds;


          you must put AllScreens and the screen wich you mean to check, and then you can obtain the bouds.

          i hope it help :D

          Comment

          Working...