4 Replies - 755 Views - Last Post: 29 November 2016 - 05:07 AM Rate Topic: -----

#1 Ranbeer Singh   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-November 16

Push-Pull label with click on it

Posted 28 November 2016 - 12:24 AM

Hello Experts,

I tried to move label with two buttons, it was moving perfectly. The codes are blow.


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If (Label1.Location.Y <= 5) Then
        Else
            Label1.Location = New Point(Label1.Location.X, Label1.Location.Y - 10)
        End If

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If (Label1.Location.Y >= Me.Height - 60) Then
        Else
            Label1.Location = New Point(Label1.Location.X, Label1.Location.Y + 10)
        End If
End Sub


But I want to move a label up-down by clicking on label same as slidbar.

Thanks in advance

This post has been edited by IronRazer: 28 November 2016 - 05:09 AM
Reason for edit:: Inserted Code Tags


Is This A Good Question/Topic? 0
  • +

Replies To: Push-Pull label with click on it

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6823
  • View blog
  • Posts: 28,277
  • Joined: 12-December 12

Re: Push-Pull label with click on it

Posted 28 November 2016 - 12:39 AM

If you want to move the label by clicking it then it's practically the same code. If you want to drag it then look into, and search, drag events.
Was This Post Helpful? 0
  • +
  • -

#3 Ranbeer Singh   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-November 16

Re: Push-Pull label with click on it

Posted 28 November 2016 - 03:47 AM

Thank you very much for reply

Can you please give me a example? I want to move up/down only.
Was This Post Helpful? 0
  • +
  • -

#4 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1537
  • View blog
  • Posts: 3,867
  • Joined: 01-February 13

Re: Push-Pull label with click on it

Posted 28 November 2016 - 05:09 AM

As andrewsw has said, it would be pretty much the same code. The only thing you need to do is place the code in the click events of the Labels instead of the Click events of the Buttons. Give it a try.

If you are still having problems after that, then post the code that you have tried (using CODE tags), and explain what is not working the way you want it to. 8)
Was This Post Helpful? 0
  • +
  • -

#5 Ranbeer Singh   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-November 16

Re: Push-Pull label with click on it

Posted 29 November 2016 - 05:07 AM

Hi,

I tried MouseUp & MouseDown events, the codes result is little matching to my need. When i click on label, it does not see like pulling/pushing and goes to correct place when i leave mouse button. i need to see it's pulling/pushing with mouse cursor.

Public Class Form1


    Private Sub Label1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
        If (Label1.Location.Y >= Me.Height - 60) Then
            Label1.Location = New Point(Label1.Location.X, Me.Height - 60)
        ElseIf (Label1.Location.Y <= 5) Then
            Label1.Location = New Point(Label1.Location.X, 5)
        Else
            Label1.Location = New Point(Label1.Location.X, e.Y)
        End If
    End Sub

    Private Sub Label1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseUp
        If (Label1.Location.Y >= Me.Height - 60) Then
            Label1.Location = New Point(Label1.Location.X, Me.Height - 60)
        ElseIf (Label1.Location.Y <= 5) Then
            Label1.Location = New Point(Label1.Location.X, 5)
        Else
            Label1.Location = New Point(Label1.Location.X, e.Y)
        End If
    End Sub
End Class

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1