NightBlader
asked on
Moving the mouse over the whole form
Hello!
Im am making a little game on VB .Net, and i have a problem:
I have used the MouseMove event to move a control on my form with a mouse, but I had to make separate event subs for each control on the form to be able to make the control move when my mouse is over the different controls.
The problem is that I have a large area covered by a picturebox "array" (I'm using the suggestion microsoft made concerning control array replacement in VB .Net) built from about a hundred pictureboxes I create during runtime.
Now when I try to make a mousemove sub for the array it wont work, the control which has to move doesnt move when my mouse is over the array.
The array is created artificially and doesnt have a "base" in the design mode.
This is the header of the array function:
Private Sub PictBoxArray_MouseMove(ByV al sender As Object, ByVal e As System.Windows.Forms.Mouse EventArgs) _ Handles MyBase.MouseMove
How will I be able to move the control in any mouse position on the form.
The microsoft solution regarding control arrays:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchcreatingcontrolarraysinvisualbasicnetvisualcnet.asp
Thank You.
Im am making a little game on VB .Net, and i have a problem:
I have used the MouseMove event to move a control on my form with a mouse, but I had to make separate event subs for each control on the form to be able to make the control move when my mouse is over the different controls.
The problem is that I have a large area covered by a picturebox "array" (I'm using the suggestion microsoft made concerning control array replacement in VB .Net) built from about a hundred pictureboxes I create during runtime.
Now when I try to make a mousemove sub for the array it wont work, the control which has to move doesnt move when my mouse is over the array.
The array is created artificially and doesnt have a "base" in the design mode.
This is the header of the array function:
Private Sub PictBoxArray_MouseMove(ByV
How will I be able to move the control in any mouse position on the form.
The microsoft solution regarding control arrays:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchcreatingcontrolarraysinvisualbasicnetvisualcnet.asp
Thank You.
Just trying to understand what it is you are doing and want to acheive...give me a bit....
Andrew
Andrew
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you.
That would work but the picturebox creation is located in a different class, the function should be located in the main form class.
Now when I try accessing the form with:
AddHandler newPictureBox.MouseMove, AddressOf frmMain.MyPictureBox_Mouse Move
the compiler says I have to declare frmMain as an object, and I dont know how to declare it.
Could you please advise?
Thank You.
That would work but the picturebox creation is located in a different class, the function should be located in the main form class.
Now when I try accessing the form with:
AddHandler newPictureBox.MouseMove, AddressOf frmMain.MyPictureBox_Mouse
the compiler says I have to declare frmMain as an object, and I dont know how to declare it.
Could you please advise?
Thank You.
If you are creating and managing the pictureboxes from inside a class, then you should be adding the handler to the class, not the form. Perhaps you can show us some of your code so we can make more intelligent suggestions. =)
It sounds like a coding nightmare though. Another alternative, instead of trying to hand off mouse move events between different controls much as a cell phone call jumps from transmitting station to station as the caller moves around, is to use a timer and poll the current cursor position on the screen. But without knowing exactly what you app is doing it is hard to make suggestions.
Could you explain in more detail what your app does and how you want it to behave?
~IM
It sounds like a coding nightmare though. Another alternative, instead of trying to hand off mouse move events between different controls much as a cell phone call jumps from transmitting station to station as the caller moves around, is to use a timer and poll the current cursor position on the screen. But without knowing exactly what you app is doing it is hard to make suggestions.
Could you explain in more detail what your app does and how you want it to behave?
~IM
ASKER
Ah, ok.
I've already added the handle to the class.
Im not managing the pictureboxes through the class, I only use it for one purpose, creating a picturebox collection when the program starts and using the method in it to add pictureboxes to the collection, put them in place and set their size.
Im new to VB .NET (im using my dad's software, im 16), and I didnt use collections before.
If I was working with VB6 I wouldnt have any problems, I would just create a control array and work with it.
But as VB .NET doesnt support control arrays I have to emulate them through a collection using a class, microsoft made that suggestion in the link above.
At the beggining of the program, after positioning different controls I have a loop to generate the pictureboxes(blocks).
With each loop I call the class method which creates my picturebox and add that picturebox to an array as follows:
For i = 0 To BRICK_ROW_NUM - 1
For k = 0 To BRICK_COL_NUM - 1
System.Threading.Thread.Sl eep(30)
BrickArr.AddNewPicture(i, k)
BrickArr(i * BRICK_COL_NUM + k).BorderStyle = BorderStyle.FixedSingle
BrickArr(i * BRICK_COL_NUM + k).BackColor = ColorArr(Int(((COLOR_NUM - 1) * Rnd()) + 0))
Next k
Next i
(I declare BrickArr as PictureArray which is my class name)
The method in the class:
Public Function AddNewPicture(ByVal i As Integer, ByVal k As Integer) As System.Windows.Forms.Pictu reBox
Dim picDataShow As New System.Windows.Forms.Pictu reBox
Me.List.Add(picDataShow)
AddHandler picDataShow.MouseMove, AddressOf frmMain.Bricks_MouseMove 'THE HANDLER I ADD
HostForm.Controls.Add(picD ataShow)
picDataShow.Height = BRICK_HEIGHT / 1
picDataShow.Width = BRICK_WIDTH / 1
picDataShow.Top = i * picDataShow.Height + PANEL_HEIGHT
picDataShow.Left = k * picDataShow.Width + 7
picDataShow.Tag = Me.Count
Return picDataShow
End Function
frmMain is also automatically set as the name of the main form class because it's the name of the form
The compiler says:
Reference to a non-shared member requires an object reference.
About: frmMain.Bricks_MouseMove
MSDN says I have to declare frmMain, how do I do that?
Thank You.
I've already added the handle to the class.
Im not managing the pictureboxes through the class, I only use it for one purpose, creating a picturebox collection when the program starts and using the method in it to add pictureboxes to the collection, put them in place and set their size.
Im new to VB .NET (im using my dad's software, im 16), and I didnt use collections before.
If I was working with VB6 I wouldnt have any problems, I would just create a control array and work with it.
But as VB .NET doesnt support control arrays I have to emulate them through a collection using a class, microsoft made that suggestion in the link above.
At the beggining of the program, after positioning different controls I have a loop to generate the pictureboxes(blocks).
With each loop I call the class method which creates my picturebox and add that picturebox to an array as follows:
For i = 0 To BRICK_ROW_NUM - 1
For k = 0 To BRICK_COL_NUM - 1
System.Threading.Thread.Sl
BrickArr.AddNewPicture(i, k)
BrickArr(i * BRICK_COL_NUM + k).BorderStyle = BorderStyle.FixedSingle
BrickArr(i * BRICK_COL_NUM + k).BackColor = ColorArr(Int(((COLOR_NUM - 1) * Rnd()) + 0))
Next k
Next i
(I declare BrickArr as PictureArray which is my class name)
The method in the class:
Public Function AddNewPicture(ByVal i As Integer, ByVal k As Integer) As System.Windows.Forms.Pictu
Dim picDataShow As New System.Windows.Forms.Pictu
Me.List.Add(picDataShow)
AddHandler picDataShow.MouseMove, AddressOf frmMain.Bricks_MouseMove 'THE HANDLER I ADD
HostForm.Controls.Add(picD
picDataShow.Height = BRICK_HEIGHT / 1
picDataShow.Width = BRICK_WIDTH / 1
picDataShow.Top = i * picDataShow.Height + PANEL_HEIGHT
picDataShow.Left = k * picDataShow.Width + 7
picDataShow.Tag = Me.Count
Return picDataShow
End Function
frmMain is also automatically set as the name of the main form class because it's the name of the form
The compiler says:
Reference to a non-shared member requires an object reference.
About: frmMain.Bricks_MouseMove
MSDN says I have to declare frmMain, how do I do that?
Thank You.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yeah, of course, I tried that.
But, it gives the mistake:
'Bricks_MouseMove' is not a member of 'System.Windows.Forms.Form '.
When I try Intellisense on HostForm it just displays a list of form properties and none of the methods in the frmMain class.
I think HostForm is just a kinda "C++ pointer" or reference to the form itself, not the class with the same name.
This is how I declare HostName, the following sub is located in the PictureArray class.
Public Sub New(ByVal host As System.Windows.Forms.Form)
HostForm = host
Me.AddNewPicture(0, 0)
End Sub
Thank You.
But, it gives the mistake:
'Bricks_MouseMove' is not a member of 'System.Windows.Forms.Form
When I try Intellisense on HostForm it just displays a list of form properties and none of the methods in the frmMain class.
I think HostForm is just a kinda "C++ pointer" or reference to the form itself, not the class with the same name.
This is how I declare HostName, the following sub is located in the PictureArray class.
Public Sub New(ByVal host As System.Windows.Forms.Form)
HostForm = host
Me.AddNewPicture(0, 0)
End Sub
Thank You.
ASKER
Ah,
I also have
BrickArr = New PictureArray(Me)
added to the
#Region " Windows Form Designer generated code "
I also have
BrickArr = New PictureArray(Me)
added to the
#Region " Windows Form Designer generated code "
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yep, that works.
The mistake with public I figured out myself, but I had HostForm declared as System.Windows.Forms.Form.
Thank you both very much.
I have actually finished my game but had this annoyence I couldnt move my mouse over half of the screen.
I split the points 40:85.
The mistake with public I figured out myself, but I had HostForm declared as System.Windows.Forms.Form.
Thank you both very much.
I have actually finished my game but had this annoyence I couldnt move my mouse over half of the screen.
I split the points 40:85.
Glad we could figure it out.
~M
~M
NightBlader/IM,
Sorry, been off the air for a while:-/ apologies.
Andrew
Sorry, been off the air for a while:-/ apologies.
Andrew
ASKER