tags:

views:

27

answers:

2

Hello! I am new to visual basic and I have to program a form application for a university project. The application has a 2d array of panels that make up a grid that user can interact with. I have some experience with java, so what I am trying to ask is if there is anyway to translate this line into visual basic:

pnl[x][y].addMouseListener(new MouseListener(){ /*do stuff */};

A: 

That depends on which of the VB.NET UI libraries you are using, i.e., WinForms or WPF (what's the VB6 tag doing in your question, BTW?).

For example, to capture mouse moves in WinForms, you could do something like this:

AddHandler pnl(x)(y).MouseMove, AddressOf MyMouseMoveMethod

This attaches a handler function (see below) to the event that you want to handle.

Private Sub MyMouseMoveMethod(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    ... ''# The Mouse has been moved over the panel... do something
End Sub

The MouseListener thing in Java is an implementation of the Observer pattern. In .net, the same problems are solved through events and event handlers instead. To find out which events are available and what signature is required for the event handler, check the MSDN documentation page of the Panel control you are using.

Heinzi
yeah...so the application that I am making is part of a larger application that is in vb6...probably should have mentioned that.
Umesh
A: 

Make sure to use control arrays, so you will only need one Click event shared among all form elements. http://www.vb6.us/tutorials/vb6-control-array-tutorial

Detect