<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Clearest code challenge</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx</link><description>This is a real problem I had recently. Suppose you have a form with OK and Cancel buttons. You want the buttons to be placed in the bottom-right corner of the form. Normally you'd place them where they go, then set their Anchor properties to Bottom, Right.</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Clearest code challenge</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx#93288</link><pubDate>Sat, 20 Mar 2004 19:47:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:93288</guid><dc:creator>Derek LaZard</dc:creator><description>The following info will be needed in the equation:&lt;br&gt;&lt;br&gt;1) FormDimensions &lt;br&gt;2) ButtonDimensions&lt;br&gt;</description></item><item><title>re: Clearest code challenge</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx#93302</link><pubDate>Sat, 20 Mar 2004 20:37:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:93302</guid><dc:creator>DarthPedro</dc:creator><description>Assuming that this is the Form and button sizes have already been set...&lt;br&gt;&lt;br&gt;private const int Size buttonMargin = new Size(12, 12);&lt;br&gt;&lt;br&gt;this._buttonCancel.Location.X = this.ClientRectangle.Right - buttonMargin.Width - this._buttonCancel.Width;&lt;br&gt;this._buttonCancel.Location.Y =&lt;br&gt;this.ClientRectangle.Bottom - buttonMargin.Height - this._buttonCancel.Height;&lt;br&gt;&lt;br&gt;this._buttonOK.Location.X = this._buttonCancel.Location.X - buttonMargin.Width - this._buttonOK.Width;&lt;br&gt;this._buttonOK.Location.Y = this.ClientRectangle.Bottom - buttonMargin.Height - this._buttonOK.Height;&lt;br&gt;</description></item><item><title>re: Clearest code challenge</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx#93311</link><pubDate>Sat, 20 Mar 2004 21:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:93311</guid><dc:creator>Panos Theofanopoulos</dc:creator><description>protected override void OnSizeChanged(EventArgs e) {&lt;br&gt;base.OnSizeChanged (e);&lt;br&gt;//instead of ctor put your code with layout logic here&lt;br&gt;}&lt;br&gt;&lt;br&gt;btw why the heck VS auto completes using base.OnSizeChanged (e);&lt;br&gt;with a space after the method ?&lt;br&gt;nobody writes this way, not even MS :)&lt;br&gt;</description></item><item><title>re: Clearest code challenge</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx#93336</link><pubDate>Sun, 21 Mar 2004 00:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:93336</guid><dc:creator>RichB</dc:creator><description>Isn't the Location X and Y immutable? I thought you had to create a new Point() class every time. Apart from that, my code would take the same form as DarthPedro's code.</description></item><item><title>re: Clearest code challenge</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx#93363</link><pubDate>Sun, 21 Mar 2004 02:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:93363</guid><dc:creator>Jay Bazuzi [MS]</dc:creator><description>Rich is right that the Location property is immutable, so you can't modify X &amp;amp; Y directly &amp;amp; must create a new object to replace it.&lt;br&gt;&lt;br&gt;I'm assuming that correctness isn't the hard part here.  I assume that most developers can solve the problem of placing the controls correctly.  The challenge is *clarity*.</description></item><item><title>re: Clearest code challenge</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx#93370</link><pubDate>Sun, 21 Mar 2004 03:09:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:93370</guid><dc:creator>Jay Bazuzi [MS]</dc:creator><description>Panos: In Whidbey we've implemented a powerful &amp;amp; flexible formatting engine.  There is an option for this exact case.  (At one point we had 90 options!)&lt;br&gt;&lt;br&gt;It turns out that any time you say &amp;quot;No one formats there code like XXX&amp;quot;, you'll hear from someone who does.  For example, *I* like a space between the method name and the open paren.</description></item><item><title>re: Clearest code challenge</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx#93387</link><pubDate>Sun, 21 Mar 2004 05:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:93387</guid><dc:creator>Thomas Eyde</dc:creator><description>int margin = 12;&lt;br&gt;&lt;br&gt;ControlMover okMover = new ControlMover(_buttonOK, this.ClientSize, margin);&lt;br&gt;okMover.MoveLeft();&lt;br&gt;okMover.MoveUp();&lt;br&gt;&lt;br&gt;ControlMover cancelMover = new ControlMover(_buttonCancel, _buttonOK.Location, margin);&lt;br&gt;cancelMover.MoveLeft();&lt;br&gt;&lt;br&gt;class ControlMover&lt;br&gt;{&lt;br&gt;	Control _control;&lt;br&gt;	int _margin;&lt;br&gt;&lt;br&gt;	public ControlMover(Control c, Point location, int margin)&lt;br&gt;	{&lt;br&gt;		_margin = margin;&lt;br&gt;		_control = c;&lt;br&gt;		_control.Location = location;&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	public ControlMover(Control c, Size location, int margin)&lt;br&gt;		: this (c, new Point(location), margin)&lt;br&gt;	{&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	public void MoveLeft(int delta)&lt;br&gt;	{&lt;br&gt;		_control.Location = Offset(- delta - _margin, 0);&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	Point Offset(int deltaX, int deltaY)&lt;br&gt;	{&lt;br&gt;		Point location = _control.Location;&lt;br&gt;		location.Offset(deltaX, deltaY);&lt;br&gt;		return location;&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	public void MoveLeft()&lt;br&gt;	{&lt;br&gt;		MoveLeft(_control.Width);&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	public void MoveUp(int delta)&lt;br&gt;	{&lt;br&gt;		_control.Location = Offset(0, - delta - _margin);&lt;br&gt;	}&lt;br&gt;&lt;br&gt;	public void MoveUp()&lt;br&gt;	{&lt;br&gt;		MoveUp(_control.Height);&lt;br&gt;	}&lt;br&gt;}&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Clearest code challenge</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx#93495</link><pubDate>Sun, 21 Mar 2004 16:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:93495</guid><dc:creator>pin17931</dc:creator><description>private const int Margin = 12;&lt;br&gt;&lt;br&gt;int x = ClientRectangle.Right - Margin;&lt;br&gt;int y = ClientRectangle.Bottom + Margin + _buttonCancel.Height;&lt;br&gt;&lt;br&gt;this._buttonCancel = New Point(x,y)&lt;br&gt;&lt;br&gt;x -= buttonCancel.Width - Margin;&lt;br&gt;this._buttonOK = new Point(x,y)</description></item><item><title>re: Clearest code challenge</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx#93505</link><pubDate>Sun, 21 Mar 2004 17:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:93505</guid><dc:creator>Tene</dc:creator><description>// put the Cancel button in the lower right corner&lt;br&gt;&lt;br&gt;// put the Ok button at the left of the Cancel button&lt;br&gt;&lt;br&gt;From that, no matter how crap the code is, if the developer can read a comment, he'll be able to get the idea beyond the code. And unless the dev made the exact opposite challenge anyone should be even able to find the code clear.&lt;br&gt;&lt;br&gt;&lt;br&gt;By the way: I won't put the code in OnSizeChanged, I'll simply use what winforms give us: anchoring.</description></item><item><title>// blue cheese </title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx#94068</link><pubDate>Mon, 22 Mar 2004 22:37:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:94068</guid><dc:creator>jaybaz_MS's WebLog</dc:creator><description /></item><item><title>// blue cheese </title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx#94069</link><pubDate>Mon, 22 Mar 2004 22:37:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:94069</guid><dc:creator>jaybaz_MS's WebLog</dc:creator><description /></item><item><title>YetAnotherAttempt</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx#95431</link><pubDate>Wed, 24 Mar 2004 18:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:95431</guid><dc:creator>Louis Zelus</dc:creator><description>    Private Sub JayBazExample_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load&lt;br&gt;        _buttonCancel.PositionBottomRight(12, 12)&lt;br&gt;        _buttonOK.PositionLeftOf(_buttonCancel, 12)&lt;br&gt;    End Sub&lt;br&gt;End Class&lt;br&gt;&lt;br&gt;Public Class PositionalButton&lt;br&gt;    Inherits Button&lt;br&gt;&lt;br&gt;    Public Sub PositionBottomRight(ByVal VerticalPadding As Int32, ByVal HorizontalPadding As Int32)&lt;br&gt;        Top = Me.Parent.ClientSize.Height - Me.Height - VerticalPadding&lt;br&gt;        Left = Me.Parent.ClientSize.Width - Me.Width - HorizontalPadding&lt;br&gt;    End Sub&lt;br&gt;&lt;br&gt;    Public Sub PositionLeftOf(ByVal Target As Button, ByVal VerticalPadding As Int32)&lt;br&gt;        Top = Target.Top&lt;br&gt;        Left = Target.Left - Me.Width - VerticalPadding&lt;br&gt;    End Sub&lt;br&gt;&lt;br&gt;End Class</description></item><item><title>re: Clearest code challenge</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx#95576</link><pubDate>Wed, 24 Mar 2004 22:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:95576</guid><dc:creator>Alfred Gary Myers Jr.</dc:creator><description>_buttonCancel.Top = ClientSize.Height - _buttonCancel.Height - 12;&lt;br&gt;_buttonCancel.Left = ClientSize.Width - _buttonCancel.Width - 12;&lt;br&gt;&lt;br&gt;_buttonOK.Top = _buttonCancel.Top;&lt;br&gt;_buttonOK.Left = _buttonCancel.Left - _buttonOK.Width - 12;&lt;br&gt;</description></item><item><title>re: Clearest code challenge</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx#95579</link><pubDate>Wed, 24 Mar 2004 22:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:95579</guid><dc:creator>Alfred Gary Myers Jr.</dc:creator><description>_buttonCancel.Location = new Point(ClientSize.Width - _buttonCancel.Width - 12, ClientSize.Height - _buttonCancel.Height - 12);&lt;br&gt;_buttonOK.Location = new Point(_buttonCancel.Left - _buttonOK.Width - 12, _buttonCancel.Top);&lt;br&gt;</description></item><item><title>re: Clearest code challenge</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx#96122</link><pubDate>Thu, 25 Mar 2004 16:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:96122</guid><dc:creator>Michal Chaniewski</dc:creator><description>For me the clearest solution is simple&lt;br&gt;&lt;br&gt;private void PlaceButtons()&lt;br&gt;{&lt;br&gt;    const int BUTTON_MARGIN = 12;&lt;br&gt;&lt;br&gt;    _buttonCancel.Location = new System.Drawing.Point(&lt;br&gt;        this.ClientRectangle.Width - _buttonCancel.Width - BUTTON_MARGIN, &lt;br&gt;        this.ClientRectangle.Height - _buttonCancel.Height - BUTTON_MARGIN);&lt;br&gt;    _buttonOK.Location = new System.Drawing.Point(&lt;br&gt;        this.ClientRectangle.Width - _buttonCancel.Width - _buttonOK.Width - 2*BUTTON_MARGIN, &lt;br&gt;        this.ClientRectangle.Height - _buttonOK.Height - BUTTON_MARGIN);&lt;br&gt;&lt;br&gt;    _buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;&lt;br&gt;    _buttonOK.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;&lt;br&gt;}</description></item><item><title>Comments on an Answer to a Clearest Code Challenge</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx#97190</link><pubDate>Sat, 27 Mar 2004 04:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:97190</guid><dc:creator>the1's WebLog</dc:creator><description /></item><item><title>Comments on an Answer to a Clearest Code Challenge</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx#97273</link><pubDate>Sat, 27 Mar 2004 08:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:97273</guid><dc:creator>the1's WebLog</dc:creator><description /></item><item><title> jaybaz MS WebLog Clearest code challenge | Green Tea Fat Burner</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/03/20/93236.aspx#9717853</link><pubDate>Tue, 09 Jun 2009 22:32:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9717853</guid><dc:creator> jaybaz MS WebLog Clearest code challenge | Green Tea Fat Burner</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://greenteafatburner.info/story.php?id=3736"&gt;http://greenteafatburner.info/story.php?id=3736&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>