Easy Question - Moving Button Code

trujm
07-05-2007, 10:54 AM
Hi, thanks in advance.

I want to make the button move WITH the mouse, completely centered within the mouse cursor. I know it's really easy but for some reason it's not working for me.

I've tried:

Private Sub Timer1_Tick_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Button1.Top = MousePosition.Y
Button1.Left = MousePosition.X
End Sub

and

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
Button1.Top = e.Y
Button1.Left = e.X
End Sub

I think the problem is that I'm trying to do this OVER a webbrowser control. When I move the mouse on the little bit of the form that is NOT part of the webbrowser control, it works fine except that the cursor is in the top left corner of the buton. There is no "MouseMove" event for the webbrowser control. What should I do, and how do I get the cursor in the center of button?



Thanks in advance

trujm
07-05-2007, 03:23 PM
Anyone? I would REALLY appreciate it.

AtmaWeapon
07-05-2007, 04:18 PM
I really can't figure out a good reason for this; having the button directly under the cursor means that nothing's going to get click events but the buttons but oh well.

Setting the Form's Capture property to true might work at the expense of the mouse cannot move outside of the Form. If that doesn't work, I really don't see anything equivalent to the KeyPreview property for the mouse so you would probably have to override WndProc and look for the mousemove messages there.

trujm
07-05-2007, 07:14 PM
I really can't figure out a good reason for this; having the button directly under the cursor means that nothing's going to get click events but the buttons but oh well.

Setting the Form's Capture property to true might work at the expense of the mouse cannot move outside of the Form. If that doesn't work, I really don't see anything equivalent to the KeyPreview property for the mouse so you would probably have to override WndProc and look for the mousemove messages there.

Ok, I'll explain to you how im using this, so you can get a feel for what im trying to do, and also feel free to make a suggestion on if there is a better way of doing it.

I'm writing a program designed to make messaging people on myspace a little bit easier. What the program does is it automatically messages people when you click on their picture, rather than having to manually go to their profile and click "Send Message".

The way the program works: You click someone's avatar picture. Program navigates to their profile. Program extracts their member ID from the URL in their profile. Program navigates to the URL to send mail on myspace. Program fills out the form and clicks send. Message Sent. Simple as that. However, I wanted to skip the step of having to actually go to their profile first, and go straight to the send message form from the initial clicking of the avatar.

Which means that you have to intercept the click that leads you to their profile. A browser control is hard wired to go to whatever link you click, so what I have to do is intercept the user from clicking the profile - which I thought could be accomplished by creating an invisible button that followed the cursor everywhere within the browser control. When they clicked the button, it would bring them straight to the send mail form, and not the profile.

Any suggestions on how to do this without "ghetto rigging it" like I am seemingly forced to do now? LOL

Eduardo Lorenzo
07-05-2007, 07:32 PM
First: The step of going through the profile page was placed there by the developers of myspace for a reason. Probably to retrieve som data before sending mail. There are some steps that we are not allowed to skip. I haven't checked out that myspace thingie yet so I am guessing here. :)

Second: The most reasonable and logical way to accomplish what you want to do is to redirect the click. Instead of the site navigating to the profile page, it will go straight to the send mail page, which, would be almost the same as hijacking the flow and most sites do not allow that.

Am in the office right now (slacking) and myspace is blocked here.

AtmaWeapon
07-05-2007, 08:06 PM
What's going to happen when the user clicks the invisible button is either the button will receive the click event (unlikely) or the web browser will receive the click event and happily behave as normal.

There are two ways I can see doing this with VB .NET that are a good bit more sane. Supposing all parameters to the "Send Message" page aren't Post variables, you could simply look in the source to determine what makes the user portrait unique; odds are it has a class or id applied to its tag. Then, you want to load the page and work with the DocumentText property to alter all picture links to point to the appropriate "Send Message" page instead.

I'm not sure if DocumentText can be used that way; if not then an alternative would be to actually make the HTTP GET for the page yourself, then parse the response, then send that response to the WebBrowser control.

Of course the easiest way of all is to let someone else do the work for you. Consider looking into the Greasemonkey Firefox extension which is basically made to do work like this. I'd be willing to bet there's probably already a script that does exactly what you want, and you get to feel all pretentious using your alternabrowser as well! (Actually Firefox + Adblock + Greasemonkey + NoScript is the only way to surf.)

trujm
07-05-2007, 08:13 PM
Can I alter the document source AFTER the page is received? If so, I could replace the links to the profiles with links to send them mail.

And if so, how?

Thanks again.

Eduardo Lorenzo
07-05-2007, 08:56 PM
Supposing all parameters to the "Send Message" page aren't Post variables,

always remember this trujm.

For what you want to do, you can use a webbrowser control, read-in the html source AFTER the page has been loaded, find the appropriate strings (probably using regular expressions) and do the redirect yourself.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum