{"id":193,"date":"2008-08-17T21:11:05","date_gmt":"2008-08-17T09:11:05","guid":{"rendered":"https:\/\/www.deltics.co.nz\/blog\/?p=193"},"modified":"2009-08-07T14:56:31","modified_gmt":"2009-08-07T02:56:31","slug":"resizing-a-non-resizable-form","status":"publish","type":"post","link":"https:\/\/www.deltics.co.nz\/blog\/posts\/193\/","title":{"rendered":"Resizing a Non-Resizable Form"},"content":{"rendered":"<span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">[Estimated Reading Time: <\/span> <span class=\"rt-time\">3<\/span> <span class=\"rt-label rt-postfix\">minutes]<\/span><\/span><p>One control that I have not seen in the line-up of new controls in the VCL for Tibur\u00f3n is a size grip.<\/p>\n<p>Most people may not even realise that this control exists, even though it is part of Windows itself and is really quite useful.\u00a0 Fortunately, implementing it ourselves is truly trivial.<\/p>\n<p><!--more--><\/p>\n<h3>What is a Size Grip?<\/h3>\n<p>A size grip is the small triangular control, usually in the lower right hand corner of a window that provides an indication that the window is resizable and is also a grab-point that the user can use to resize the window itself.<\/p>\n<p>You will see one if you place a status-bar control on a resizable form:<\/p>\n<figure style=\"width: 312px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/i0.wp.com\/www.deltics.co.nz\/picture_library\/sizegrip.gif?ssl=1\"><img decoding=\"async\" loading=\"lazy\" title=\"Example of a Size Grip\" src=\"https:\/\/i0.wp.com\/www.deltics.co.nz\/picture_library\/sizegrip.gif?resize=312%2C140&#038;ssl=1\" alt=\"Example of a Size Grip\" width=\"312\" height=\"140\" data-recalc-dims=\"1\" \/><\/a><figcaption class=\"wp-caption-text\">Example of a Size Grip<\/figcaption><\/figure>\n<p>If the form is not resizable, the grip does not appear in the status bar.<\/p>\n<p>But what if I have a form that I want to be sizable, but which does not have a status bar, doesn&#8217;t <span style=\"text-decoration: underline;\">need<\/span> a status bar, and which perhaps in all other respects doesn&#8217;t even look resizable?<\/p>\n<p>Imagine, for example, that I have <a href=\"http:\/\/chrisbensen.blogspot.com\/2008\/07\/tiburn-sneak-peek-project-options.html\" target=\"_blank\">redesigned a dialog box so that it now needs to be resizable<\/a>&#8230;.<\/p>\n<p>If you look at the dialog box shown in that link, you will see that it is resizable but offers no immediately obvious visual cue that this is in fact the case.\u00a0 It clearly doesn&#8217;t need a status bar.<\/p>\n<p>What would be useful in such cases is a way to add a size grip without having to use a status bar.<\/p>\n<p>And this is exactly what a size grip control does for us.<\/p>\n<h3>The Implementation<\/h3>\n<p>As I mentioned, the implementation of such a control is trivial.\u00a0 So trivial that the entire implementation is provided below.\u00a0 No need for a download in this case.<\/p>\n<pre class=\"delphi\">interface\r\n\r\n  uses\r\n    Classes,\r\n    Controls;\r\n\r\n  type\r\n    TSizeGrip = class(TWinControl)\r\n    protected\r\n      procedure CreateParams(var Params: TCreateParams); override;\r\n      procedure CreateWnd; override;\r\n    public\r\n      constructor Create(aOwner: TComponent); override;\r\n    end;\r\n\r\nimplementation\r\n\r\n  uses\r\n    Windows;\r\n\r\n{ TSizeGrip }\r\n\r\n  constructor TSizeGrip.Create(aOwner: TComponent);\r\n  begin\r\n    inherited;\r\n\r\n    ControlStyle := [csOpaque, csFixedWidth, csFixedHeight];\r\n\r\n    Anchors := [akRight, akBottom];\r\n    Cursor  := crSizeNWSE;\r\n    Height  := 11;\r\n    Width   := 11;\r\n  end;\r\n\r\n  procedure TSizeGrip.CreateParams(var Params: TCreateParams);\r\n  begin\r\n    inherited;\r\n    CreateSubClass(Params, 'SCROLLBAR');\r\n    Params.Style := Params.Style or WS_CLIPSIBLINGS or SBS_SIZEGRIP;\r\n  end;\r\n\r\n  procedure TSizeGrip.CreateWnd;\r\n  begin\r\n    inherited;\r\n    Left := Parent.ClientWidth - Width - 1;\r\n    Top  := Parent.ClientHeight - Height - 1;\r\n    SendToBack;\r\n  end;<\/pre>\n<p>As you can see, a size grip is in fact a special form of the built in SCROLLBAR Windows control class.<\/p>\n<p>This code should work in any Win32 version of Delphi.\u00a0 In my case since I use Delphi 7 I use dotted unit names and have it implemented in <strong>Deltics.Controls.SizeGrip<\/strong>.\u00a0 In earlier Delphi versions you will need to use a unit name with no dots.<\/p>\n<p>And yes, we should probably use system metrics to size the control.<\/p>\n<p>The implementation has the control place itself in the lower right hand corner of it&#8217;s parent, and stay there.  But how do we ensure that we only show the control if the form is resizable?<\/p>\n<p>Well, actually, we don&#8217;t need to worry about that.  Simply placing the control on a form <span style=\"text-decoration: underline;\">makes<\/span> the form resizable (via the size grip) even if that form would normally not be resizable.\u00a0 That is, if the user moves their mouse over the size grip it will change to the resizing cursor and they can resize the form by grabbing the control and dragging.<\/p>\n<p>So the user can see that the dialog is resizable <span style=\"text-decoration: underline;\">and<\/span> is provided with the means to resize the form, even if the form has no border at all, such as this one, with border style <strong>bsNone<\/strong>:<\/p>\n<figure style=\"width: 207px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/i0.wp.com\/www.deltics.co.nz\/picture_library\/sizegrip2.gif?ssl=1\"><img decoding=\"async\" loading=\"lazy\" title=\"Resizable, Borderless Form\" src=\"https:\/\/i0.wp.com\/www.deltics.co.nz\/picture_library\/sizegrip2.gif?resize=207%2C111&#038;ssl=1\" alt=\"Resizable, Borderless Form\" width=\"207\" height=\"111\" data-recalc-dims=\"1\" \/><\/a><figcaption class=\"wp-caption-text\">Resizable, Borderless Form<\/figcaption><\/figure>\n<p>Getting this is as easy as adding:<\/p>\n<pre class=\"delphi\">    with TSizeGrip.Create(self) do\r\n      Parent := self;<\/pre>\n<p>To a form <em>constructor<\/em> or <em>OnCreate<\/em> event.<\/p>\n<p>In fact, in my applications I can simply write in any form <em>constructor<\/em> or <em>OnCreate<\/em> event:<\/p>\n<pre class=\"delphi\">    HasSizeGrip := TRUE;<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>Any<\/em><\/span> form.<\/p>\n<p>How is that possible?\u00a0 <strong>HasSizeGrip<\/strong> is not a property of <strong>TForm<\/strong>, so where does it come from?<\/p>\n<p>I&#8217;m saving that for next time.\u00a0 \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">[Estimated Reading Time: <\/span> <span class=\"rt-time\">3<\/span> <span class=\"rt-label rt-postfix\">minutes]<\/span><\/span> One control that I have not seen in the line-up of new controls in the VCL for Tibur\u00f3n is a size grip. Most people may not even realise that this control exists, even though it is part of Windows itself and is really quite useful.\u00a0 Fortunately, implementing it ourselves is truly trivial.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[4],"tags":[292,293,40],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1TKYv-37","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":28,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/28\/","url_meta":{"origin":193,"position":0},"title":"Tiburon Preview","date":"02 Aug 2008","format":false,"excerpt":"A roundup of that part of the Preview I saw of Tiburon - the next release of Delphi from CodeGear.","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":321,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/321\/","url_meta":{"origin":193,"position":1},"title":"Delphi 2009 Trial &#8211; First Impressions","date":"11 Sep 2008","format":false,"excerpt":"I imagine the news has spread like wildfire - the Delphi 2009 Trial Edition is now available for download!\u00a0 I got me one, and these are my initial impressions. 1. The Installation The installer itself is a small downloader stub, so the initial download is very quick.\u00a0 During installation of\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":222,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/222\/","url_meta":{"origin":193,"position":2},"title":"More Deltics.Forms Magic","date":"24 Aug 2008","format":false,"excerpt":"Last time I introduced a bit of skullduggery with my Deltics.Forms unit as a way to easily \"inject\" a new TForm class into my projects.\u00a0 We used this new class to add public property that we could use to add a size grip control to any form. This time we\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":180,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/180\/","url_meta":{"origin":193,"position":3},"title":"Latest Tibur\u00f3n Preview","date":"14 Aug 2008","format":false,"excerpt":"I was a little disappointed that the preview webinar this morning was little more than a re-run of the same content from a little over a week ago, albeit with some downloadable PowerPoint slides this time. It was at least an opportunity for some more Q&A and a couple of\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":89,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/89\/","url_meta":{"origin":193,"position":4},"title":"Tiburon Preview Videos Coming Online","date":"05 Aug 2008","format":false,"excerpt":"The first two canned videos from last weeks preview of Tiburon have appeared on the CDN site.\u00a0 Of the two, one covers some new language features in C++ Builder, but the one of most interest to Delphi developers I think is the one that demonstrates some of the VCL improvements\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":375,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/375\/","url_meta":{"origin":193,"position":5},"title":"Delphi 2009 &#8211; StringPerformance Redux","date":"22 Sep 2008","format":false,"excerpt":"It looks like I may have jumped the gun with my conclusions from the previous exercise to benchmark string performance in Delphi 2009.\u00a0 Following a useful exchange in the comments with Kryvich I corrected a small discrepancy in the tests and made some changes to the performance testing subsystem within\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/delphi2009-stringperformance-chart.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/193"}],"collection":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/comments?post=193"}],"version-history":[{"count":4,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/193\/revisions"}],"predecessor-version":[{"id":472,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/193\/revisions\/472"}],"wp:attachment":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/media?parent=193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/categories?post=193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/tags?post=193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}