473,378 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Moving a control as runtime

I use the following three subs to click on a label and reposition it at
runtime:

Private Sub lblP1JoyUp_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseDown

myMouseDown = True

mouseX = Cursor.Position.X - Me.Location.X - (lblP1JoyUp.Width / 2)

mouseY = Cursor.Position.Y - Me.Location.Y - (lblP1JoyUp.Height / 2)

End Sub

Private Sub lblP1JoyUp_MouseMove(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseMove

Static LastCursor As Point

Dim NowCursor As Point = New Point(mouseX, mouseY)

If Point.op_Inequality(NowCursor, LastCursor) Then

If myMouseDown Then

lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle

lblP1JoyUp.Location = New
System.Drawing.Point(Cursor.Position.X - (Me.Location.X + 4) -
(lblP1JoyUp.Width / 2), Cursor.Position.Y - (Me.Location.Y + 50) -
(lblP1JoyUp.Height / 2))

End If

LastCursor = Cursor.Position

End If

End Sub

Private Sub lblP1JoyUp_MouseUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseUp

lblP1JoyUp.BorderStyle = BorderStyle.None

myMouseDown = False

End Sub

The problem is that if I drag it over top of another label funny things
happen. I seems somewhat randon. Sometimes the label I'm dragging will drop
and the label I moved over will be picked up instead. Sometime labels seem
to jump to another part of the screen. I am looking for a way to lock all of
the controls except for the one that I am dragging.

Thanks,

John
Nov 20 '05 #1
7 1592
Hi John,

Do you mean that you want it to bring to front in the mouse down event?

:-)

Cor
Nov 20 '05 #2
I think I may have resolved it. i was using a global variable called
"myMouseDown". I think the problem was that all 25 label controls called the
same variable. Hence, when I drag one label over top of another label the
"myMouseDown" variable is true and the label does funny things. I created a
seperate variable for each label. I'll give it a try and see if it seemed to
help.

Thanks,

John

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi John,

Do you mean that you want it to bring to front in the mouse down event?

:-)

Cor

Nov 20 '05 #3
Hi John,

But did you set that label1 you are using as I said
label(x).bringtofront

I think that will do a lot.

:-)

Cor

Do you mean that you want it to bring to front in the mouse down event?

:-)

Cor


Nov 20 '05 #4
HI John,

I still not see that sentence,
Private Sub lblP1JoyUp_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseDown
lblP1JoyUpMouseDown = True

lblP1JoyUp.bringtofront

mouseX = Cursor.Position.X - Me.Location.X - (lblP1JoyUp.Width / 2)
mouseY = Cursor.Position.Y - Me.Location.Y - (lblP1JoyUp.Height / 2)
End Sub

In you code what was in the previous message?

Cor


Nov 20 '05 #5
Cor....Sorry man. I didn't see your suggestion until after I thought of it
myself, which was AFTER I made the previous post. That solved the problem. I
have one other slight problem with this routine. If I move the mouse to
quickly and the cursor gets outside of the label control, the label stops
moving until you go back over top of it again. It's pretty annoying since
you have to move the mouse quite slowly while dragging. One thing I did to
help was changed the backcolor property from transparent to black. The user
can the set them to transparent once they get the label into position.
Transparent seems to REALLY slow things dow. Must be all of the additional
calcs the processor needs to perform. ANyways, an ideas on the dragging
issue?

Thanks,
John
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OX**************@TK2MSFTNGP11.phx.gbl...
HI John,

I still not see that sentence,
Private Sub lblP1JoyUp_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseDown
lblP1JoyUpMouseDown = True

lblP1JoyUp.bringtofront

mouseX = Cursor.Position.X - Me.Location.X - (lblP1JoyUp.Width / 2) mouseY = Cursor.Position.Y - Me.Location.Y - (lblP1JoyUp.Height / 2) End Sub

In you code what was in the previous message?

Cor

Nov 20 '05 #6
Hi John,

I made a complete sample, for me it does work as I expect, however do not
forget this goes through all borders etc. I did bring the sample back to
keep it readable.

(You can open a new form project, delete everything in the code past this in
and than it should go)

I hope this helps,

Cor

