Hi!
On a form I have a calendar. The form is rezised to 1024x768 (Don't
worry - this is a training case) when loaded.
Now I want to center the calendar on the form so that its edges are
equally far from the upper, right, left and bottom borders of the form.
I understand I must use the location property, am I right?
Anybody that could point me to an article on this?
Me.Name
:-) 4 3308
> I understand I must use the location property, am I right?
The Location property of a System.Windows.Forms.Control is a Point
structure. The Point has an X and a Y member. The X member defines the
distance (in pixels) of the left edge of the control from the left edge of
the client area of the Container Control it resides in. The Y member defines
the distance (in pixels) of the top edge of the control from the top edge of
the client area of the Container Control it resides in. Now I want to center the calendar on the form so that its edges are equally far from the upper, right, left and bottom borders of the form.
Knowing what I've just told you, it's a simple Math problem. A Control is a
rectangle that occupies a certain area in its parent rectangle. The Control
has a Width and a Height property as well. Taking each of these in turn, the
Width of the parent rectangle minus the width of the Control rectangle
yields the total amount of space available on both sides. Half of the width
of the Control rectangle defines its center. Half of the parent Control
rectangle defines the center of the parent Control rectangle. To center the
Control in the parent Control, the center of the Control must coincide with
the center of the parent Control. As the X member of the Location property
defines the distance from the left edge of the parent Control, the X member
of the Location property of the Control must be half of the width of the
Parent Container minus half the width of the Control:
Parent: 100 pixels wide
0---------------25---------------50---------------75---------------100
Control: 50 pixels wide
0---------------25---------------50
1/2 of the Parent's width = 50.
1/2 of the Control's width is 25.
50 - 25 = 25.
The X position of the Control must be 25 in order to leave the same number
of pixels on the left as on the right.
Apply the same Math to get the Y member of the Location property, and you're
done!
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
<gs***@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com... Hi!
On a form I have a calendar. The form is rezised to 1024x768 (Don't worry - this is a training case) when loaded.
Now I want to center the calendar on the form so that its edges are equally far from the upper, right, left and bottom borders of the form.
I understand I must use the location property, am I right?
Anybody that could point me to an article on this?
Me.Name
:-)
This is a great treatise on the math involved, but there is a much
simpler way. Put the control on your form, center it with the "Center
Control" button in the form designer, then turn OFF both the Left Anchor
and the Right Anchor properties of the control. If you want to keep the
control centered vertically as well, then center the control vertically
(with the "Center Vertically" button) and make sure both the Top Anchor
and the Bottom Anchor are turned off.
You don't need to mess with catching the form resize event or anything
like that.
-mdb
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in
news:ex**************@tk2msftngp13.phx.gbl: I understand I must use the location property, am I right?
The Location property of a System.Windows.Forms.Control is a Point structure. The Point has an X and a Y member. The X member defines the distance (in pixels) of the left edge of the control from the left edge of the client area of the Container Control it resides in. The Y member defines the distance (in pixels) of the top edge of the control from the top edge of the client area of the Container Control it resides in.
Now I want to center the calendar on the form so that its edges are equally far from the upper, right, left and bottom borders of the form.
Knowing what I've just told you, it's a simple Math problem. A Control is a rectangle that occupies a certain area in its parent rectangle. The Control has a Width and a Height property as well. Taking each of these in turn, the Width of the parent rectangle minus the width of the Control rectangle yields the total amount of space available on both sides. Half of the width of the Control rectangle defines its center. Half of the parent Control rectangle defines the center of the parent Control rectangle. To center the Control in the parent Control, the center of the Control must coincide with the center of the parent Control. As the X member of the Location property defines the distance from the left edge of the parent Control, the X member of the Location property of the Control must be half of the width of the Parent Container minus half the width of the Control:
Parent: 100 pixels wide 0---------------25---------------50---------------75---------------100
Control: 50 pixels wide 0---------------25---------------50
1/2 of the Parent's width = 50. 1/2 of the Control's width is 25. 50 - 25 = 25. The X position of the Control must be 25 in order to leave the same number of pixels on the left as on the right.
Apply the same Math to get the Y member of the Location property, and you're done!
Damn, I thought I was going to get to answer a question. Well done Micheal.
"Michael Bray" wrote: This is a great treatise on the math involved, but there is a much simpler way. Put the control on your form, center it with the "Center Control" button in the form designer, then turn OFF both the Left Anchor and the Right Anchor properties of the control. If you want to keep the control centered vertically as well, then center the control vertically (with the "Center Vertically" button) and make sure both the Top Anchor and the Bottom Anchor are turned off.
You don't need to mess with catching the form resize event or anything like that.
-mdb
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in news:ex**************@tk2msftngp13.phx.gbl:
I understand I must use the location property, am I right?
The Location property of a System.Windows.Forms.Control is a Point structure. The Point has an X and a Y member. The X member defines the distance (in pixels) of the left edge of the control from the left edge of the client area of the Container Control it resides in. The Y member defines the distance (in pixels) of the top edge of the control from the top edge of the client area of the Container Control it resides in.
Now I want to center the calendar on the form so that its edges are equally far from the upper, right, left and bottom borders of the form.
Knowing what I've just told you, it's a simple Math problem. A Control is a rectangle that occupies a certain area in its parent rectangle. The Control has a Width and a Height property as well. Taking each of these in turn, the Width of the parent rectangle minus the width of the Control rectangle yields the total amount of space available on both sides. Half of the width of the Control rectangle defines its center. Half of the parent Control rectangle defines the center of the parent Control rectangle. To center the Control in the parent Control, the center of the Control must coincide with the center of the parent Control. As the X member of the Location property defines the distance from the left edge of the parent Control, the X member of the Location property of the Control must be half of the width of the Parent Container minus half the width of the Control:
Parent: 100 pixels wide 0---------------25---------------50---------------75---------------100
Control: 50 pixels wide 0---------------25---------------50
1/2 of the Parent's width = 50. 1/2 of the Control's width is 25. 50 - 25 = 25. The X position of the Control must be 25 in order to leave the same number of pixels on the left as on the right.
Apply the same Math to get the Y member of the Location property, and you're done!
Yeah, that is easy.
However...I wanted to learn how do this mathematically, so a big thanks
to both for contributing
:-)
Me.Name This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Griff Miller |
last post by:
Please see http://home.houston.rr.com/gmiller15/css/vertprob.html .
In mozilla 1.6/1.7 it looks the way I want it, with a thin separation
between the two boxes. In IE6, the two boxes touch, which...
|
by: hzgt9b |
last post by:
Using Visual studio 2003 and VB.NET, I want to programatically position a
control (windows media player) on my form. For example, I want to position
the control in 1 of 9 locations: topLeft,...
|
by: Michelle Stone |
last post by:
I have a user control that I want to position anywhere I
like on my Web Form. I am able to do so in design time by
adding a style="position:absolute" to the HTML tag of the
user control dragged in...
|
by: Johnson Smith |
last post by:
Question is related to ASP.Net and controlling the position of these
controls.
I am using html table to placce my web controls. I am displaying same
datagrid and calendar controls at clicks of...
|
by: Angelos Karantzalis |
last post by:
Hi guys,
I've a small problem with validators.
I'm building a single .aspx file that handles all my form posts. I need to
be using ASP.NET validators ( or subclasses thereof ), so what i do to...
|
by: Glenn T. Kitchen |
last post by:
Hello Group,
How do you position a web control you create at runtime?
I thought:
=====================================
Dim Label1 as Label = New Label
Me.Controls.Add(Label1)...
|
by: Rob R. Ainscough |
last post by:
I'm slowly (very slowly) working my way thru the bizarre and sadistic world
of control positioning in MultiViews (ASP 2.0). I came across this to help
me explain (or attempt to anyway) why my web...
|
by: steve |
last post by:
Hi All
I have textboxes within a TableLayoutpanel and I want to be able to position
an independant control adjacent to a selected textbox
This independent control allows selection of text to...
|
by: Hamed |
last post by:
Hello
I have a question about CHILD forms in an MDI form.
How can I have a neat positioning of child windows in an MDI form?
When I open a new child window in my MDI form it is opened in a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |