469,299 Members | 2,050 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

Screen dimensions

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?
Feb 26 '07 #1
4 4249
4,871 Expert 4TB
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.
Feb 26 '07 #2

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.AllScreens[Screen.AllScreens.Length - 1].Bounds.Right - Properties.Settings.Default.tamanno.Width)
this.Left = Screen.AllScreens[Screen.AllScreens.Length - 1].Bounds.Right - (Properties.Settings.Default.tamanno.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.AllScreens[Screen.AllScreens.Length - 1].Bounds.Bottom)
this.Top = Screen.AllScreens[Screen.AllScreens.Length - 1].Bounds.Bottom - (Properties.Settings.Default.tamanno.Height + 10 + (Screen.PrimaryScreen.Bounds.Height - Screen.PrimaryScreen.WorkingArea.Height));
//inicializar combo
for (int i = 0; i < Screen.AllScreens.Length; i++)

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.
Feb 26 '07 #3
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.VisualBasic.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..which object should I use? Is there anything similar to ThisComputerWorking.Screen.Bounds?

I'll attach my piece of code:

internal void placeButtons(int[] 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 = 0;
for (int r = 0; r < dim[0]; r++)
for (int c = 0; c < dim[1]; c++)
string str = CreateStrName(i);
//int buttH = SystemInformation.PrimaryMonitorMaximizedWindowSiz e.Height / dim[0];
//int buttW = SystemInformation.PrimaryMonitorMaximizedWindowSiz e.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].UseVisualStyleBackColor = true;
Console.WriteLine(buttons[r, c].Name + " placed at coordinates: (" + x + "," + y + ")");
for (int r = 0; r < dim[0]; r++)
for (int c = 0; c < dim[1]; c++)
this.Controls.Add(buttons[r, c]);
Feb 26 '07 #4
you can't use it like that.. you should specify the screen.


Rectangle rect = Screen.AllScreens[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
Feb 27 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

13 posts views Thread by Erik | last post: by
48 posts views Thread by David J Patrick | last post: by
1 post views Thread by Patrick | last post: by
7 posts views Thread by mukeshgupta.WD | last post: by
1 post views Thread by Mufasa | last post: by
reply views Thread by =?Utf-8?B?amFtZXNjaGk=?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.