473,772 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Destinquishing between controls

I have a test app with one button and a context menu. When I click on the
button, it adds a label with some properties, one being the assignment of
the context menu. If I add 5 buttons then want to delete one I can right
click and choose Delete from the context menu. The problems is that I don't
know the proper verbage to search for (in help) to find the code to tell
which label is the one the received the right click event. I'm not sure if
sender is the proper word but I need to know which label is the sender.
Also, how will I the reference the individual labels is code? What will
their names be (or how can I assign a unique name to each label)? I don't
really want to use a loop because I may add a couple of labels then later
add a couple of more and so on (or possibly delete some). I hope this makes
sense. Here is my code.

Dim intTopCounter As Integer = 20

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim MyLabel As New Label

MyLabel.Text = intTopCounter.T oString

MyLabel.TextAli gn = ContentAlignmen t.MiddleCenter

MyLabel.BackCol or = BackColor.Black

MyLabel.ForeCol or = ForeColor.White

MyLabel.Top = intTopCounter

MyLabel.Left = 40

MyLabel.Context Menu = cmnuLabels

intTopCounter = intTopCounter + 30

Me.Controls.Add (MyLabel)

End Sub

Private Sub cmDelete_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmDelete.Click

'Delete Label Code Here

End Sub
Thanks,
John

Nov 21 '05 #1
8 1142
John,

You mean this?
\\\
Me.Controls.Rem ove(Me.ActiveCo ntrol)
///
I hope this helps?
Cor
I have a test app with one button and a context menu. When I click on the
button, it adds a label with some properties, one being the assignment of
the context menu. If I add 5 buttons then want to delete one I can right
click and choose Delete from the context menu. The problems is that I don't know the proper verbage to search for (in help) to find the code to tell
which label is the one the received the right click event. I'm not sure if
sender is the proper word but I need to know which label is the sender.
Also, how will I the reference the individual labels is code? What will
their names be (or how can I assign a unique name to each label)? I don't
really want to use a loop because I may add a couple of labels then later
add a couple of more and so on (or possibly delete some). I hope this makes sense. Here is my code.

Dim intTopCounter As Integer = 20

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim MyLabel As New Label

MyLabel.Text = intTopCounter.T oString

MyLabel.TextAli gn = ContentAlignmen t.MiddleCenter

MyLabel.BackCol or = BackColor.Black

MyLabel.ForeCol or = ForeColor.White

MyLabel.Top = intTopCounter

MyLabel.Left = 40

MyLabel.Context Menu = cmnuLabels

intTopCounter = intTopCounter + 30

Me.Controls.Add (MyLabel)

End Sub

Private Sub cmDelete_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmDelete.Click

'Delete Label Code Here

End Sub
Thanks,
John

Nov 21 '05 #2
Hey Cor....Good to hear from you again. Well, that's kind of correct,
however when I click on the button to add the labels the button remains the
active control. Then when I right click on a label and try to remove it, the
button gets removed.

Thanks,
John

"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:ee******** *****@TK2MSFTNG P11.phx.gbl...
John,

You mean this?
\\\
Me.Controls.Rem ove(Me.ActiveCo ntrol)
///
I hope this helps?
Cor
I have a test app with one button and a context menu. When I click on the button, it adds a label with some properties, one being the assignment of the context menu. If I add 5 buttons then want to delete one I can right
click and choose Delete from the context menu. The problems is that I

don't
know the proper verbage to search for (in help) to find the code to tell
which label is the one the received the right click event. I'm not sure if sender is the proper word but I need to know which label is the sender.
Also, how will I the reference the individual labels is code? What will
their names be (or how can I assign a unique name to each label)? I don't really want to use a loop because I may add a couple of labels then later add a couple of more and so on (or possibly delete some). I hope this

makes
sense. Here is my code.

Dim intTopCounter As Integer = 20

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim MyLabel As New Label

MyLabel.Text = intTopCounter.T oString

MyLabel.TextAli gn = ContentAlignmen t.MiddleCenter

MyLabel.BackCol or = BackColor.Black

MyLabel.ForeCol or = ForeColor.White

MyLabel.Top = intTopCounter

MyLabel.Left = 40

MyLabel.Context Menu = cmnuLabels

intTopCounter = intTopCounter + 30

Me.Controls.Add (MyLabel)

End Sub

Private Sub cmDelete_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmDelete.Click

'Delete Label Code Here

End Sub
Thanks,
John


Nov 21 '05 #3
John,

I think that it is because the label get never focus.

I once made this sample special for your however never got any reaction.

You can try it again, because a sample how to do the things you ask now and
some more things I have in added in it.

The only thing it needs is open a new project, delete all code and paste
this what is below in.

I hope this helps.

Cor

\\\
Public Class Form1
Inherits System.Windows. Forms.Form
Public Sub New()
MyBase.New()
InitializeCompo nent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
Friend WithEvents ContextMenu1 As System.Windows. Forms.ContextMe nu
Friend WithEvents mnuAdd As System.Windows. Forms.MenuItem
Friend WithEvents mnuRemove As System.Windows. Forms.MenuItem
Private Sub InitializeCompo nent()
Me.components = New System.Componen tModel.Containe r
Me.myToolTip = New System.Windows. Forms.ToolTip(M e.components)
Me.ContextMenu1 = New System.Windows. Forms.ContextMe nu
Me.mnuAdd = New System.Windows. Forms.MenuItem
Me.mnuRemove = New System.Windows. Forms.MenuItem
Me.ContextMenu1 .MenuItems.AddR ange(New
System.Windows. Forms.MenuItem( ) _
{Me.mnuAdd, Me.mnuRemove})
Me.mnuAdd.Index = 0
Me.mnuAdd.Text = "Add"
Me.mnuRemove.In dex = 1
Me.mnuRemove.Te xt = "Remove"
Me.Name = "Form1"
End Sub
Private components As System.Componen tModel.IContain er
Private mouseX, mouseY As Integer
Private arLabels As New ArrayList
Private myToolTip As ToolTip
Private createdLabels As Integer
Private myMousedown As String
Private Lastlabel As Label
Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
CreateLabel("Se e Tooltip")
End Sub
Private Sub CreateLabel(ByV al LabelText As String)
Me.ClientSize = New System.Drawing. Size(400, 400)
Dim lbl As New Label
createdLabels = +1
lbl.Name = "Label" & createdLabels.T oString
Dim lblY As Integer = 100
lbl.Location = New System.Drawing. Point(100, lblY)
lbl.ForeColor = Color.Red
lbl.BackColor = Color.Transpare nt
lbl.TextAlign = ContentAlignmen t.MiddleCenter
lbl.Text = LabelText
lbl.ContextMenu = ContextMenu1
AddHandler lbl.MouseDown, AddressOf Label_MouseDown
AddHandler lbl.MouseUp, AddressOf Label_MouseUp
AddHandler lbl.MouseMove, AddressOf Label_MouseMove
lblY += 30
Me.Controls.Add (lbl)
lbl.BringToFron t()
End Sub
Private Sub Label_MouseDown (ByVal sender As Object, ByVal _
e As System.Windows. Forms.MouseEven tArgs)
Lastlabel = DirectCast(send er, Label)
myMousedown = Lastlabel.Name
Lastlabel.Bring ToFront()
mouseX = Cursor.Position .X - Lastlabel.Locat ion.X
mouseY = Cursor.Position .Y - Lastlabel.Locat ion.Y
Lastlabel.Curso r = Cursors.Hand
End Sub
Private Sub Label_MouseUp(B yVal sender As Object, ByVal e As _
System.Windows. Forms.MouseEven tArgs)
Dim lbl As Label = DirectCast(send er, Label)
myMousedown = ""
lbl.Cursor = Cursors.Default
End Sub
Private Sub Label_MouseMove (ByVal sender As Object, ByVal e _
As System.Windows. Forms.MouseEven tArgs)
Dim lbl As Label = DirectCast(send er, Label)
Static LastCursor As Point
Dim NowCursor As Point = New Point(Cursor.Po sition.X,
Cursor.Position .Y)
If Point.op_Inequa lity(NowCursor, LastCursor) Then
If myMousedown = lbl.Name Then
lbl.Location = New System.Drawing. Point(Cursor.Po sition.X _
- mouseX, Cursor.Position .Y - mouseY)
End If
LastCursor = Cursor.Position
lbl.Text = "Right Click me"
myToolTip.SetTo olTip(lbl, _
lbl.Location.X. ToString & "." & lbl.Location.Y. ToString)
End If
End Sub
Private Sub mnuAdd_Click(By Val sender As Object, _
ByVal e As System.EventArg s) Handles mnuAdd.Click
CreateLabel("Mo ve me away")
End Sub
Private Sub mnuRemove_Click (ByVal sender As Object, _
ByVal e As System.EventArg s) Handles mnuRemove.Click
Me.Controls.Rem ove(Lastlabel)
End Sub
End Class
///

