Reordering TabPages Inside TabControl

When using TabControl in my programs, usually there is one thing users always ask for - “let me reorder those tabs”. Since reordering tabs is such a logical operation, one would think that the mighty .NET 2.0 Framework has one. But no luck there. Visual Studio 2008 does have that feature, but framework mortals are not blessed with it.

Since Visual Basic programmers waited for inheritance for far too long, they tend to use it for solving every possible problem (when you have a hammer, all problems look like nails). May I say that here, the same inheritance approach will be used. :)

What we want to do here is to extend the standard TabControl. Inside of it, we are interested in MouseDown, MouseMove and MouseUp events. Some people like to use drag and drop here, but that seems to me like using a bomb to kill a fly.

MouseDown

Upon receiving a MouseDown event, we check if the Left button is used and if TabControl has tab selected. If those requirements are fulfilled, we initialize the SourceTabPage variable. With that, we are ready for further events.

MouseMove

When the mouse is moved, one must check if reordering is in progress. If that is true, we look at what TabPage is under it. If it is not starting one - we have a show.

One of the things we must discover is which TabPage we are hovering over. Since unfortunately, we cannot use some sort of HitText, we must iterate through all TabPages and select one with our coordinates.

After that, we check which side we are hovering. It is only important if you wish to display a different cursor for each side. These two are the ones I use, but you can think of your own schema.

MouseUp

Here, we must know on which side we are since the new location (before or after hovering TabPage) depends on this information. This code is basically the same as the one we use for determining the cursor type. After clearing is done, so is our function.

Conclusion

This extended control offers a good solution to reordering TabPages inside a TabControl. I think that the only thing one may hold against it is updating the order on MouseUp but that decision is made for the sake of speed and code clarity. This way, it is very easy to implement changes through further extending since it uses protected OnMouseX procedures.

There is source code available in both VB.NET and C#. Hope you like it.

P.S.

This is redoing of my Code Project article.

Intellisense 10-4

Illustration

While C#'s IntelliSense was always good, in Visual Studio 2010 they enhanced it even more. When one writes e.g. “reason”, it will also match CloseReason. While this may not seem much, it is gem if you do not remember exact property name.

Small feature that helps a lot.

User With Password Is Needed for Virtual PC's Integrated Services

Illustration

Integration features were always thing you installed first on your new virtual machine. Greatest benefit was seamless mouse movement between host and virtual machine, but there were other thing like clock synchronization and clipboard sharing.

New version of Virtual PC (Windows 7 beta) also offers thing you may noticed on remote desktop - ability to share local resources (direct replacement for old shared folders).

Because Remote Desktop is underlying protocol, in order to share resources, you need to have user with password on your virtual machine. This was problem for me since I often skip this step. Once you try to enable integration features, you are presented with logon screen. It will not accept empty password and there is no obvious way to escape from it.

It took me a while to figure that, once you disable integration features, you can logon. Once I had Windows under control, I have assigned password to user and integration components did like it. Since that password can be remembered automatically, there is no need to enter it manually every time.

Although it is slightly more cumbersome to setup, I do like this Remote Desktop style.

Virtual Disk Management From PowerShell

Illustration

Since my presentation on KulenDayz 2009 is over, I will share here PowerShell scripts for creating and mounting virtual disks under Windows Server 2008 R2. For those who really need it on Windows 7, there is solution with C# dll called from PowerShell (or just use small sample application).

Here are also links to some older post that cover most of what I was speaking about:

If you are C# soul, you may also want to check my WinDays post.

Windows 7 E

Microsoft decided to ship Windows 7 without Internet Explorer 8 for customers inside European Union, Switzerland and Croatia. While this seems similar to “N” versions of Vista, there is small but significant difference - there will be no full version of Windows 7 available in those countries.

For those who wish to read little bit more, there is Microsoft’s statement and European’s Commission reply to it. I will not go too much into politics of this, although initial European Commission proposal of bundling competition’s browsers inside Windows 7 seems highly idiotic to me. Why on earth would anybody accept this?

When error occurs in Firefox (although we all know that Firefox doesn’t crash), who will get support calls? If customer got Firefox with Windows, he will call Microsoft since probably 90% of them will have no idea that Mozzila even exists. When they fail to get an answer, they will be angry at Microsoft since, in their mind, this is Microsoft’s problem. The only winning move is not to play, and that is exactly what Microsoft did by removing IE.

Although I am Croatian MSDN subscriber (thanks Marc), I hope that this decision will not affect me and that I will still be able to download normal version of Windows 7 with IE. I do want Internet Explorer on my computer (although I have Firefox and Chrome also installed).

I also hope that full version and “E” will share same key. Since they are essentially the same, probably nothing in license will forbid installing Windows from full DVD instead from crippled one. I would use this to install Windows on other people’s computers. It saves me time installing all necessary programs and they can download whatever browser they prefer later.

If everything else fails, I hope that I will at least get option to install it via Windows Update (which is conveniently separated from browser since Windows Vista). This will at least allow me to install it with patches.

Final result will be known on August, 22nd.

[2009-06-26: Because of compliance, it seems that upgrade will not be available in “E” version.]

[2009-07-24: Microsoft proposed “ballot screen” selection to European Commission. Internet Explorer would come with Windows 7 and other browsers will be offered for download after installation.]