{"id":58,"date":"2011-09-12T19:39:08","date_gmt":"2011-09-12T21:39:08","guid":{"rendered":"http:\/\/blog.iordanov.info\/?p=58"},"modified":"2011-09-12T19:50:13","modified_gmt":"2011-09-12T21:50:13","slug":"c-tablelayoutpanel-and-and-mouse-scroll","status":"publish","type":"post","link":"https:\/\/blog.iordanov.info\/?p=58","title":{"rendered":"C# TableLayoutPanel and and Mouse Scroll."},"content":{"rendered":"<dl class=\"wp-caption alignleft\" style=\"width: 160px;\">\n<dt class=\"wp-caption-dt\"><a href=\"https:\/\/blog.iordanov.info\/wp-content\/uploads\/2011\/09\/TableLayoutPanelTest.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-thumbnail wp-image-68\" title=\"TableLayoutPanel and Mouse Scroll\" src=\"https:\/\/blog.iordanov.info\/wp-content\/uploads\/2011\/09\/TableLayoutPanelTest-e1315863660809.png\" alt=\"\" width=\"150\" height=\"123\" \/><\/a><\/dt>\n<\/dl>\n<p>I have a simple problem with my windows application developed in .NET. I have a\u00a0<em>TableLayoutPanel<\/em>\u00a0which contains a\u00a0<em>RichTextBox<\/em>control. I am not able to\u00a0<strong>scroll<\/strong>\u00a0the\u00a0<em>TableLayoutPanel<\/em>.<\/p>\n<p>I made a search in Google and found that many people has the same problem like\u00a0<sup id=\"cite_ref-Info2007_0-0\"><a href=\"http:\/\/infovish.wordpress.com\/2007\/01\/03\/problem-with-scrolling-with-tablelayoutpanel\/\">[1]<\/a><\/sup>\u00a0<sup id=\"cite_ref-problem2_1-0\"><a href=\"http:\/\/stackoverflow.com\/questions\/5803892\/mouse-scroll-on-tablelayoutpanel-breaks-layout\">[2]<\/a><\/sup>\u00a0The idea for to resolving this issue cams from\u00a0<sup id=\"cite_ref-Info2007_0-1\"><a href=\"http:\/\/infovish.wordpress.com\/2007\/01\/03\/problem-with-scrolling-with-tablelayoutpanel\/\">[1]<\/a><\/sup>\u00a0blog.<\/p>\n<p>In fact the Panel can&#8217;t have the focus itself, only an item placed inside the panel can have the focus. The panel will only receive the MouseWheel event once something is placed inside it and that thing has the focus. Simply hoevering over the panel and moving the mouse wheel will send the event to the form, not to the TableLayoutPanel.<\/p>\n<p>That&#8217;s I implemented a MouseWheel Event in the RichTextBox placed inside the panel. In the implementation I Update the drawing of the TableLayoutPanel (parent) based upon the mouse wheel scrolling.<\/p>\n<pre>this.richTextBox.MouseWheel +=\r\n         new System.Windows.Forms.MouseEventHandler(richTextBox_MouseWheel);<\/pre>\n<pre>void richTextBox_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)\r\n{\r\n    if (!(this.Parent == null) &amp;&amp;\r\n         (this.Parent.GetType() == typeof(TableLayoutPanel)))\r\n    {\r\n\r\n        TableLayoutPanel parentPanel = (TableLayoutPanel)this.Parent;\r\n        if (e.Delta != 0)\r\n        {\r\n            int newVerticalScrollValue = parentPanel.VerticalScroll.Value + e.Delta;\r\n            if (newVerticalScrollValue &gt; parentPanel.VerticalScroll.Maximum)\r\n                newVerticalScrollValue = parentPanel.VerticalScroll.Maximum;\r\n\r\n            if (newVerticalScrollValue &lt; parentPanel.VerticalScroll.Minimum)\r\n                newVerticalScrollValue = parentPanel.VerticalScroll.Minimum;\r\n\r\n            parentPanel.VerticalScroll.Enabled = true;\r\n            parentPanel.VerticalScroll.Value = newVerticalScrollValue;\r\n        }\r\n    }\r\n}<\/pre>\n<p>This solve the problem!<\/p>\n<h2>Excample<\/h2>\n<p>TableLayoutPanelTest<\/p>\n<h2>References<\/h2>\n<ol>\n<li id=\"cite_note-Info2007-0\"><a title=\"http:\/\/stackoverflow.com\/users\/639956\/soul-reaver\" href=\"http:\/\/stackoverflow.com\/users\/639956\/soul-reaver\" rel=\"nofollow\">Soul Reaver<\/a>\u00a0,<a title=\"http:\/\/infovish.wordpress.com\/2007\/01\/03\/problem-with-scrolling-with-tablelayoutpanel\/\" href=\"http:\/\/infovish.wordpress.com\/2007\/01\/03\/problem-with-scrolling-with-tablelayoutpanel\/\" rel=\"nofollow\">Problem with scrolling with TableLayoutPanel<\/a>,Jan 03, 2007<\/li>\n<li id=\"cite_note-problem2-1\"><a title=\"http:\/\/en.gravatar.com\/infovish\" href=\"http:\/\/en.gravatar.com\/infovish\" rel=\"nofollow\">Jabber Infovish<\/a>\u00a0,<a title=\"http:\/\/stackoverflow.com\/questions\/5803892\/mouse-scroll-on-tablelayoutpanel-breaks-layout\" href=\"http:\/\/stackoverflow.com\/questions\/5803892\/mouse-scroll-on-tablelayoutpanel-breaks-layout\" rel=\"nofollow\">Mouse scroll on TableLayoutPanel breaks layout.<\/a>,April 27, 2011<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>I have a simple problem with my windows application developed in .NET. I have a\u00a0TableLayoutPanel\u00a0which contains a\u00a0RichTextBoxcontrol. I am not able to\u00a0scroll\u00a0the\u00a0TableLayoutPanel. I made a search in Google and found that many people has the same problem like\u00a0[1]\u00a0[2]\u00a0The idea for &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/blog.iordanov.info\/?p=58\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":68,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[5],"tags":[6,7,30,10,11,9],"class_list":["post-58","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","tag-net","tag-c","tag-dotnet","tag-mousewheel","tag-scroll","tag-tablelayoutpanel"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/p3jsZJ-W","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_featured_media_url":"https:\/\/blog.iordanov.info\/wp-content\/uploads\/2011\/09\/TableLayoutPanelTest-e1315863660809.png","_links":{"self":[{"href":"https:\/\/blog.iordanov.info\/index.php?rest_route=\/wp\/v2\/posts\/58","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.iordanov.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.iordanov.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.iordanov.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.iordanov.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=58"}],"version-history":[{"count":15,"href":"https:\/\/blog.iordanov.info\/index.php?rest_route=\/wp\/v2\/posts\/58\/revisions"}],"predecessor-version":[{"id":70,"href":"https:\/\/blog.iordanov.info\/index.php?rest_route=\/wp\/v2\/posts\/58\/revisions\/70"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.iordanov.info\/index.php?rest_route=\/wp\/v2\/media\/68"}],"wp:attachment":[{"href":"https:\/\/blog.iordanov.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iordanov.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iordanov.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}