Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 06:32

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Visualbasic FormAnwendung; mouse/Picturebox location

Discussion on Visualbasic FormAnwendung; mouse/Picturebox location within the .NET Languages forum part of the Coders Den category.

Closed Thread
 
Old   #1
 
elite*gold: 0
Join Date: Jan 2013
Posts: 130
Received Thanks: 11
Visualbasic FormAnwendung; mouse/Picturebox location

Keine Ahnung wie ich den titel nennen sollte
aber mein Problem ist es das ich es nicht hinbekommen
wen ich mit meiner mouse auf der Picturebox bin und linke mouse geklickt halte
das die picturebox die Koordinaten von der mouse fährt wichtig hier bei ist das es um die links rechts Koordinaten geht

mein versuch wahr es daher das mouse move event wen mouse auf der Picturebox ist.

Picturebox1.location = (e.X,100) oder Picturebox1.Location (mouseposition. X,100)
wahren so meine ideen, aber beides hat nicht funktioniert ^^"
darauf folgten dann eha hilflose versuche das ich gesagt habe
das wen mouse auf der picbox ist das es ein integer 1 geben soll
und wen es leave 0
und hab dann das Mousemove event einzeln genommen und hab
abgefragt darin ist integer 1 + mouse left click dann soll
Picturebox1.location = (e.X,100) passieren ^^"
hat auch nicht geklappt

Wüsstet ihr wie ich es machen könnte ? ^^"
ProDielerNR(1) is offline  
Old 07/15/2020, 15:51   #2





 
Legendary's Avatar
 
elite*gold: 16
Join Date: Apr 2012
Posts: 5,497
Received Thanks: 632
Du kannst für die PictureBox ein Event registrieren (MouseDown). Im Constructor des Events (im Code) gibt es 2x Parameter. 1x den Sender und die EventArgs.

Code:
Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles MyBase.MouseDown
    MessageBox.Show(e.X & ", " & e.Y)
End Sub
Bei den Event-Args hast du die "X" Koordinate, welche für die links/rechts Position zuständig ist. Hoffe das hilft dir etwas weiter.
Legendary is offline  
Thanks
2 Users
Old 07/15/2020, 20:37   #3
 
elite*gold: 0
Join Date: Jan 2013
Posts: 130
Received Thanks: 11
hat mir leider nicht geholfen :?

um es spezifischer zu beschreiben, ich möchte mit der mouse die pickbox hin und her verschieben auf einer bestimmten x axe (kordinaten)
ProDielerNR(1) is offline  
Old 07/16/2020, 18:31   #4
 
elite*gold: 0
Join Date: Apr 2011
Posts: 363
Received Thanks: 166
Quote:
Originally Posted by ProDielerNR(1) View Post
hat mir leider nicht geholfen :?

um es spezifischer zu beschreiben, ich möchte mit der mouse die pickbox hin und her verschieben auf einer bestimmten x axe (kordinaten)
I don't know much vb sintax, but here is the basic algorithm:

1- Register mouse down event either for form or picture itself
1.a- Inside event handler save click location in a global or accesible variable in your code named $prevMousePosition, set $movingX and $movingY variables to false or sth like that, and set $mouseDown to true

2-Register mouse move event in form
2.a - if(not $mouseDown) return; //exit function nothing to do here
2.b - Compute $prevMousePosition vs $currentMouse if $movingX or $movingY are false, something like this:

if(not movingX and not movingY){
dx = $currentMouse.X - $prevMousePosition.X
dy = $currentMouse.Y - $prevMousePosition.Y
if(dx > dy)
$movingX = true
else
$movingY = true
}
if($movingX){
//lock x axis to click location in Y
Picturebox1.location = ($currentMouse.X,$prevMousePosition.Y)
}else if($movingY){
Picturebox1.location = ($prevMousePosition.X,$currentMouse.Y)
}


3- Register mouse up event: clear $mouseDown flag and set it to false

Reference for mouse events


Notes: words with $ means variables, just to clarify.

Summary:
Code:
mouseDownEvent(_,event){
movingX = false;
movingY = false;
prevMousePosition = event;
mouseDown = true;
}

mouseUpEvent(_,event){
mouseDown = false;
}