Nov 21 '05 #4
* "jcrouse" <me> scripsit:
I have a test app with one button and a context menu. When I click on the
button, it adds a label with some properties, one being the assignment of
the context menu. If I add 5 buttons then want to delete one I can right
click and choose Delete from the context menu. The problems is that I don't
know the proper verbage to search for (in help) to find the code to tell
which label is the one the received the right click event.


Take a look at the context menu's 'SourceControl' property. This
property will contain a reference to the control the context menu was
shown on.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5
Herfried,

Thanks I could not find it in the object,

Cor
Nov 21 '05 #6
Well Cor, I got your code working great. Thanks. I do have a question
though. I also use the mouse_enter and mouse_leave events for each of my
label. Since the labels usually have the same backcolor as the background,
on mouse_enter I write the current backcolor to a variable then change it to
something different (it makes it easier to find the edges to resize). Then
on mouse_leave I set the original backcolor back by retreiving it from the
variable.
I tried adding the following handlers:
AddHandler lbl.MouseEnter, AddressOf Label_MouseEnte r

AddHandler lbl.MouseLeave, AddressOf Label_MouseLeav e

However, I get error something about deligates not being the same. How do I
add the handlers the use them in the subs?

Thanks and hope to hear from you,
John


"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:uI******** ******@TK2MSFTN GP09.phx.gbl...
John,

I think that it is because the label get never focus.

I once made this sample special for your however never got any reaction.

You can try it again, because a sample how to do the things you ask now and some more things I have in added in it.

The only thing it needs is open a new project, delete all code and paste
this what is below in.

I hope this helps.

Cor

\\\
Public Class Form1
Inherits System.Windows. Forms.Form
Public Sub New()
MyBase.New()
InitializeCompo nent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
Friend WithEvents ContextMenu1 As System.Windows. Forms.ContextMe nu
Friend WithEvents mnuAdd As System.Windows. Forms.MenuItem
Friend WithEvents mnuRemove As System.Windows. Forms.MenuItem
Private Sub InitializeCompo nent()
Me.components = New System.Componen tModel.Containe r
Me.myToolTip = New System.Windows. Forms.ToolTip(M e.components)
Me.ContextMenu1 = New System.Windows. Forms.ContextMe nu
Me.mnuAdd = New System.Windows. Forms.MenuItem
Me.mnuRemove = New System.Windows. Forms.MenuItem
Me.ContextMenu1 .MenuItems.AddR ange(New
System.Windows. Forms.MenuItem( ) _
{Me.mnuAdd, Me.mnuRemove})
Me.mnuAdd.Index = 0
Me.mnuAdd.Text = "Add"
Me.mnuRemove.In dex = 1
Me.mnuRemove.Te xt = "Remove"
Me.Name = "Form1"
End Sub
Private components As System.Componen tModel.IContain er
Private mouseX, mouseY As Integer
Private arLabels As New ArrayList
Private myToolTip As ToolTip
Private createdLabels As Integer
Private myMousedown As String
Private Lastlabel As Label
Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
CreateLabel("Se e Tooltip")
End Sub
Private Sub CreateLabel(ByV al LabelText As String)
Me.ClientSize = New System.Drawing. Size(400, 400)
Dim lbl As New Label
createdLabels = +1
lbl.Name = "Label" & createdLabels.T oString
Dim lblY As Integer = 100
lbl.Location = New System.Drawing. Point(100, lblY)
lbl.ForeColor = Color.Red
lbl.BackColor = Color.Transpare nt
lbl.TextAlign = ContentAlignmen t.MiddleCenter
lbl.Text = LabelText
lbl.ContextMenu = ContextMenu1
AddHandler lbl.MouseDown, AddressOf Label_MouseDown
AddHandler lbl.MouseUp, AddressOf Label_MouseUp
AddHandler lbl.MouseMove, AddressOf Label_MouseMove
lblY += 30
Me.Controls.Add (lbl)
lbl.BringToFron t()
End Sub
Private Sub Label_MouseDown (ByVal sender As Object, ByVal _
e As System.Windows. Forms.MouseEven tArgs)
Lastlabel = DirectCast(send er, Label)
myMousedown = Lastlabel.Name
Lastlabel.Bring ToFront()
mouseX = Cursor.Position .X - Lastlabel.Locat ion.X
mouseY = Cursor.Position .Y - Lastlabel.Locat ion.Y
Lastlabel.Curso r = Cursors.Hand
End Sub
Private Sub Label_MouseUp(B yVal sender As Object, ByVal e As _
System.Windows. Forms.MouseEven tArgs)
Dim lbl As Label = DirectCast(send er, Label)
myMousedown = ""
lbl.Cursor = Cursors.Default
End Sub
Private Sub Label_MouseMove (ByVal sender As Object, ByVal e _
As System.Windows. Forms.MouseEven tArgs)
Dim lbl As Label = DirectCast(send er, Label)
Static LastCursor As Point
Dim NowCursor As Point = New Point(Cursor.Po sition.X,
Cursor.Position .Y)
If Point.op_Inequa lity(NowCursor, LastCursor) Then
If myMousedown = lbl.Name Then
lbl.Location = New System.Drawing. Point(Cursor.Po sition.X _ - mouseX, Cursor.Position .Y - mouseY)
End If
LastCursor = Cursor.Position
lbl.Text = "Right Click me"
myToolTip.SetTo olTip(lbl, _
lbl.Location.X. ToString & "." & lbl.Location.Y. ToString)
End If
End Sub
Private Sub mnuAdd_Click(By Val sender As Object, _
ByVal e As System.EventArg s) Handles mnuAdd.Click
CreateLabel("Mo ve me away")
End Sub
Private Sub mnuRemove_Click (ByVal sender As Object, _
ByVal e As System.EventArg s) Handles mnuRemove.Click
Me.Controls.Rem ove(Lastlabel)
End Sub
End Class
///

Nov 21 '05 #7
WOW, I think I got it. Only took 2 hours of trying. See, some of us are
fffaaarrrr below your level.

LOL,
John

"jcrouse" <me> wrote in message news:e1******** *****@TK2MSFTNG P11.phx.gbl...
Well Cor, I got your code working great. Thanks. I do have a question
though. I also use the mouse_enter and mouse_leave events for each of my
label. Since the labels usually have the same backcolor as the background,
on mouse_enter I write the current backcolor to a variable then change it to something different (it makes it easier to find the edges to resize). Then
on mouse_leave I set the original backcolor back by retreiving it from the
variable.
I tried adding the following handlers:
AddHandler lbl.MouseEnter, AddressOf Label_MouseEnte r

AddHandler lbl.MouseLeave, AddressOf Label_MouseLeav e

However, I get error something about deligates not being the same. How do I add the handlers the use them in the subs?

Thanks and hope to hear from you,
John


"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:uI******** ******@TK2MSFTN GP09.phx.gbl...
John,

I think that it is because the label get never focus.

I once made this sample special for your however never got any reaction.

You can try it again, because a sample how to do the things you ask now and
some more things I have in added in it.

The only thing it needs is open a new project, delete all code and paste
this what is below in.

I hope this helps.

Cor

\\\
Public Class Form1
Inherits System.Windows. Forms.Form
Public Sub New()
MyBase.New()
InitializeCompo nent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
Friend WithEvents ContextMenu1 As System.Windows. Forms.ContextMe nu
Friend WithEvents mnuAdd As System.Windows. Forms.MenuItem
Friend WithEvents mnuRemove As System.Windows. Forms.MenuItem
Private Sub InitializeCompo nent()
Me.components = New System.Componen tModel.Containe r
Me.myToolTip = New System.Windows. Forms.ToolTip(M e.components)
Me.ContextMenu1 = New System.Windows. Forms.ContextMe nu
Me.mnuAdd = New System.Windows. Forms.MenuItem
Me.mnuRemove = New System.Windows. Forms.MenuItem
Me.ContextMenu1 .MenuItems.AddR ange(New
System.Windows. Forms.MenuItem( ) _
{Me.mnuAdd, Me.mnuRemove})
Me.mnuAdd.Index = 0
Me.mnuAdd.Text = "Add"
Me.mnuRemove.In dex = 1
Me.mnuRemove.Te xt = "Remove"
Me.Name = "Form1"
End Sub
Private components As System.Componen tModel.IContain er
Private mouseX, mouseY As Integer
Private arLabels As New ArrayList
Private myToolTip As ToolTip
Private createdLabels As Integer
Private myMousedown As String
Private Lastlabel As Label
Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
CreateLabel("Se e Tooltip")
End Sub
Private Sub CreateLabel(ByV al LabelText As String)
Me.ClientSize = New System.Drawing. Size(400, 400)
Dim lbl As New Label
createdLabels = +1
lbl.Name = "Label" & createdLabels.T oString
Dim lblY As Integer = 100
lbl.Location = New System.Drawing. Point(100, lblY)
lbl.ForeColor = Color.Red
lbl.BackColor = Color.Transpare nt
lbl.TextAlign = ContentAlignmen t.MiddleCenter
lbl.Text = LabelText
lbl.ContextMenu = ContextMenu1
AddHandler lbl.MouseDown, AddressOf Label_MouseDown
AddHandler lbl.MouseUp, AddressOf Label_MouseUp
AddHandler lbl.MouseMove, AddressOf Label_MouseMove
lblY += 30
Me.Controls.Add (lbl)
lbl.BringToFron t()
End Sub
Private Sub Label_MouseDown (ByVal sender As Object, ByVal _
e As System.Windows. Forms.MouseEven tArgs)
Lastlabel = DirectCast(send er, Label)
myMousedown = Lastlabel.Name
Lastlabel.Bring ToFront()
mouseX = Cursor.Position .X - Lastlabel.Locat ion.X
mouseY = Cursor.Position .Y - Lastlabel.Locat ion.Y
Lastlabel.Curso r = Cursors.Hand
End Sub
Private Sub Label_MouseUp(B yVal sender As Object, ByVal e As _
System.Windows. Forms.MouseEven tArgs)
Dim lbl As Label = DirectCast(send er, Label)
myMousedown = ""
lbl.Cursor = Cursors.Default
End Sub
Private Sub Label_MouseMove (ByVal sender As Object, ByVal e _
As System.Windows. Forms.MouseEven tArgs)
Dim lbl As Label = DirectCast(send er, Label)
Static LastCursor As Point
Dim NowCursor As Point = New Point(Cursor.Po sition.X,
Cursor.Position .Y)
If Point.op_Inequa lity(NowCursor, LastCursor) Then
If myMousedown = lbl.Name Then
lbl.Location = New

