[V8i C# Addin] - How to get a dock panel to size?

I am new to microstation programming and am making an addin. I get everything to work properly but I cannot size the dockpanel. I have a keyin called 'Show' that triggers the showform function below:

internal static void ShowForm(Bentley.MicroStation.AddIn addIn)
s_current = null;

s_current = new AreaWindow(addIn);
s_current.AutoSize = false;

s_current.AttachAsTopLevelForm(addIn, true);
s_current.NETDockable = false;

Bentley.Windowing.WindowManager windowManager = Bentley.Windowing.WindowManager.GetForMicroStation();

s_current.m_windowContent = windowManager.DockPanel(s_current, s_current.Name, s_current.Name, Bentley.Windowing.DockLocation.Floating, new Size(350, 0), new Size(0,250));

s_comApp = BMI.Utilities.ComApp;

Everything works properly except the dockpanel is not 350 x 250. My form is that size but the dock panel i'm putting it into stretches larger for some reason. and just leaves padding to the right.

I've tried with/without autosize, with/without dockable. Nothing seems to work on it. Any ideas?

  • I had faced the similar problem earlier. After adding docking functionality the actual size of the form changed to some random height and width. I have used Win32 API to restore the correct size of the form. With the help of Dan Paul post http://communities.bentley.com/products/microstation/microstation_programming/f/19569/p/58662/139641.aspx I came up with the following class file. 

    Create a class ResizeAddinWindow.cs in your project and copy the following code. Change the namespace (Utilities) to your project namespace. 

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    using Bentley.Windowing;
    using System.Windows.Forms;

    namespace Utilities
    /// <summary>
    /// Class to resize Addin window
    /// </summary>
    public class ResizeAddinWindow
    // Rectangle layout
    public struct RECT
    public int X;
    public int Y;
    public int Width;
    public int Height;

    // resizing window methods
    public static extern bool GetWindowRect(IntPtr hWnd, ref RECT Rect);
    public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int Width, int Height, bool Repaint);

    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool
    SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,
    int X, int Y, int cx, int cy, uint uFlags);

    private enum SWP
    SWP_NOSIZE = 0x0001,
    SWP_NOMOVE = 0x0002,
    SWP_NOZORDER = 0x0004,
    SWP_NOREDRAW = 0x0008,
    SWP_NOACTIVATE = 0x0010,
    SWP_FRAMECHANGED = 0x0020,
    SWP_SHOWWINDOW = 0x0040,
    SWP_HIDEWINDOW = 0x0080,
    SWP_NOCOPYBITS = 0x0100,
    SWP_DEFERERASE = 0x2000,
    // Method to resize the actual window
    public static bool ResizeWindow(WindowContent _contentManager, int _windowWidth, int _windowHeight)
    Form _frm = _contentManager.Zone.FindForm();
    if (_frm != null)
    // To set the correct height and width
    RECT _currWindowRect = new RECT();
    if (GetWindowRect(_frm.Handle, ref _currWindowRect))
    MoveWindow(_frm.Handle, _currWindowRect.X, _currWindowRect.Y, _windowWidth, _windowHeight, true);
    SetWindowPos(_frm.Handle, new IntPtr(1), 0, 0, 0, 0,

    return false;
    return true;


    Bentley.Windowing.WindowManager windowManager = Bentley.Windowing.WindowManager.GetForMicroStation();

    s_current.m_windowContent = windowManager.DockPanel(s_current, s_current.Name, s_current.Name, Bentley.Windowing.DockLocation.Floating);

    ResizeAddinWindow.ResizeWindow(s_current.m_windowContent, 350, 250);

    Clean and Rebuild your solution.

    Let me know if this is not what you are looking for.

    Answer Verified By: zCane75