How to get method on an Ocx in vb.net

145 Views Asked by At

So this is a both a general and very specific question: My client has a vb6 project migrating to vb.net as does not want to upgrade to a new component. This is with respect to VSPrinter. I can import the lib no problems and it works. Code: Imports VSPrinter8Lib And then Dim VS As New VSPrinter With VS etc.. End With I can access all properties and all good. But… When it fires a NewPage() I have no way of trapping that method. How do I do that? If I create a form and drop the ocx on it I can get that Private Sub VS_NewPage(sender As Object, e As EventArgs) Handles VS.NewPageEvent MsgBox("J") End Sub But then I can’t use VS.Picture = VS.LoadPicture(etc) to bring in an image.

I think I am missing how to load an ocx library an get at the methods programmatically. Any help would be greatly appreciated

Thanks!

1

There are 1 best solutions below

0
quest On

You need to create a form, add VsPrinter as an OCX component, then do this:

.Picture = .get_LoadPicture(your picture) 

This is different than VB6 LoadPicture. You also need to pass ByRef your initial call to any sub call. So, as an example, on your form load, if you want to call a routine that loads a picture you first

Import AxVSPrinter8Lib 

and then create a call GetCoLogo(Me.VS) to

Private Shared Sub GetCoLogo(ByRef VS As AxVSPrinter)