.Net usercontrol in MS Access

You can create .Net UserControls, which can be used in the form of VB6 / MS Access via COM, using Interrop tools or as a simple ActiveX .

This works pretty well, except for one big pain: resizing .

You cannot resize the control at runtime.
Securing control on opposite sides of the form makes it grow every time you resize the form, even if you reduce the shape ...

There seems to be no way to tame this behavior:

  • From .Net, any attempt to resize UserControl code with an error fails.
  • From MS Access, a user control cannot be modified using code.

Apparently, one solution could be to complete the .Net Usercontrol in VB6 user control . Unfortunately, in addition to the need to use another shell and more ad-hoc code, the VB6 environment is no longer available ...

Is there any way to solve this problem?

+3
source share
3 answers

I'm not sure why MS Access and VB6 behave differently, but I found a working solution using .Net Interop with C #. It should also work with VB.Net.

  • Extend the IInteropUserControl interface with the following entry:

    void ResizeThis (int width, int height);

  • Implementing the ResizeThis Function:

    public void ResizeThis(int width, int height)
    {
        this.UpdateBounds(Left, Top, width, height);
        this.SetBounds(0, 0, width + 1, height + 1, BoundsSpecified.Width | BoundsSpecified.Height);
    }
    
  • MS Access ResizeThis .

  • . Access UserControl . , SetBoundsCore LockResizing. true, UserControl .

    protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
    {
        if (_LockResizing)
            throw new Exception();
    
        base.SetBoundsCore(x, y, width, height, specified);
    }
    
    public bool LockResizing
    {
        get { return _LockResizing; }
        set { _LockResizing = value; }
    }
    

UserControl MS Access 2010 2016 (Office 365).

+1

, . , , ...

VDN MSDN: Interop UserControl MSAccess.
, , , .

, Access , , .
, , , , .

+1

, / , , , .
, ....

.net com control

Private _ForceWidth As Integer = 0
Private _ForceHeight As Integer = 0

Public Property ForceWidth As Integer
    Get
        Return _ForceWidth
    End Get
    Set(value As Integer)
        _ForceWidth = value
    End Set
End Property


Public Property ForceHeight As Integer
    Get
        Return _ForceHeight
    End Get
    Set(value As Integer)
        _ForceHeight = value
    End Set
End Property



Private Sub MyControl_Resize(sender As Object, e As EventArgs) Handles MyBase.Resize
    If ForceWidth > 0 Then
        Me.Width = ForceWidth
    End If
    If ForceHeight > 0 Then
        Me.Height = ForceHeight
    End If
End Sub

Acces

Private Sub Form_Current()
    MyControl1.ForceWidth = 800
    MyControl1.ForceHeight = 600
    MyControl1.Width = SignatureControl6.Width - 1   'force sending resize message
End Sub

, ,

+1

Source: https://habr.com/ru/post/1778706/


All Articles