Search code examples
c#winformsms-accessactivexcom-interop

Set Size of an ActiveX Control in MS Access


I have written an WinForms Control as ActiveX by COM-Interop and so far it works well in MS Access. But the Problem is in Access the Form on the Display View hasn't the same Size as the Form in the Design View. I have tried to set the Initialize Size by getting the ContainerControl. But i doesn't return the right Value.

    public DummyCtrl()
    {
        this.Dock = DockStyle.Fill;
        this.AutoSize = true;

        var axC = (Control)this.GetContainerControl();
        this.Width = axC.Width;
        this.Height = axC.Height;

        InitializeComponent();
    }

GetContainerControl() contains a "ControlAxSourcingSite[WFControl.DummyCtrl]" Object.

I'm not sure how to get the right Value befor Initialize the Element. Any Ideas?


Solution

  • So i found it by myself. ;)

    The right way to do this is:

    public DummyCtrl()
    { 
        this.Size = PreferredSize;
        InitializeComponent();
    }
    

    I suggest that this works probably in every Forms Control. Have a nice Day...