{"id":23,"date":"2011-05-21T14:13:08","date_gmt":"2011-05-21T14:13:08","guid":{"rendered":"http:\/\/devnot.wordpress.com\/?p=23"},"modified":"2011-05-21T14:13:08","modified_gmt":"2011-05-21T14:13:08","slug":"the-paint-event-and-scrollable-panels","status":"publish","type":"post","link":"https:\/\/thomas-jansen.eu\/?p=23","title":{"rendered":"Scrollable panels and the Paint event."},"content":{"rendered":"<p>When a panel has scrollbars &#8216;default&#8217; drawing on the DC does not\u00a0 work correctly when the upper-left is not at 0,0.\u00a0 Graphics functions draw on the current client area, even when scrolled the upper-left posotion of the client area is still at 0,0.<\/p>\n<p>Use the function <em>TranslateTransform<\/em> to offset the coordinates.<\/p>\n<p><strong>Example<br \/>\n<\/strong><\/p>\n<pre>private void dc_Paint(object sender, PaintEventArgs e)\n{\n   e.Graphics.TranslateTransform(dc.AutoScrollPosition.X, dc.AutoScrollPosition.Y);\n   \/\/0,0 is now relative to the total scrollable area, not the visible part (client area).\n}<\/pre>\n<p><strong>Notes:<\/strong><\/p>\n<p>Although this will work great for simple drawing and unnecessary drawing is limited (being clipped ), some form of optimization would speed things up considerably.<\/p>\n<p>To setup a larger DC size as visible set the properties <em>AutoScroll<\/em> to\u00a0 true and the property <em>AutoScrollMinSize<\/em> to a size larger then the visible area.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When a panel has scrollbars &#8216;default&#8217; drawing on the DC does not\u00a0 work correctly when the upper-left is not at 0,0.\u00a0 Graphics functions draw on the current client area, even when scrolled the upper-left posotion of the client area is still at 0,0. Use the function TranslateTransform to offset the coordinates. Example private void dc_Paint(object [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[52,80,88],"class_list":["post-23","post","type-post","status-publish","format-standard","hentry","category-c","tag-paint","tag-translatetransform","tag-wrong-offset"],"_links":{"self":[{"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/posts\/23","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=23"}],"version-history":[{"count":0,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/posts\/23\/revisions"}],"wp:attachment":[{"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}