System.Drawing. Point(Cursor.Po sition.X _
- mouseX, Cursor.Position .Y - mouseY)
End If
LastCursor = Cursor.Position
lbl.Text = "Right Click me"
myToolTip.SetTo olTip(lbl, _
lbl.Location.X. ToString & "." & lbl.Location.Y. ToString)
End If
End Sub
Private Sub mnuAdd_Click(By Val sender As Object, _
ByVal e As System.EventArg s) Handles mnuAdd.Click
CreateLabel("Mo ve me away")
End Sub
Private Sub mnuRemove_Click (ByVal sender As Object, _
ByVal e As System.EventArg s) Handles mnuRemove.Click
Me.Controls.Rem ove(Lastlabel)
End Sub
End Class
///


Nov 21 '05 #8
John,

2 hours learing time, what is wrong with that.

I looked again at the sample and changed it again a little bit, there is
some orphaned code in it. However I think that will be in every program.

With persons as you I "had" to answer in an hour.

(What I do in those situations you ask is set a label on a form, create the
event with the IDE and than remove the handler in the by the IDE created
code, I am lazy as well)

:-)

Cor

\\\
Public Class Form1
Inherits System.Windows. Forms.Form
Public Sub New()
MyBase.New()
InitializeCompo nent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
Friend WithEvents ContextMenu1 As System.Windows. Forms.ContextMe nu
Friend WithEvents mnuAdd As System.Windows. Forms.MenuItem
Friend WithEvents mnuRemove As System.Windows. Forms.MenuItem
Private Sub InitializeCompo nent()
components = New System.Componen tModel.Containe r
myToolTip = New System.Windows. Forms.ToolTip(M e.components)
ContextMenu1 = New System.Windows. Forms.ContextMe nu
mnuAdd = New System.Windows. Forms.MenuItem
mnuRemove = New System.Windows. Forms.MenuItem
ContextMenu1.Me nuItems.AddRang e(New System.Windows. Forms.MenuItem( )
_
{Me.mnuAdd, Me.mnuRemove})
Me.mnuAdd.Text = "Add"
Me.mnuRemove.Te xt = "Remove"
End Sub
Private components As System.Componen tModel.IContain er
Private mouseX, mouseY As Integer
Private myToolTip As ToolTip
Private LabelMouseDown As Label
Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
CreateLabel("Se e Tooltip")
End Sub
Private Sub CreateLabel(ByV al LabelText As String)
Me.ClientSize = New System.Drawing. Size(400, 400)
Dim lbl As New Label
lbl.Location = New System.Drawing. Point(100, 100)
lbl.ForeColor = Color.Red
lbl.BackColor = Color.Transpare nt
lbl.TextAlign = ContentAlignmen t.MiddleCenter
lbl.Text = LabelText
lbl.ContextMenu = ContextMenu1
AddHandler lbl.MouseDown, AddressOf Label_MouseDown
AddHandler lbl.MouseUp, AddressOf Label_MouseUp
AddHandler lbl.MouseMove, AddressOf Label_MouseMove
Me.Controls.Add (lbl)
lbl.BringToFron t()
End Sub
Private Sub Label_MouseDown (ByVal sender As Object, ByVal _
e As System.Windows. Forms.MouseEven tArgs)
LabelMouseDown = DirectCast(send er, Label)
LabelMouseDown = LabelMouseDown
LabelMouseDown. BringToFront()
mouseX = Cursor.Position .X - LabelMouseDown. Location.X
mouseY = Cursor.Position .Y - LabelMouseDown. Location.Y
LabelMouseDown. Cursor = Cursors.Hand
End Sub
Private Sub Label_MouseUp(B yVal sender As Object, ByVal e As _
System.Windows. Forms.MouseEven tArgs)
Dim lbl As Label = DirectCast(send er, Label)
LabelMouseDown = Nothing
lbl.Cursor = Cursors.Default
End Sub
Private Sub Label_MouseMove (ByVal sender As Object, ByVal e _
As System.Windows. Forms.MouseEven tArgs)
Dim lbl As Label = DirectCast(send er, Label)
Static LastCursor As Point
Dim NowCursor As Point = New Point(Cursor.Po sition.X,
Cursor.Position .Y)
If Point.op_Inequa lity(NowCursor, LastCursor) Then
If LabelMouseDown Is lbl Then
lbl.Location = New System.Drawing. Point(Cursor.Po sition.X _
- mouseX, Cursor.Position .Y - mouseY)
End If
LastCursor = Cursor.Position
lbl.Text = "Right Click me"
myToolTip.SetTo olTip(lbl, _
lbl.Location.X. ToString & "." & lbl.Location.Y. ToString)
End If
End Sub
Private Sub mnuAdd_Click(By Val sender As Object, _
ByVal e As System.EventArg s) Handles mnuAdd.Click
CreateLabel("Mo ve me away")
End Sub
Private Sub mnuRemove_Click (ByVal sender As Object, _
ByVal e As System.EventArg s) Handles mnuRemove.Click
Me.Controls.Rem ove(ContextMenu 1.SourceControl )
End Sub
End Class
///

