Hello,I am using VB Interop Toolkit to create a .NET activex control fur use in MSAccess.Unfortunately the activex is not sizable in MSAccess.Help is greatly appreciated.Marco.
Thursday, June 26, 2008 9:31 AM
- Changed type Riquel_DongModerator Wednesday, July 02, 2008 1:31 AM don't follow up with the necessary information
What do you mean that it is not sizable in Access? If you use it in VB6 application, could you resize it?
As far as I know, the Interop usercontrol is mainly applied in VB6 application. If you need to use the .Net control which is exposed to COM client like the Access application, you can create a usercontrol and register it for COM interop. I don't test this in Access and also don't use VBA language. I just create a normal usercontrol without using Interop usercontrol template and expose it to COM client. Then use it in VB6 application without problem. Try this.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.Monday, June 30, 2008 9:05 AM
I have experienced the same behaviour. I also wanted to use the Interop Forms Toolkit to create a usercontrol for our MSAccess-solution. I can add the control to my form, I can drag and drop it, but afterwards I cannot change the size of the control (that is; I can resize it in *design* mode, but when the form is displayed at runtime, it has the same size as when I put the control on my form). Another thing I observed was the following: I have a connectionstring-property for my control which has a default value (for testing purposes), this property can also not be changed. Again the same behaviour, I can change it in design mode, but at runtime it uses the original value for that property. It seems that all properties are frozen the moment you put the control on the form, you can changed them at design-time but these changes are not used at runtime. I tested the control in VB6 and there the behaviour is normal. But having to create a VB6 wrapper for every usercontrol I create, just doesn't seem like a practical solution, any ideas on how I could change this behaviour? I'm just guessing but I would say that there is something in the generated COM/Automation-interface that is creating this behaviour.
Friday, October 03, 2008 10:34 AM
Yes, for Interop UserControls, any value assigned to the Width and Height property of the control is ignored if the control is on a Access form. If the width of control X is 100...
X.Width = 200
The width will still be 100 in Access, but 200 in Visual Basic. If someone finds a solution to this, it would really be great.
Anders HWednesday, May 12, 2010 11:43 AM
FWIW, I abandonned using Interop controls for use in an Access-Form, it wasn't mission critical at the time. The problem it seemed was the fact that the ActiveX-container in Access is not the same as used in VB6 (where my control worked just fine). I did a couple of tests and the results were that if I made an ActiveX in .Net using the toolkit and then wrapping the ActiveX in VB6 duplicating the interface of the interop-control in VB6 (i.e. create an activeX in VB6 which has the same methods/properties as the interop-control), I could get it to work correctly. Using reflection (and maybe some custom attributes) I think you can fully automate this procedure. It's up to you to see if it's worth investing the time. I you pursue this solution, please keep me informed, I am very interested in the result!
CarlWednesday, May 12, 2010 12:14 PM
I did this, and our VBA programmer reports that Access still doesn't get the type library right, but that the container properties now works. The control can be resized using Width and Height. Also, it appears that Windows 7 64bit runs VB6 programs without problems. This feels like an ugly hack, and the best thing of course would be if Access could use "regular" ActiveX controls or if a better template for Visual Studio 2008 would be available.
Thanks for your help. I am still looking for a better way to do this without VB6.
MCSD/MCAD/MCTWednesday, May 19, 2010 1:29 PM
I have found a partial solution. It will work if your Interop UserControl is placed on an Access form.
Even though you can't programatically resize the Interop UserControl, you can set its Horizontal Anchor and Vertical Anchor properties to "Both" and the Access form will then cause the UserControl to be resized when the form is resized. The problem is that Access causes the UserControl to become way bigger than the form its on.
Here's the workaround:
Create a new Interop UserControl in .NET. Add a panel to the control. Place all your other controls on the panel.
Add a Rezise method that will be called from Access:
Public Sub ResizeInTwips(Optional ByVal Width As Integer = -1, Optional ByVal Height As Integer = -1) If Width > 0 Then Panel1.Width = ConvertTwipsToPixels(Width, 0) End If If Height > 0 Then Panel1.Height = ConvertTwipsToPixels(Height, 1) End If End Sub
<DllImport("user32.dll")> _ Private Shared Function GetDC(ByVal hwnd As IntPtr) As IntPtr End Function <DllImport("user32.dll")> _ Private Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Boolean End Function <DllImport("gdi32.dll")> _ Public Shared Function GetDeviceCaps(ByVal hDC As IntPtr, ByVal nIndex As Integer) As Integer End Function Const WU_LOGPIXELSX = 88 Const WU_LOGPIXELSY = 90 Function ConvertTwipsToPixels(ByVal intTwips As Integer, ByVal intDirection As Integer) As Integer Static bGotDC As Boolean = False Static intDC As Integer Static intPixelsPerInchHorizontal As Integer Static intPixelsPerInchVertical As Integer If Not bGotDC Then intDC = GetDC(0) intPixelsPerInchHorizontal = GetDeviceCaps(intDC, WU_LOGPIXELSX) intPixelsPerInchVertical = GetDeviceCaps(intDC, WU_LOGPIXELSY) intDC = ReleaseDC(0, intDC) bGotDC = True End If Dim intPixelsPerInch As Integer Const nTwipsPerInch = 1440 If (intDirection = 0) Then 'Horizontal intPixelsPerInch = intPixelsPerInchHorizontal Else 'Vertical intPixelsPerInch = intPixelsPerInchVertical End If Return (intTwips / nTwipsPerInch) * intPixelsPerInch End Function
Add your Interop UserControl to the Access form.
In the Access form, add the following code:
Private Sub Form_Resize() InteropUserControl1.ResizeInTwips Me.InsideWidth, Me.InsideHeight End Sub
That's all there is to it.
It works for me both when displaying the form as normal or making it a popup form.
If you need your Interop UserControl not to take up the whole Access form, you can put it in a subform.Thursday, December 09, 2010 5:25 PM