mouseMoveEvent(_,event){
if(not mouseDown) return;

f(not movingX and not movingY){
  dx = event.X - prevMousePosition.X
  dy = event.Y - prevMousePosition.Y
  if(dx > dy) 
  movingX = true
  else 
 movingY = true
}
if(movingX){
//lock x axis to click location in Y
Picturebox1.location = (event.X,prevMousePosition.Y)
}else if($movingY){
Picturebox1.location = (prevMousePosition.X,event.Y)
}

}
You can expand this code saving the object that you clicked in a variable and updating location of saved object
elmarcia is offline  
Thanks
1 User
Old 07/17/2020, 00:59   #5
 
elite*gold: 0
Join Date: Jan 2013
Posts: 130
Received Thanks: 11
I've already tried this in my code language (VB.net Application form) but it didn't work

Code:
Imports System
Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1
    Private Sub PictureBox1_MouseEnter(sender As Object, e As EventArgs) Handles PictureBox1.MouseEnter
        PictureBox1.Location = New Point(MousePosition.X, 100)
    End Sub
End Class
This is my first try for this
but have not actually work

Code:
Imports System
Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1
    Dim DragFlag As Boolean
    Dim MemX As Integer, MemY As Integer

    Private Sub picturebox1_MouseDown1(ByVal sender As Object,
    ByVal e As System.Windows.Forms.MouseEventArgs) _
    Handles PictureBox1.MouseDown
        DragFlag = True : MemX = e.X : MemY = e.Y
    End Sub

    Private Sub picturebox1_MouseMove1(ByVal sender As Object,
        ByVal e As System.Windows.Forms.MouseEventArgs) _
        Handles PictureBox1.MouseMove
        If Not DragFlag Then Exit Sub
        PictureBox1.Left = PictureBox1.Left + (e.X - MemX)
       
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        PictureBox1.Location = New Point(50, 100)
    End Sub

    Private Sub Picture2_MouseUp1(ByVal sender As Object,
    ByVal e As System.Windows.Forms.MouseEventArgs) _
    Handles PictureBox1.MouseUp
        DragFlag = False
    End Sub
End Class
I have found my solution!
Closed Quest
ProDielerNR(1) is offline  
Closed Thread


Similar Threads Similar Threads
[Selling] Dragonite Nest Location [Auto-Buy] + Free Dratini Hotspot Location for Candyfarming
08/07/2016 - Pokemon Trading - 0 Replies
AutoBuy: https://sellfy.com/p/AuNn/ http://i.imgur.com/QmNYGb1.jpg
Kontrollieren PictureBox andere PictureBox berührt?
11/20/2013 - .NET Languages - 5 Replies
Hey e*pvp! Ich habe aus Spaß in der Schule ein kleines Spiel angefangen... jedoch hänge ich gerade an einem ziemlich doofen Punkt. Wenn der Spieler den Diamanten berührt, dann soll ein neuer Diamant erstellt werden und die Punkte sollen sich um 1 erhöhen; alles kein Problem eigentlich... aber wie kann ich kontrollieren, ob die 1. PictureBox die 2. PictureBox berührt? Der Spieler ist 32x32 groß, und der Diamant 16x16. (Der Spieler kann nur rauf und runter, also müsste er nur die...
[?]Dynamische Picturebox Location
10/25/2012 - .NET Languages - 4 Replies
Hallo zusammen hier bin ich wieder mit einem neuen Problem. Wie der Titel schon sagt, geht es diesmal um die dynamische Position der Picturebox auf meiner Form. Meine Sub sieht so aus: Public Sub PicPlace() Dim rnW As Integer = 0 Dim rnH As Integer = 0
[MACRO/AHK/Mouse shortcut] hieitk's "mouse wheel button", REVISITED
04/12/2009 - CO2 Exploits, Hacks & Tools - 11 Replies
Since after discovering it I've been an affectoinate user of mbutton. Saves fingers and keys. And stress. Especially when you have to drop/sell stuff. But I had several issues with some of the "features", namely: 1) I couldn't scroll fast enough between the functions, let's say I had it on Jump, and wanted to sell. I had to do three scrolls, but between each there was a delay of more than one second 2) The F10 function wasn't really necessary 3) The functions didn't cycle, when you were...



All times are GMT +2. The time now is 06:32.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.