Nov 21 '05 #9

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

Similar topics

7
3558
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET) template. Briefly -------------------------------------------------------------------------------------------- I need to create dynamically some controls on the forms, and display these
16
7238
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
0
2325
by: Mark Johnson | last post by:
Sometimes Controls that have been added to a GroupBox do not show up. What I am doing : 1) I am not using the designer, but create all the Controls per hand: groupBoxProdukt_01 = new System.Windows.Forms.GroupBox(); etc. for all other Controls. After setting Font and Text values I then add them to the Panel: pnPanelControls.Controls.Add(groupBoxProdukt_01); pnPanelControls.Controls.Add(groupBoxProdukt_02);...
3
4050
by: Roger | last post by:
Hi In a Windows forms application I have 2 forms A and B; Form B inherits from form A. Form A is never displayed and its only purpose is to be inherited from and therefore contains mostly public/protected methods that I have created (as well a few controls that inheriting forms may use). In my method on form A (public virtual void setcontrols()) I need a list of all controls on the instantiated form (in this example form B). Form B has a...
1
2135
by: Robert Howells | last post by:
Perhaps I'm just too new at this to pull it off, or perhaps it's just bad architecture. I'd appreciate some feedback on the the wisdom (or lack thereof) in attempting the following: I'm not new to programming, but I am new to ASP.NET and Web application design in general... loved the concept of user controls and dynamically adding them to a page. So what I wound up with was an application that dynamically loads two user controls directly...
66
4146
by: Cor | last post by:
Hi, I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever. It started by an example from me, that was far from complete and with typing errors, but basically it had the meaning to show that removing controls reversible was the nicest method. This was a lets say conclusion (but what is that in a newsgroup) in a...
7
2477
by: Mike Bulava | last post by:
I have created a base form that I plan to use throughout my application let call the form form1. I have Built the project then add another form that inherits from form1, I add a few panel controls each with a couple of controls in them I then rebuilt my project and my new panels and all controls they contained are gone... I've looked through the Auto generated code but don't see anything that looks wrong Any body have any idea why this...
15
2195
by: Arpan | last post by:
Consider the following code which retrieves data from a SQL Server 2005 DB table & displays it in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) Dim dSet As DataSet Dim sqlConn As SqlConnection Dim sqlDapter As SqlDataAdapter sqlConn = New SqlConnection("Data Source=AD\SQLEXPRESS;Initial
8
3590
by: Ryan | last post by:
Ok.. I have a form with lots of stuff on it; a tool strip panel, menu strip, data binding elements (dataset, binding source, table adapter), tab control with 7 tab pages, each page contains a picture box, lots of text boxes (for input).. you get the idea. All of a sudden everything on the form has disappeared, it looks like a blank, newly created form. I can still get to the properties of every item on the form using the drop-down box in...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4009
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.