﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>A1VBCode Forums / Visual Basic (VB 4/5/6) / General Visual Basic  / Remove Focus From Only CommandButton On Form? / Latest Posts</title><generator>InstantForum.NET v4.1.1</generator><description>A1VBCode Forums</description><link>http://www.a1vbcode.com/vbforums/</link><webMaster>forums@a1vbcode.com</webMaster><lastBuildDate>Sun, 12 Oct 2008 10:30:19 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Remove Focus From Only CommandButton On Form?</title><link>http://www.a1vbcode.com/vbforums/Topic24928-3-1.aspx</link><description>&lt;div class="Quote"&gt;&lt;b&gt;Keithuk (5/15/2008)&lt;/b&gt;&lt;hr noshade size="1" class="hr"&gt;Apart from the Shape shown how many other controls are there on the Form?&lt;/div&gt; &lt;P&gt;Keith, like I said, only the CommandButton. That's why Mark's code doesn't quite answer the question. This code isn't part of a project. It's simply an issue that I was aware of but often wondered if there was a quick work around that I was missing. This issue won't manifest itself if there's another control (not a CommandButton or ListBox) on the Form because they won't overide the KeyPreview property of the Form. I was not surprised that the links you posted point to API,s as solution though. &lt;/P&gt;&lt;P&gt;I will continue to put my graphics in a PicBox instead of the Form because it eliminates this whole issue entirely as I illuded to in this post.&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.a1vbcode.com/vbforums/FindPost24875.aspx"&gt;http://www.a1vbcode.com/vbforums/FindPost24875.aspx&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It was this thread that got me thinking about this issue in the first place and why I told Jenna not to use the Form.&lt;/P&gt;&lt;P&gt;Thanks for the effort guys. </description><pubDate>Thu, 15 May 2008 22:36:10 GMT</pubDate><dc:creator>CDRIVE</dc:creator></item><item><title>RE: Remove Focus From Only CommandButton On Form?</title><link>http://www.a1vbcode.com/vbforums/Topic24928-3-1.aspx</link><description>Apart from the Shape shown how many other controls are there on the Form?&lt;P&gt;You could always set the Command button &lt;STRONG&gt;TabStop&lt;/STRONG&gt; to False. That way you would have to physically press the button to make it work.&lt;/P&gt;&lt;P&gt;I've just put a Shape and Command button (with the TabStop to False) on a Form with Me.KeyPreview = True and the Shape wouldn't move. I put a PictureBox on the Form then it would move. If I made the PictureBox not visible it wouldn't move again, strange. Now a Shape doesn't have a TabStop so the tab key wouldn't work. &lt;img align="absmiddle" src="http://www.a1vbcode.com/vbforums/Skins/Classic/Images/EmotIcons/Wink.gif" border="0" title="Wink"&gt;&lt;P&gt;Ok a search on VBforums.&lt;P&gt;&lt;a href="http://www.vbforums.com/showpost.php?p=1910210&amp;amp;postcount=19" target="_blank" class="SmlLinks"&gt;Focus Rect&lt;/a&gt;&lt;P&gt;&lt;a href="http://www.vbforums.com/showpost.php?p=2006985&amp;amp;postcount=8" target="_blank" class="SmlLinks"&gt;How to prevent Command btn from taking focus?&lt;/a&gt;&lt;P&gt;&lt;a href="http://www.vbforums.com/showthread.php?t=224592&amp;amp;" target="_blank" class="SmlLinks"&gt;Focus Of Command Buttons&lt;/a&gt;</description><pubDate>Thu, 15 May 2008 17:39:53 GMT</pubDate><dc:creator>Keithuk</dc:creator></item><item><title>RE: Remove Focus From Only CommandButton On Form?</title><link>http://www.a1vbcode.com/vbforums/Topic24928-3-1.aspx</link><description>This is a real hack and it probably falls into the don't respond with the obvious category but here you go.&lt;BR&gt;&lt;DIV style="BORDER-RIGHT: #000000 3px solid; PADDING-RIGHT: 25px; BORDER-TOP: #000000 3px solid; PADDING-LEFT: 25px; BACKGROUND-IMAGE: none; PADDING-BOTTOM: 25px; BORDER-LEFT: #000000 3px solid; PADDING-TOP: 25px; BORDER-BOTTOM: #000000 3px solid; BACKGROUND-COLOR: #cccccc"&gt;&lt;FONT color=#0000cc&gt;Option&lt;/FONT&gt; &lt;FONT color=#0000cc&gt;Explicit&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000cc&gt;Private&lt;/FONT&gt; &lt;FONT color=#0000cc&gt;Sub&lt;/FONT&gt; Command1_Click()&lt;BR&gt;    MsgBox "I work!" &amp;amp; vbCrLf &amp;amp; "Now press the &lt;FONT color=#0000cc&gt;left&lt;/FONT&gt; arrow key."&lt;BR&gt;    Picture1.SetFocus&lt;BR&gt;&lt;FONT color=#0000cc&gt;End&lt;/FONT&gt; &lt;FONT color=#0000cc&gt;Sub&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000cc&gt;Private&lt;/FONT&gt; &lt;FONT color=#0000cc&gt;Sub&lt;/FONT&gt; Form_KeyDown(KeyCode &lt;FONT color=#0000cc&gt;As&lt;/FONT&gt; &lt;FONT color=#0000cc&gt;Integer&lt;/FONT&gt;, Shift &lt;FONT color=#0000cc&gt;As&lt;/FONT&gt; &lt;FONT color=#0000cc&gt;Integer&lt;/FONT&gt;)&lt;BR&gt;   &lt;FONT color=#0000cc&gt;If&lt;/FONT&gt; KeyCode = vbKeyLeft &lt;FONT color=#0000cc&gt;Then&lt;/FONT&gt;&lt;BR&gt;      Shape1.Left = Shape1.Left - 100&lt;BR&gt;   &lt;FONT color=#0000cc&gt;End&lt;/FONT&gt; &lt;FONT color=#0000cc&gt;If&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000cc&gt;End&lt;/FONT&gt; &lt;FONT color=#0000cc&gt;Sub&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000cc&gt;Private&lt;/FONT&gt; &lt;FONT color=#0000cc&gt;Sub&lt;/FONT&gt; Form_Load()&lt;BR&gt;    Picture1.Move -100, 0, 1, 1&lt;BR&gt;    Me.Show&lt;BR&gt;&lt;FONT color=#0000cc&gt;End&lt;/FONT&gt; &lt;FONT color=#0000cc&gt;Sub&lt;/FONT&gt;&lt;BR&gt;&lt;/DIV&gt;</description><pubDate>Thu, 15 May 2008 14:43:35 GMT</pubDate><dc:creator>Mark</dc:creator></item><item><title>Remove Focus From Only CommandButton On Form?</title><link>http://www.a1vbcode.com/vbforums/Topic24928-3-1.aspx</link><description>I think we all know that &lt;STRONG&gt;KeyPreview&lt;/STRONG&gt; will do nothing for you if the only control on your Form is a CommandButton. At least as far as KeyCode's for Arrow keys &amp;amp; the Enter Key are concerned. That's why I prefer to put animation code in PictureBox events. My question is, is there an undocumented trick to get the focus off of the CommandButton? Just in case what I'm asking is not clear, refer to this simple code that has the &lt;STRONG&gt;me.KeyPreview=True&lt;/STRONG&gt; but has only a CommandButton on the Form. This code will never fire. Btw, I read the KeyPreview property info in the library and the note at the bottom regarding this issue and it does not mention a work around.&lt;DIV style="BORDER-RIGHT: #000000 3px solid; PADDING-RIGHT: 25px; BORDER-TOP: #000000 3px solid; PADDING-LEFT: 25px; BACKGROUND-IMAGE: none; PADDING-BOTTOM: 25px; BORDER-LEFT: #000000 3px solid; PADDING-TOP: 25px; BORDER-BOTTOM: #000000 3px solid; BACKGROUND-COLOR: #cccccc"&gt;&lt;FONT color=#0000cc&gt;Private&lt;/FONT&gt; &lt;FONT color=#0000cc&gt;Sub&lt;/FONT&gt; Form_KeyDown(KeyCode &lt;FONT color=#0000cc&gt;As&lt;/FONT&gt; &lt;FONT color=#0000cc&gt;Integer&lt;/FONT&gt;, Shift &lt;FONT color=#0000cc&gt;As&lt;/FONT&gt; &lt;FONT color=#0000cc&gt;Integer&lt;/FONT&gt;)&lt;BR&gt;   &lt;FONT color=#0000cc&gt;If&lt;/FONT&gt; KeyCode = vbKeyLeft &lt;FONT color=#0000cc&gt;Then&lt;/FONT&gt;&lt;BR&gt;      Shape1.Left = Shape1.Left - 100&lt;BR&gt;   &lt;FONT color=#0000cc&gt;End&lt;/FONT&gt; &lt;FONT color=#0000cc&gt;If&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000cc&gt;End&lt;/FONT&gt; &lt;FONT color=#0000cc&gt;Sub&lt;/FONT&gt;&lt;BR&gt;&lt;BR&gt;&lt;FONT color=#0000cc&gt;Private&lt;/FONT&gt; &lt;FONT color=#0000cc&gt;Sub&lt;/FONT&gt; Command1_Click()&lt;BR&gt;   &lt;FONT color=#009900&gt;' Do nothing. I'm here just to make a point.&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000cc&gt;End&lt;/FONT&gt; &lt;FONT color=#0000cc&gt;Sub&lt;/FONT&gt;&lt;BR&gt;&lt;/DIV&gt;&lt;P&gt;Please don't respond with the obvious, like "Set the Button's Visible or Enabled property to False".</description><pubDate>Thu, 15 May 2008 13:36:42 GMT</pubDate><dc:creator>CDRIVE</dc:creator></item></channel></rss>