need a algoritm to place user control

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hello!

I will place userControl on the form by using this pattern where I number
each placed user control with numbers
1 2
3 4
5 6
....

I should be able to place any number of user control on the form but only in
the pattern that is shown.
So I can place 2 or 5 or 7 or any number.

My question is if any have any good algoritm to use for location for each
placed user control.

//Tony
 
I will place userControl on the form by using this pattern where I number
each placed user control with numbers
1 2
3 4
5 6
...

I should be able to place any number of user control on the form but only
in the pattern that is shown.
So I can place 2 or 5 or 7 or any number.

My question is if any have any good algoritm to use for location for each
placed user control.

More info. Are you looking for an algorithm that gives you the X and Y
coordinates for a given user control number? Like 1 -> (0, 0), 2 -> (250,
0), etc.? Does this algorithm need to support a varying number of columns or
will there ALWAYS only be 2 columns? Again, please provide more info.
 
Jeff Johnson said:
More info. Are you looking for an algorithm that gives you the X and Y
coordinates for a given user control number? Like 1 -> (0, 0), 2 -> (250,
0), etc.? Does this algorithm need to support a varying number of columns
or will there ALWAYS only be 2 columns? Again, please provide more info.
Yes always two columns with same small space between each user control
I hope if it's possible to find some generic algoritm that will satisfy any
number of user control

//Tony
 
Tony Johansson said:
Yes always two columns with same small space between each user control
I hope if it's possible to find some generic algoritm that will satisfy
any number of user control

//Tony
yes it's the x and y pos I hope to find some generic algoritm for.
As you can see here it's the xPos and yPos that should have suitable values
so my user control is placed according to the pattern that I showed.
pg.Location = new Point(xPos, yPos);



//Tony
 
Tony said:
Hello!

I will place userControl on the form by using this pattern where I number
each placed user control with numbers
1 2
3 4
5 6
...

I should be able to place any number of user control on the form but only in
the pattern that is shown.
So I can place 2 or 5 or 7 or any number.

My question is if any have any good algoritm to use for location for each
placed user control.

Are these controls all the same size?
If not, is the size of all of them known before the first one is placed?
If not, is it okay to move a control that has already been placed?
 
Rick Lones said:
Are these controls all the same size?
If not, is the size of all of them known before the first one is
placed?
If not, is it okay to move a control that has already been placed?
All user control that are placed on the form are identical in size.
The only requirement is that there should be some small space between
them.in x and y.

//Tony
 
Tony said:
All user control that are placed on the form are identical in size.
The only requirement is that there should be some small space between
them.in x and y.

Well then this hardly rises to the level of an "algorithm". It's
straightforward junior high school algebra. Assign identifiers to your
variables and constants and derive the expressions which calculate your xpos and
ypos. Implement them as functions if you want to get "generic".
 
yes it's the x and y pos I hope to find some generic algoritm for.
As you can see here it's the xPos and yPos that should have suitable values
so my user control is placed according to the pattern that I showed.
pg.Location = new Point(xPos, yPos);

Something along the lines of:

x = lm + (n % 2) * w

y = tm + (n / 2) * h

Arne
 
Tony Johansson said:
Can you specify what each variable is.

//Tony

Here is the event handler that is called when a new user control is supposed
to be added to the form
This only add two user control correct. So how should I add these two
statements into this code to make it correct.
x = lm + (n % 2) * w
y = tm + (n / 2) * h

private void BtnNewPlayer_Click(object sender, EventArgs e)
{
guiCounter++;
int myWidth= 0;
int myHeight = 0;

if (pg != null)
{
myWidth = pg.Width;
myHeight = pg.Height;
}

pg = new PlayerGUI();

if (guiCounter == 1)
pg.Location = new Point(0, 0);
else if (guiCounter % 2 == 0)
pg.Location = new Point(myWidth + 5, 0);


playerGUIs.Add(pg);
panel1.Controls.Add(pg);
dgvAllPlayers.DataSource = bindingSource;
}
//Tony
 
Tony Johansson said:
Here is the event handler that is called when a new user control is
supposed to be added to the form
This only add two user control correct. So how should I add these two
statements into this code to make it correct.
x = lm + (n % 2) * w
y = tm + (n / 2) * h

private void BtnNewPlayer_Click(object sender, EventArgs e)
{
guiCounter++;
int myWidth= 0;
int myHeight = 0;

if (pg != null)
{
myWidth = pg.Width;
myHeight = pg.Height;
}

pg = new PlayerGUI();

if (guiCounter == 1)
pg.Location = new Point(0, 0);
else if (guiCounter % 2 == 0)
pg.Location = new Point(myWidth + 5, 0);


playerGUIs.Add(pg);
panel1.Controls.Add(pg);
dgvAllPlayers.DataSource = bindingSource;
}
//Tony

yes I'just use these and now it works fine
x = lm + (n % 2) * w
y = tm + (n / 2) * h

//Tony
 
Back
Top