Public Class Form1
Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
Private WithEvents Label1 As New Label
Private WithEvents Label2 As New Label
Private mouseX, mouseY As Integer
Private arLabels() As Label
Dim myMousedown As String
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.ClientSize = New System.Drawing.Size(400, 400)
Label1.Name = "Label1"
Label2.Name = "Label2"
arLabels = New Label() {Label1, Label2}
Dim lblY As Integer = 100
For Each Lbl As Label In arLabels
Lbl.Location = New System.Drawing.Point(100, lblY)
Lbl.ForeColor = Color.Red
Lbl.BackColor = Color.Transparent
Lbl.TextAlign = ContentAlignment.MiddleCenter
Lbl.Text = Lbl.Location.X.ToString & "." &
Lbl.Location.Y.ToString
AddHandler Lbl.MouseDown, AddressOf Label_MouseDown
AddHandler Lbl.MouseUp, AddressOf Label_MouseUp
AddHandler Lbl.MouseMove, AddressOf Label_MouseMove
lblY += 30
Me.Controls.Add(Lbl)
Next
End Sub
Private Sub Label_MouseDown(ByVal sender As Object, ByVal _
e As System.Windows.Forms.MouseEventArgs)
Dim lbl As Label = DirectCast(sender, Label)
myMousedown = lbl.Name
lbl.BringToFront()
mouseX = Cursor.Position.X - lbl.Location.X
mouseY = Cursor.Position.Y - lbl.Location.Y
lbl.Cursor = Cursors.Hand
End Sub
Private Sub Label_MouseUp(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs)
Dim lbl As Label = DirectCast(sender, Label)
myMousedown = ""
lbl.Cursor = Cursors.Default
End Sub
Private Sub Label_MouseMove(ByVal sender As Object, ByVal e _
As System.Windows.Forms.MouseEventArgs)
Dim lbl As Label = DirectCast(sender, Label)
Static LastCursor As Point
Dim NowCursor As Point = New Point(Cursor.Position.X,
Cursor.Position.Y)
If Point.op_Inequality(NowCursor, LastCursor) Then
If myMousedown = lbl.Name Then
lbl.Location = New System.Drawing.Point(Cursor.Position.X _
- mouseX, Cursor.Position.Y - mouseY)
End If
LastCursor = Cursor.Position
lbl.Text = lbl.Location.X.ToString & "." &
lbl.Location.Y.ToString
End If
End Sub
End Class
I hope this helps a little bit?

Cor
Nov 20 '05 #7
Resolved!

Thanks,
John

"jcrouse" <me> wrote in message
news:ua**************@TK2MSFTNGP10.phx.gbl...
I use the following three subs to click on a label and reposition it at
runtime:

Private Sub lblP1JoyUp_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseDown

myMouseDown = True

mouseX = Cursor.Position.X - Me.Location.X - (lblP1JoyUp.Width / 2)
mouseY = Cursor.Position.Y - Me.Location.Y - (lblP1JoyUp.Height / 2)
End Sub

Private Sub lblP1JoyUp_MouseMove(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseMove

Static LastCursor As Point

Dim NowCursor As Point = New Point(mouseX, mouseY)

If Point.op_Inequality(NowCursor, LastCursor) Then

If myMouseDown Then

lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle

lblP1JoyUp.Location = New
System.Drawing.Point(Cursor.Position.X - (Me.Location.X + 4) -
(lblP1JoyUp.Width / 2), Cursor.Position.Y - (Me.Location.Y + 50) -
(lblP1JoyUp.Height / 2))

End If

LastCursor = Cursor.Position

End If

End Sub

Private Sub lblP1JoyUp_MouseUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseUp

lblP1JoyUp.BorderStyle = BorderStyle.None

myMouseDown = False

End Sub

The problem is that if I drag it over top of another label funny things
happen. I seems somewhat randon. Sometimes the label I'm dragging will drop and the label I moved over will be picked up instead. Sometime labels seem
to jump to another part of the screen. I am looking for a way to lock all of the controls except for the one that I am dragging.

Thanks,

John

Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Barrett | last post by:
Hello, basically I want to be able to determine the height of a panel at runtime on a webform. The only value I can squeeze out of the control properties is the height that is set at design time....
12
by: swingingming | last post by:
Hi, in the NorthWind sample database, when clicking on the next navigation button on the new order record with nothing on the subform (order details), we got an order with nothing ordered. How can...
2
by: jbmeeh | last post by:
I have an application in which I need to expose runtime moving and resizing of controls. Most of the functionality that I need is exposed by the CRectTracker class in the C++ library. Are there any...
20
by: Guadala Harry | last post by:
In an ASCX, I have a Literal control into which I inject a at runtime. litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID); This works great as long as the contains just...
7
by: Smithers | last post by:
I have a non trivial ASP.NET Web application that implements its navigation system via a user control (menu.ascx) placed on every page. It is important to note that the user control that hosts...
3
by: Just Me | last post by:
If I move the mouse cursor over a control and stop moving I get a MouseHover event. If I then move the cursor while staying within the control and then stop moving I do not get another...
2
by: Diogo Alves - Software Developer | last post by:
Greetings I would like to knowhow can I put a sliding panel... I've done this: if (panel1.Width < 300) { while (panel1.Width < 300) { panel1.Width = panel1.Width + 40;
0
by: xpnet | last post by:
Hi, I am using Mutliview control, and want to move a user control from one view to another view based on user selection. I can do this by placing a "Placeholder" control in each views. Based on...
3
by: SonOf27 | last post by:
Morning all. I was hoping somone would be able to help me with some VBA program that will allow me to move the whole Tab Control on an Access form at runtime. What I have is a form in Access 2000...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.