cancel
Showing results for 
Search instead for 
Did you mean: 

Problem Form Windows

Former Member
0 Kudos

I am developing an Addon for SAP Businnes One using Visual.Net. I need to include Windows forms but it gives me this error - the form is drawn without cantrols and hanged.

my code is:

This is the code:

Private Sub SBOapp_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean) Handles SBOapp.MenuEvent

If pVal.BeforeAction Then

If pVal.MenuUID = "modUSER" Then

Dim myFORM As New frmIMAGEN

myFORM.TopMost = True

myFORM.Show()

.....

Does anybody knows how to solve this problem?

This is very important an urgent for me, Somebody can help me?

thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Carmen,

You must open the windows form in a new thread:


Imports System.Threading
....
....
Dim myThread As Thread
Dim myform1 As New form1
myThreadFic = New Thread(New ThreadStart(AddressOf myform1.Form1Main))
myThread.Start()

In the form1 you must add the Form1Main procedure:


Public Sub Form1Main()
Me.Show()
Do
   System.Windows.Forms.Application.DoEvents()
Loop
End Sub

Regards

Blas

simone_pastorin
Participant
0 Kudos

Thank you Blas! You put me on the right way.

Anyway in my case it gave me this error:

Cross thread operation not valid: Control "XXXXXXXXXX" accessed from a thread other than the thread it was created.

So I add to make some changes:

In my public void SBO_Application_MenuEvent I wrote:

//open the form on a different thread

var thread = new Thread(MyForm.StartForm);

thread.Start();

and in my class MyForm I wrote:

//start the form creating a new instance of it

public static MyForm fMyForm;

public static void StartForm()

{

    fMyForm = new MyForm();

    fMyForm.Show();

    while(true)

        Application.DoEvents();

}

Hope it can help someone!

Answers (1)

Answers (1)

Former Member
0 Kudos

You need a separate thread to run it:

Check here:

HTH Lutz Morrien