Is there a way to keep a control centered inside a form without having
to recalculate everytime the form is resized? 17 6855
No One,
Yes, there is. When the control is first placed on the form, perform
the calcs to center the control. Once you do that, set the Anchor property
so that it anchors to all sides of its container. If you are placing the
control in the container at design time, then just center the control and
set the Anchor property at design time.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"No One" <no***@yahoo.com> wrote in message
news:40***************@yahoo.com... Is there a way to keep a control centered inside a form without having to recalculate everytime the form is resized?
On Tue, 22 Jun 2004 08:18:05 -0400, Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote: No One,
Yes, there is. When the control is first placed on the form, perform the calcs to center the control. Once you do that, set the Anchor property so that it anchors to all sides of its container. If you are placing the control in the container at design time, then just center the control and set the Anchor property at design time.
Hope this helps.
This will have the side effect of resizing the control though. Anchoring makes sure the distance to the side is constant, and if you anchor both up and down or left and right it will resize the control. I am afraid you will have to recalculate the position in the Form's SizeChanged event.
--
Happy coding!
Morten Wennevik [C# MVP]
>>This will have the side effect of resizing the control though. <<
I doubt he would want the size of the control to remain constant, and have
the margin around it growing and shrinking, that would look just weird. And,
in fact, would seem like a candidate to have a fixed dialog border.
An alternative to Nicholas' suggestion - set the Dock property of the object
to Fill, and adjust the DockPadding property of the form to set the margin
size.
--
John Wood
EMail: first name, dot, second name at priorganize.com
"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opr9zzv5hnklbvpo@morten_x.edunord... On Tue, 22 Jun 2004 08:18:05 -0400, Nicholas Paldino [.NET/C# MVP]
<mv*@spam.guard.caspershouse.com> wrote: No One,
Yes, there is. When the control is first placed on the form,
perform the calcs to center the control. Once you do that, set the Anchor
property so that it anchors to all sides of its container. If you are placing
the control in the container at design time, then just center the control
and set the Anchor property at design time.
Hope this helps.
This will have the side effect of resizing the control though. Anchoring
makes sure the distance to the side is constant, and if you anchor both up
and down or left and right it will resize the control. I am afraid you will
have to recalculate the position in the Form's SizeChanged event. -- Happy coding! Morten Wennevik [C# MVP]
Hi No One,
"No One" <no***@yahoo.com> wrote in message
news:40***************@yahoo.com... Is there a way to keep a control centered inside a form without having to recalculate everytime the form is resized?
If you want the control to remain centered in the form as it resizes,
but you want the control itself to remain the same size, center the control
in the form and set the Anchor property to "None".
Regards,
Daniel
What am I missing here?
Why not simply use HTML <div align="center"> to center the control?
--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/
"John Wood" <sp**@isannoying.com> wrote in message
news:#s**************@tk2msftngp13.phx.gbl... This will have the side effect of resizing the control though. << I doubt he would want the size of the control to remain constant, and have the margin around it growing and shrinking, that would look just weird. And, in fact, would seem like a candidate to have a fixed dialog border.
An alternative to Nicholas' suggestion - set the Dock property of the object to Fill, and adjust the DockPadding property of the form to set the margin size.
-- John Wood EMail: first name, dot, second name at priorganize.com
"Morten Wennevik" <Mo************@hotmail.com> wrote in message news:opr9zzv5hnklbvpo@morten_x.edunord... On Tue, 22 Jun 2004 08:18:05 -0400, Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote: No One,
Yes, there is. When the control is first placed on the form,
perform the calcs to center the control. Once you do that, set the Anchor property so that it anchors to all sides of its container. If you are placing the control in the container at design time, then just center the control and set the Anchor property at design time.
Hope this helps.
This will have the side effect of resizing the control though. Anchoring
makes sure the distance to the side is constant, and if you anchor both up and down or left and right it will resize the control. I am afraid you will have to recalculate the position in the Form's SizeChanged event. -- Happy coding! Morten Wennevik [C# MVP]
well um, he said form not web page.
--
John Wood
EMail: first name, dot, second name at priorganize.com
"clintonG" <csgallagher@RE************@metromilwaukee.com> wrote in message
news:ev**************@tk2msftngp13.phx.gbl... What am I missing here? Why not simply use HTML <div align="center"> to center the control?
-- <%= Clinton Gallagher A/E/C Consulting, Web Design, e-Commerce Software Development Wauwatosa, Milwaukee County, Wisconsin USA NET csgallagher@ REMOVETHISTEXT metromilwaukee.com URL http://www.metromilwaukee.com/clintongallagher/ "John Wood" <sp**@isannoying.com> wrote in message news:#s**************@tk2msftngp13.phx.gbl...>This will have the side effect of resizing the control though. << I doubt he would want the size of the control to remain constant, and
have the margin around it growing and shrinking, that would look just weird.
And, in fact, would seem like a candidate to have a fixed dialog border.
An alternative to Nicholas' suggestion - set the Dock property of the
object to Fill, and adjust the DockPadding property of the form to set the
margin size.
-- John Wood EMail: first name, dot, second name at priorganize.com
"Morten Wennevik" <Mo************@hotmail.com> wrote in message news:opr9zzv5hnklbvpo@morten_x.edunord... On Tue, 22 Jun 2004 08:18:05 -0400, Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote: > No One, > > Yes, there is. When the control is first placed on the form,
perform > the calcs to center the control. Once you do that, set the Anchor property > so that it anchors to all sides of its container. If you are
placing the > control in the container at design time, then just center the
control and > set the Anchor property at design time. > > Hope this helps. > >
This will have the side effect of resizing the control though.
Anchoring makes sure the distance to the side is constant, and if you anchor both
up and down or left and right it will resize the control. I am afraid you
will have to recalculate the position in the Form's SizeChanged event. -- Happy coding! Morten Wennevik [C# MVP]
I read "centered inside a form" with the emphasis on 'inside'
meaning declared HTML that if and when the form is processed
on the server the response will be rendered as HTML regardless.
A span or div element should be all that is needed unless again, I am
really missing the boat. Its not like I have not actually met more than
a handful of developers who can code in their sleep but are literally
HTML clueless. I'm just asking what seemed to be obvious to me...
<%= Clinton Gallagher
"John Wood" <sp**@isannoying.com> wrote in message
news:#H**************@TK2MSFTNGP09.phx.gbl... well um, he said form not web page.
-- John Wood EMail: first name, dot, second name at priorganize.com
"clintonG" <csgallagher@RE************@metromilwaukee.com> wrote in message news:ev**************@tk2msftngp13.phx.gbl... What am I missing here? Why not simply use HTML <div align="center"> to center the control?
-- <%= Clinton Gallagher A/E/C Consulting, Web Design, e-Commerce Software Development Wauwatosa, Milwaukee County, Wisconsin USA NET csgallagher@ REMOVETHISTEXT metromilwaukee.com URL http://www.metromilwaukee.com/clintongallagher/ "John Wood" <sp**@isannoying.com> wrote in message news:#s**************@tk2msftngp13.phx.gbl... >>This will have the side effect of resizing the control though. << I doubt he would want the size of the control to remain constant, and have the margin around it growing and shrinking, that would look just weird. And, in fact, would seem like a candidate to have a fixed dialog border.
An alternative to Nicholas' suggestion - set the Dock property of the object to Fill, and adjust the DockPadding property of the form to set the margin size.
-- John Wood EMail: first name, dot, second name at priorganize.com
"Morten Wennevik" <Mo************@hotmail.com> wrote in message news:opr9zzv5hnklbvpo@morten_x.edunord... > On Tue, 22 Jun 2004 08:18:05 -0400, Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote: > > > No One, > > > > Yes, there is. When the control is first placed on the form, perform > > the calcs to center the control. Once you do that, set the Anchor property > > so that it anchors to all sides of its container. If you are placing the > > control in the container at design time, then just center the control and > > set the Anchor property at design time. > > > > Hope this helps. > > > > > > This will have the side effect of resizing the control though. Anchoring makes sure the distance to the side is constant, and if you anchor both up and down or left and right it will resize the control. I am afraid you will have to recalculate the position in the Form's SizeChanged event. > > -- > Happy coding! > Morten Wennevik [C# MVP]
I've been thinking about a similar problem. The problem is this: Given several controls positioned on a form, I want them to maintain their height, width and location proportional to the form, no matter what it resizes to. I take it from this thread that Anchor/dock settings are inadequate for such a task and only recalculations can keep the controls proportionally sized and positioned.
What has me doubting my memory is that I could have sworn I heard something at TechEd 2001 to the effect that there was built-in resizing. At the time this would have been a godsend given my unpleasant experiences with 3rd party resize controls. (Unfortunately I can't find my beta handouts :-)
"Daniel Pratt" wrote: Hi No One,
"No One" <no***@yahoo.com> wrote in message news:40***************@yahoo.com... Is there a way to keep a control centered inside a form without having to recalculate everytime the form is resized?
If you want the control to remain centered in the form as it resizes, but you want the control itself to remain the same size, center the control in the form and set the Anchor property to "None".
Regards, Daniel
>> I take it from this thread that Anchor/dock settings are inadequate for
such a task and only recalculations can keep the controls proportionally
sized and positioned <<
No not at all -- if you ancor in all four directions then the object will
resize according to the size of the form. The position will stay locked
though. Maybe you should describe what exactly you mean.
--
John Wood
EMail: first name, dot, second name at priorganize.com
"B. Chernick" <BC*******@discussions.microsoft.com> wrote in message
news:0F**********************************@microsof t.com... I've been thinking about a similar problem. The problem is this: Given
several controls positioned on a form, I want them to maintain their height,
width and location proportional to the form, no matter what it resizes to.
I take it from this thread that Anchor/dock settings are inadequate for such
a task and only recalculations can keep the controls proportionally sized
and positioned. What has me doubting my memory is that I could have sworn I heard
something at TechEd 2001 to the effect that there was built-in resizing. At
the time this would have been a godsend given my unpleasant experiences with
3rd party resize controls. (Unfortunately I can't find my beta handouts :-) "Daniel Pratt" wrote:
Hi No One,
"No One" <no***@yahoo.com> wrote in message news:40***************@yahoo.com... Is there a way to keep a control centered inside a form without having to recalculate everytime the form is resized?
If you want the control to remain centered in the form as it
resizes, but you want the control itself to remain the same size, center the
control in the form and set the Anchor property to "None".
Regards, Daniel
Then you would read incorrectly. This is a Windows form.
clintonG wrote: I read "centered inside a form" with the emphasis on 'inside' meaning declared HTML that if and when the form is processed on the server the response will be rendered as HTML regardless.
A span or div element should be all that is needed unless again, I am really missing the boat. Its not like I have not actually met more than a handful of developers who can code in their sleep but are literally HTML clueless. I'm just asking what seemed to be obvious to me...
<%= Clinton Gallagher
"John Wood" <sp**@isannoying.com> wrote in message news:#H**************@TK2MSFTNGP09.phx.gbl... well um, he said form not web page.
-- John Wood EMail: first name, dot, second name at priorganize.com
"clintonG" <csgallagher@RE************@metromilwaukee.com> wrote in message news:ev**************@tk2msftngp13.phx.gbl... What am I missing here? Why not simply use HTML <div align="center"> to center the control?
-- <%= Clinton Gallagher A/E/C Consulting, Web Design, e-Commerce Software Development Wauwatosa, Milwaukee County, Wisconsin USA NET csgallagher@ REMOVETHISTEXT metromilwaukee.com URL http://www.metromilwaukee.com/clintongallagher/ "John Wood" <sp**@isannoying.com> wrote in message news:#s**************@tk2msftngp13.phx.gbl... > >>This will have the side effect of resizing the control though. << > I doubt he would want the size of the control to remain constant, and have > the margin around it growing and shrinking, that would look just weird. And, > in fact, would seem like a candidate to have a fixed dialog border. > > An alternative to Nicholas' suggestion - set the Dock property of the object > to Fill, and adjust the DockPadding property of the form to set the margin > size. > > -- > John Wood > EMail: first name, dot, second name at priorganize.com > > > "Morten Wennevik" <Mo************@hotmail.com> wrote in message > news:opr9zzv5hnklbvpo@morten_x.edunord... > > On Tue, 22 Jun 2004 08:18:05 -0400, Nicholas Paldino [.NET/C# MVP] > <mv*@spam.guard.caspershouse.com> wrote: > > > > > No One, > > > > > > Yes, there is. When the control is first placed on the form, > perform > > > the calcs to center the control. Once you do that, set the Anchor > property > > > so that it anchors to all sides of its container. If you are placing > the > > > control in the container at design time, then just center the control > and > > > set the Anchor property at design time. > > > > > > Hope this helps. > > > > > > > > > > This will have the side effect of resizing the control though. Anchoring > makes sure the distance to the side is constant, and if you anchor both up > and down or left and right it will resize the control. I am afraid you will > have to recalculate the position in the Form's SizeChanged event. > > > > -- > > Happy coding! > > Morten Wennevik [C# MVP] > >
John Wood wrote: This will have the side effect of resizing the control though. << I doubt he would want the size of the control to remain constant, and have the margin around it growing and shrinking, that would look just weird. And, in fact, would seem like a candidate to have a fixed dialog border.
I do not want the control to resize when the form does, just "re-center".
An alternative to Nicholas' suggestion - set the Dock property of the object to Fill, and adjust the DockPadding property of the form to set the margin size.
I do not understand this at all.
Hi B,
"B. Chernick" <BC*******@discussions.microsoft.com> wrote in message
news:0F**********************************@microsof t.com... I've been thinking about a similar problem. The problem is this: Given
several controls positioned on a form, I want them to maintain their height,
width and location proportional to the form, no matter what it resizes to.
I take it from this thread that Anchor/dock settings are inadequate for such
a task and only recalculations can keep the controls proportionally sized
and positioned. What has me doubting my memory is that I could have sworn I heard
something at TechEd 2001 to the effect that there was built-in resizing. At
the time this would have been a godsend given my unpleasant experiences with
3rd party resize controls. (Unfortunately I can't find my beta handouts :-)
Take a look at the Control.Scale method (Form inherits from Control).
Regards,
Daniel
Am I missing something? As a test I have created a 400 by 400 form. On this form I placed a 100 by 100 panel at point (50,50). This panel is anchored as you suggested. Below that I put a button and code in it's on click event to double the height and width of the form.
When I click the button, the position of the panel is still (50,50). It's width is now 500 and it's height is 480. That is not proportional by any measure. (Inicidentally the button now overlaps the panel.)
"John Wood" wrote: I take it from this thread that Anchor/dock settings are inadequate for such a task and only recalculations can keep the controls proportionally sized and positioned <<
No not at all -- if you ancor in all four directions then the object will resize according to the size of the form. The position will stay locked though. Maybe you should describe what exactly you mean.
-- John Wood EMail: first name, dot, second name at priorganize.com
"B. Chernick" <BC*******@discussions.microsoft.com> wrote in message news:0F**********************************@microsof t.com... I've been thinking about a similar problem. The problem is this: Given several controls positioned on a form, I want them to maintain their height, width and location proportional to the form, no matter what it resizes to. I take it from this thread that Anchor/dock settings are inadequate for such a task and only recalculations can keep the controls proportionally sized and positioned. What has me doubting my memory is that I could have sworn I heard
something at TechEd 2001 to the effect that there was built-in resizing. At the time this would have been a godsend given my unpleasant experiences with 3rd party resize controls. (Unfortunately I can't find my beta handouts :-) "Daniel Pratt" wrote:
Hi No One,
"No One" <no***@yahoo.com> wrote in message news:40***************@yahoo.com... > Is there a way to keep a control centered inside a form without having > to recalculate everytime the form is resized?
If you want the control to remain centered in the form as it
resizes, but you want the control itself to remain the same size, center the control in the form and set the Anchor property to "None".
Regards, Daniel
So why not just make the border non-resizable?
Seems a bit odd to have something centered... why is the form resizable at
all in this case?
--
John Wood
EMail: first name, dot, second name at priorganize.com
"No One" <no***@yahoo.com> wrote in message
news:40***************@yahoo.com... John Wood wrote:
>This will have the side effect of resizing the control though. << I doubt he would want the size of the control to remain constant, and
have the margin around it growing and shrinking, that would look just weird.
And, in fact, would seem like a candidate to have a fixed dialog border.
I do not want the control to resize when the form does, just "re-center".
An alternative to Nicholas' suggestion - set the Dock property of the
object to Fill, and adjust the DockPadding property of the form to set the
margin size.
I do not understand this at all.
Ok, am I missing the point? If I simply call Scale for the entire form, everything appears to be scaled appropriately but when users scale the form in the usual method (with mouse or the maximize box) that would be useless. Are you saying I should keep track of form size and use the scale method of each control to adjust each one?
(Incidentally I think I've found a bug in the help. The sample referenced in Control.Scale has nothing to do with Scale.)
"Daniel Pratt" wrote: Hi B,
"B. Chernick" <BC*******@discussions.microsoft.com> wrote in message news:0F**********************************@microsof t.com... I've been thinking about a similar problem. The problem is this: Given several controls positioned on a form, I want them to maintain their height, width and location proportional to the form, no matter what it resizes to. I take it from this thread that Anchor/dock settings are inadequate for such a task and only recalculations can keep the controls proportionally sized and positioned. What has me doubting my memory is that I could have sworn I heard
something at TechEd 2001 to the effect that there was built-in resizing. At the time this would have been a godsend given my unpleasant experiences with 3rd party resize controls. (Unfortunately I can't find my beta handouts :-)
Take a look at the Control.Scale method (Form inherits from Control).
Regards, Daniel
John Wood wrote: So why not just make the border non-resizable? Seems a bit odd to have something centered... why is the form resizable at all in this case?
The form is resizable programmically, not manually. As more elements are
created and placed in the form as per a configuration file, the form may need
to expand horizontally.
>>As more elements are created and placed in the form as per a configuration
file, the form may need to expand horizontally.<<
Ah.. so where does scaling come into that.
Sounds like you're just resizing the form to make space for new controls.
--
John Wood
EMail: first name, dot, second name at priorganize.com
"No One" <no***@yahoo.com> wrote in message
news:40***************@yahoo.com... John Wood wrote:
So why not just make the border non-resizable? Seems a bit odd to have something centered... why is the form resizable
at all in this case?
The form is resizable programmically, not manually. As more elements are created and placed in the form as per a configuration file, the form may
need to expand horizontally. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Freek te Water |
last post by:
Hi,
Hope no-one is offended by my probably noob question...
Context:
I have a web page design, which always centres in the middle of the
screen (using a 100%*100% HTML-table). Now I also use...
|
by: Ryan Wade |
last post by:
If the user resizes IE I want the webform controls to be
automatically repositioned in the center of the form. How
can I accomplish this?
Ryan
|
by: gsb58 |
last post by:
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...
|
by: Austin Powers |
last post by:
I want to (on one line) show something like the following
-------------------------------------------------------
left centered right...
|
by: TheLongshot |
last post by:
I just recently converted a few pages of my application to using master
pages. Problem is, in all of my content pages, the contents are
centered. I can't figure out why. The markup in the...
|
by: Chris Saunders |
last post by:
This is not actually a C# question but I'm not sure which newsgroup is
appropriate for
this question. My apologies if I'm being "off-topic".
I'm writing and application that has a group box...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |