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:(E-Mail Removed)...
> 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_MouseEnter
>
> AddHandler lbl.MouseLeave, AddressOf Label_MouseLeave
>
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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()
> > InitializeComponent()
> > 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
> > Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
> > Friend WithEvents mnuAdd As System.Windows.Forms.MenuItem
> > Friend WithEvents mnuRemove As System.Windows.Forms.MenuItem
> > Private Sub InitializeComponent()
> > Me.components = New System.ComponentModel.Container
> > Me.myToolTip = New System.Windows.Forms.ToolTip(Me.components)
> > Me.ContextMenu1 = New System.Windows.Forms.ContextMenu
> > Me.mnuAdd = New System.Windows.Forms.MenuItem
> > Me.mnuRemove = New System.Windows.Forms.MenuItem
> > Me.ContextMenu1.MenuItems.AddRange(New
> > System.Windows.Forms.MenuItem() _
> > {Me.mnuAdd, Me.mnuRemove})
> > Me.mnuAdd.Index = 0
> > Me.mnuAdd.Text = "Add"
> > Me.mnuRemove.Index = 1
> > Me.mnuRemove.Text = "Remove"
> > Me.Name = "Form1"
> > End Sub
> > Private components As System.ComponentModel.IContainer
> > 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(ByVal sender As Object, _
> > ByVal e As System.EventArgs) Handles MyBase.Load
> > CreateLabel("See Tooltip")
> > End Sub
> > Private Sub CreateLabel(ByVal LabelText As String)
> > Me.ClientSize = New System.Drawing.Size(400, 400)
> > Dim lbl As New Label
> > createdLabels = +1
> > lbl.Name = "Label" & createdLabels.ToString
> > Dim lblY As Integer = 100
> > lbl.Location = New System.Drawing.Point(100, lblY)
> > lbl.ForeColor = Color.Red
> > lbl.BackColor = Color.Transparent
> > lbl.TextAlign = ContentAlignment.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.BringToFront()
> > End Sub
> > Private Sub Label_MouseDown(ByVal sender As Object, ByVal _
> > e As System.Windows.Forms.MouseEventArgs)
> > Lastlabel = DirectCast(sender, Label)
> > myMousedown = Lastlabel.Name
> > Lastlabel.BringToFront()
> > mouseX = Cursor.Position.X - Lastlabel.Location.X
> > mouseY = Cursor.Position.Y - Lastlabel.Location.Y
> > Lastlabel.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 = "Right Click me"
> > myToolTip.SetToolTip(lbl, _
> > lbl.Location.X.ToString & "." & lbl.Location.Y.ToString)
> > End If
> > End Sub
> > Private Sub mnuAdd_Click(ByVal sender As Object, _
> > ByVal e As System.EventArgs) Handles mnuAdd.Click
> > CreateLabel("Move me away")
> > End Sub
> > Private Sub mnuRemove_Click(ByVal sender As Object, _
> > ByVal e As System.EventArgs) Handles mnuRemove.Click
> > Me.Controls.Remove(Lastlabel)
> > End Sub
> > End Class
> > ///
> >
> >
> >
>
>
|