<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>GuiProf</title>
	<link>http://www.guiprof.com</link>
	<description>COVERAGE PROFILER FOR GUI</description>
	<pubDate>Mon, 22 Dec 2008 20:03:10 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
	<language>en</language>
			<item>
		<title>Context-Sensitive Help for Toolstrip Items</title>
		<link>http://www.guiprof.com/?p=13</link>
		<comments>http://www.guiprof.com/?p=13#comments</comments>
		<pubDate>Fri, 27 Jun 2008 13:11:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.NET development]]></category>

		<category><![CDATA[context help]]></category>

		<category><![CDATA[context sensitive help]]></category>

		<category><![CDATA[tool strip]]></category>

		<category><![CDATA[tool strip item]]></category>

		<category><![CDATA[ToolStrip]]></category>

		<category><![CDATA[ToolStripItem]]></category>

		<guid isPermaLink="false">http://www.guiprof.com/?p=13</guid>
		<description><![CDATA[Context-Sensitive Help for Toolstrip Items
Windows Forms library in .NET Framework has great support for context sensitive help. You can assign a help topic for each control in your program. This topic will be shown automatically when you press F1 provided that the control has focus.
A problem arises when you try to do this for ToolStrip [...]]]></description>
			<content:encoded><![CDATA[<h1>Context-Sensitive Help for Toolstrip Items</h1>
<p>Windows Forms library in .NET Framework has great support for context sensitive help. You can assign a help topic for each control in your program. This topic will be shown automatically when you press F1 provided that the control has focus.</p>
<p>A problem arises when you try to do this for ToolStrip items, such as ToolStripButton or ToolStripComboBox. These classes are not controls, they are not derived from Control but from ToolStripItem class. You will need some tricks to make context-sensitive help work with these objects.</p>
<p>A simple case are the classes derived from ToolStripControlHost, e.g. ToolStripComboBox. They create a control to draw themselves. So, we can just bind this control to a help topic, as shown in the following code snippet:</p>
<pre>
helpProvider1.SetHelpKeyword(toolStripComboBox1.Control, "Chapter_2.htm");
helpProvider1.SetHelpNavigator(toolStripComboBox1.Control, HelpNavigator.Topic);</pre>
<p>If you want to bind context-sensitive help to other ToolStripItems, e.g. to the ToolStripButton, you&#8217;ll need a little more work. First, you will need a custom HelpProvider:</p>
<pre>
class CustomHelpProvider : HelpProvider
{
    public override string GetHelpKeyword(Control ctl)
    {
        ToolStrip ts = ctl as ToolStrip;
        if (ts != null) {
            foreach (ToolStripItem item in ts.Items) {
                if (item.Selected) {
                    string keyword = item.Tag as string;
                    if (keyword != null)
                        return keyword;
                }
            }
        }
        return base.GetHelpKeyword(ctl);
    }
}</pre>
<p>        CustomHelpProvider looks if a ToolStripItem has focus (Selected property). If it&#8217;s the case, it uses its Tag property to get the help keyword. Now we just have to set up the ToolStrip and its items to work with our help provider:</p>
<pre>
// Register the tool strip at the help provider with an empty keyword.
helpProvider1.SetHelpKeyword(toolStrip1, "");
helpProvider1.SetHelpNavigator(toolStrip1, HelpNavigator.Topic);

// Set help keywords for the toolstrip buttons using Tag property.
toolStripButton1.Tag = "Chapter_3.htm";
toolStripButton2.Tag = "Chapter_4.htm";
toolStripButton3.Tag = "Chapter_5.htm";</pre>
<p>That&#8217;s it, now the ToolStripButtons have context-sensitive help.</p>
<p>As a further improvement, you may wish to derive your own class from ToolStripButton. This class will have a property for the help keyword instead of using Tag property.</p</p>
<p>By the way, I&#8217;ve managed to set focus to a ToolStipButton only if there is e.g. a ToolStripComboBox on the toolstrip. I can select the combobox with the mouse and than move focus to a ToolStripButton with the TAB key. If somebody knows a keyboard shortcut for navigating to and in the toolstrip, let me know.</p>
<p>You can download the full source code with a Visual Studio project and a sample help file <a href="http://www.guiprof.com/wp-content/uploads/2008/06/toolstriphelp.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guiprof.com/?feed=rss2&amp;p=13</wfw:commentRss>
		</item>
	</channel>
</rss>
