Click here to Skip to main content
Click here to Skip to main content

Issues & WorkArounds while Migrating Application from VB to C#

, 21 Apr 2009
Rate this:
Please Sign up or sign in to vote.
Issues & WorkArounds while Migrating Application from VB to C#

Introduction

While working on a Migration Project from VB6 to C#, I found some very interesting issues which are inbuilt functionalities existing in VB6 environment but it's very hard to replicate the same kind of functionality in our C# application.

Background

Gradually when we drilled down our application, we found some very interesting kind of issues which are handled in VB6 but not available in our C# Winforms side. Below are some of the issues which I want to share because there might be some other developers who need these kind of workarounds.

  1. In VB if we have two buttons having the same shortcut key, it will handle automatically with the help of Tab Key, while in C# Winforms if we have two buttons having the same shortcut Key, it will work only for the first button.
  2. In Windows MDI Applications, if our button having shortcut Key (Alt + -) ex. button &- , VB6 handled it and works perfectly while in C# MDI Application, it will open the Control Menu on the Top Left corner.
  3. In MDI Applications, if we are using MenuStrip, and we have set some menuItem to its MDIWindowListItem property so that it should show the current activated child forms under this menu item, in VB once any child is opened it takes the caption text to this MenuItem list, even after changing the caption of the child form, it reflects to the MenuItem List (i.e. it refreshes itself to show the current caption of child form). In case of C# MDI Application, we have to handle this feature so that it should show the latest caption of activated child form.

Using the Code

To handle the first two issues, we have our savior ProcessCmdKey, generally in our VB Apps we had only max two buttons having this kind of issue (have the same shortcut Key). So to handle this, I wrote my workaround in this way. Here we have two buttons button1 & button2 having the same shortcut key Alt + A.

 /// <summary>
 /// Handle the Same Shortcut Keys on form.
 /// </summary>
 private const Keys ShortCutKeysWithAlt = Keys.Alt | Keys.A;
 private bool _isFocusOnFirstButton = false;
  protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
  {
     if (keyData == ShortCutKeysWithAlt)
       {
         if (_isFocusOnFirstButton)
           {
              button1.Focus();
              _isFocusOnFirstButton = false;
           }
         else
           {
              button2.Focus();
              _isFocusOnFirstButton = true;
           }
            return true;
       }
     else
       {
          return base.ProcessCmdKey(ref msg, keyData);
       }
  }

Using the same ProcessCmdKey, we can easily handle the second issue. We just need to add a small piece of code.

/// <summary>
/// Handle the Same Shortcut Keys on form.
/// </summary>

private const Keys ShortCutKeysWithAlt = Keys.Alt | Keys.OemMinus;
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    if (keyData == ShortCutKeysWithAlt)
    {
        button.PerformClick();
        return true;
    }
    else
    {
        return base.ProcessCmdKey(ref msg, keyData);
    }
}

To resolve the third issue, we have to add DropDownOpening Event to the Menu Item which is MDIWindowList Item of MenuStrip control. We have rectified one more issue here after if block, the issue was in C# when we open any child form its Caption added in Window Menu and when we close the child form, it leaves a Separator under this Menu Item, which is inbuilt handle by VB Apps. To handle this, we manually have to remove this ToolStripSeperator from the end of menu Item.

/// <summary>
/// mnuWindow_DropDownOpening event
/// </summary>
/// <param name=""sender""></param>
/// <param name=""e""></param>
void mnuWindow_DropDownOpening(object sender, EventArgs e)
{
    if (this.ActiveMdiChild != null)
    {
        Form activeChild = this.ActiveMdiChild;
        ActivateMdiChild(null);
        ActivateMdiChild(activeChild);
    }

    if (mnuWindow.DropDownItems[mnuWindow.DropDownItems.Count - 1] is        
          System.Windows.Forms.ToolStripSeparator)
    {
         mnuWindow.DropDownItems.RemoveAt(mnuWindow.DropDownItems.Count - 1);
    }
}

I will continuously add my experiences while working on this migration project. If someone has experience with the same kind of interesting issues and their workarounds, please share with me.

History

  • 21st April, 2009: Initial post 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

vivekgaur
Technical Lead Aristocrat Technologies India Pvt. Ltd.
India India
I am MCAD certified ,working with Aristocrat Technologies(www.aristocratgaming.com).

Comments and Discussions

 
GeneralMy vote of 1 Pinmemberchangalfgggggggggg14-Oct-10 4:17 
GeneralRe: My vote of 1 PinmemberRob Philpott21-Dec-10 0:44 
Generalgood article PinmemberDonsw19-May-09 4:13 
GeneralRe: good article Pinmembervivekgaur29-Jun-09 23:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 21 Apr 2009
Article Copyright 2009 by vivekgaur
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid