'System.MissingMethodException' when calling function from Mousedown Event??

P

PocketDeveloper

This is so puzzling...maybe someone here with has a suggestion to help
me.


It started when I added an If statment (CurrentTab <> "A" ) to this
code in a MouseDown event (Note: the image bitmap assignment was
working *FINE* until I added the IF code around it):

Private Sub pictTabA_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles pictTabA.MouseDown

If CurrentTab <> "A" Then
Dim img = New Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MYApp.A
Tab Down.jpg"))
pictTabA.Image = img
End If

End Sub

Once I added the check on the CurrentTab variable, I started getting:
'An unhandled exception of type 'System.MissingMethodException'
occurred in System.Windows.Forms.dll"

The CurrentTab variable is a private Form-level variable declared in
the same form as the picture control whose MouseDown I am checking
here.

Any thoughts? I have spent HOURS on this simple code. I am so
frustrated.


Thanks for your help and suggestions!
 
P

Peter Foot [MVP]

You are comparing a TabPage to a string - you probably want:-

If CurrentTab.Text <> "A" Then

Peter
 
P

PocketDeveloper

Peter Foot said:
You are comparing a TabPage to a string - you probably want:-

If CurrentTab.Text <> "A" Then

Peter

CurrentTab is a String variable. And I have since found that trying to
call any user defined function inside the MouseDown event results in
the error.

Any further thoughts?
 
T

TradeHound

I was getting the same error in C#. I fixed it by using the Invoke
command. I am updating a DataTable which is a datasource of a
DataGrid. I was just directly calling the procedure that updated the
DataTable. This was causing an exception outside my code, like you
are getting. It has something to do with accessing a form component
from your thread that doesn't "own" the component.

Here is what fixed it for me:

Define the procedure that does the updating like this:
public void UpdGrid_handler(object sender, EventArgs evArgs)

Whenever you need to update the grid, use a line like this:
grid.Invoke(new EventHandler(UpdGrid_handler));

Hope this helps,
Mick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top