VB Migration Partner

KNOWLEDGE BASE - Forms and controls

Previous | Index | Next 

[HOWTO] Move a control over a toolbar at runtime

One of the key differences between the VB6 and VB.NET Toolbar controls is that the former can work as a control container, whereas the latter can’t. (This topic is explained in more detail in this article.) This detail has a consequence on how you move a standard control – for example, a progress bar – over a toolbar. Such an action is typically accomplished under VB6 by means of the following code:

        Set ProgressBar1.Container = Toolbar1
        ProgressBar1.Move PlaceholderButton1.Left, PlaceholderButton1.Top, _
             PlaceholderButton1.Width, PlaceholderButton1.Height

where PlaceholderButton1 is a toolbar button whose Style property is set to 4-tbrPlaceholder.

Because the .NET Toolbar control can’t contain other controls, you can’t move a control over a toolbar by setting its Container property. If TextBox1 is a standard System.Windows.Forms.TextBox control, then the following statement

        TextBox1.Container = Toolbar1

makes the TextBox1 control disappear from its previous position but doesn’t make it reappear over the toolbar.

For this reason, assignments to the Container property of any control in VB Migration Partner’s support library throws an exception if the control being assigned is a Toolbar control. The message of the exception is

        The Toolbar control can’t work as a container

(The assignment is ignored and doesn’t throw any exception if the VB6Config.ThrowOnUnsupportedMembers property is False.)

Conveniently, the VB6Toolbar control exposes a custom method named MoveControlOverButton, whose effect is virtually identical to changing a control’s Container property so that its new container is the toolbar. The syntax of such a method is:

        Toolbar1.MoveControlOverButton control, button [, resize]

where control is the control to be moved, button is either the Button object or the index of the toolbar button over which the control must be moved, and resize is an optional Boolean value that specifies whether the control must be resized to take the same area as the placeholder button. For example, assuming that PlaceholderButton is the first button in the toolbar, you can move the ProgressBar1 control over the placeholder button named PlaceholderButton by means of one of these statements:

        Toolbar1.MoveControlOverButton ProgressBar1, 1, True
        Toolbar1.MoveControlOverButton ProgressBar1, PlaceholderButton, True

The best way to include this statement in the converted VB.NET application is by means of a ReplaceStatement pragma:

        Set ProgressBar1.Container = Toolbar1
        '## ReplaceStatement Toolbar1.MoveControlOverButton ProgressBar1, 1, True
        ProgressBar1.Move PlaceholderButton1.Left, PlaceholderButton1.Top, _
            PlaceholderButton1.Width, PlaceholderButton1.Height

Notice that the MoveControlOverButton method moves the control – ProgressBar1 in this example - “over” the toolbar, without making it a child of the toolbar control. If the toolbar is then moved, the ProgressBar1 control is moved in a synchronized way. However, if the placeholder button is moved or resized, you have to manually move or resize the ProgressBar1 control.

Previous | Index | Next 

Follow Francesco Balena on VB6 migration’s group on


Read Microsoft Corp’s official case study of a VB6 conversion using VB Migration Partner.

Code Architects and its partners offers remote and onsite migration services.

More details

Subscribe to our free newsletter for useful VB6 migration tips and techniques.


To learn more about your VB6 applications, run VB6 Analyzer on your source code and send us the generated text file. You will receive a detailed report about your VB6 applications and how VB Migration Partner can help you to quickly and effectively migrate it to .NET.

Get free advice

A fully-working, time-limited Trial Edition of VB Migration Partner allows you to test it against your actual code

Get the Trial

The price of VB Migration Partner depends on the size of the VB6 application, the type of license, and other factors

Request a quote

Migrating a VB6 application in 10 easy steps

Comparing VB Migration Partner with Upgrade Wizard

Migration tools: Feature Comparison Table

All whitepapers