Vanguard Against Confusion

Feb 13 2008

Sharing Menu Items between ToolStrips on a Windows Form

So, you may have found yourself building a nice user-friendly, somewhat complicated Windows Forms application, that had lots of drop-down menus and right click context menus, and what not.. You may have naively assumed that you could *share* your menu items, so that you have a consistent set of options, icons, and more importantly event handlers for a particular menu item or set of menu items.


Well, I did… I had a Tools drop-down menu with some basic functions that I wanted to also be accessible from a right-click content menu on a treeview. Redundant? Sure… Convenient? Definately.

There’s a little annoying detail that says that a ToolStripMenuItem can’t be “owned” by more than one ToolStrip. In other words, it can only be in one place at a time. So, when you do something like this:

toolsToolStripMenuItem.DropDownItems.Add(myMenuItem);
treeNodeContextToolStrip.Items.Add(myMenuItem);

The menu item in question suddenly disappears from the tools menu, and appears in the content menu… Hmm…

So, in order to share the menu item, I came up with this hackish solution….I handled the Opening event for the two menu strips and in each one, “took ownership” of the menuitem. So, through sleight-of-hand it seems to exist in one place at a time. We can only get away with this because, ToolStrips, being modal, only show one at a time.

So, here’s a simple sample:

Hot-Swap Menu Item Sample


private void treeNodeContextMenuStrip_Opening(object sender, CancelEventArgs e)
{
treeNodeContextMenuStrip.Items.Insert(3, myToolStripMenuItem);
}

private void toolsToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
{
this.toolsToolStripMenuItem.DropDownItems.Insert(5, this.myToolStripMenuItem);
}

  /   Source: vanguard-against-confusion.blogspot.com

#ContentMenuStrip  #hackish  #Windows  #Forms  #ToolStrip  #ToolStripMenuItem  #.NET 
Feb 08 2007

vista sidebar on XP 2

Well, I was very excited about getting the Vista sidebar to work on XP, until I started playing with the Gadgets.

It turns out the patched version of the Sidebar executable is from a early beta version of Vista. The unfortunate point about that, is that the Gadgets that work with the XP version are vastly different than the Gadgets for the released version of Vista. That means all the gadgets that you can download don’t work with the XP version. It also means that all the information about developing Gadgets for the Sidebar is relevant to the Vista version, not the XP version.

To detail some of the differences:

In the early release, Gadgets are not even called Gadgets, they are called Parts. Parts and Gadgets are very similar, in that they both are a zip file containing what amounts to a mini-webpage which is loaded and interpreted by the Sidebar.

In the XP version, a Part is a zip file with the extension changed to “.part”, in Vista the extension is “.gadget”. In XP, the directory where those files are stored is %userdir%\Parts, in Vista it’s %userdir%\AppData\Local\Microsoft\Windows Sidebar\Gadgets.

Parts require a Manifest.XML file, while Gadgets require a Gadget.xml file. The contents of those files, while containing nearly the same data, use different names for all the tags, making them not compatible.

Beyond that there are a number of other subtle differences, as well as a generally limited set of functionality in the XP version, as compared to the released Vista version.

So, that poses a question? Considering the large amount of people who aren’t interested in upgrading to Vista, due to performance or cost issues, or just not wanting to uproot and start again, is it worth my time to develop for this patched version of the Vista sidebar? Is there a substantial user-base that would benefit from having more cool Gadgets, I mean Parts, to run in their XP Patched Vista Beta Sidebar?

Perhaps that’s a bigger niche than one would initially imagine.

Well, until I have an install of Vista to run the release version, providing a development environment for generating good Gadgets, I may just amuse myself with by playing with potentially pointless Parts.

  /   Source: vanguard-against-confusion.blogspot.com

#Gadgets  #Sidebar  #Vista  #Windows  #XP  #Parts 
+

vista sidebar on XP

So, I was perusing codeproject.com and I came across their current Vista Gadgets Competition. Well, this sparked my interest, not because I am interested in prizes, but because until now, I hadn’t heard of Gadgets, or the Vista Sidebar, or really much about Vista at all.

The reason for this is that, I, being slightly conservative regarding willy-nilly-ly installing new OSes as soon as they are available, choose to upgrade by force, only when absolutely unable to do otherwise. That means, I’m running Windows XP. So what is a developer to do now that his interest is piqued? Install Vista so I can play with Gadgets and the mystical sidebar? No! I, of course, choose to google up a nice patched version of sidebar.exe that can run on XP!


Woohoo! I’m excited to say, that this not only works, but works without a hitch. I was able to install and run the Vista Sidebar on XP in mere moments. And that also means I can fiddle with widgets, oops I mean Gadgets. ;)


See my next few posts for more information about Gadgets… But before you do, download the XP version of Windows Sidebar so you can join in the fun too!


Links and knowledge courtesy of MSTN and their article about this, which I found out about by reading this blog post on My Digital Life.

  /   Source: vanguard-against-confusion.blogspot.com

#Gadgets  #Sidebar  #Vista  #Windows  #XP  #widgets  #My Digital Life  #MSTN  #codeproject.com  #competition 
Page 1 of 1