Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / May 2005

Tip: Looking for answers? Try searching our database.

how to inherit LinkLabel control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael Palmer - 03 May 2005 17:07 GMT
I'm trying to inherit/extend the standard LinkLabel control so I can add a
couple of additional things to it... but, I can't get it to display on any
forms. Do I need a custom designer? What am I missing? Here's my code...

Public Class HoverLinkLabel

Inherits System.Windows.Forms.LinkLabel

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'UserControl overrides dispose to clean up the component list.

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

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

#End Region

Private _hoverColor As Color = ControlsHelper.GetHoverLinkColor

Private _linkColor As Color = Me.LinkColor

Public Property HoverColor() As Color

Get

Return _hoverColor

End Get

Set(ByVal Value As Color)

_hoverColor = Value

End Set

End Property

Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)

MyBase.OnMouseEnter(e)

Me.LinkColor = _hoverColor

End If

End Sub

Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)

MyBase.OnMouseLeave(e)

Me.LinkColor = _linkColor

End If

End Sub

End Class
Tim Wilson - 03 May 2005 17:31 GMT
The code you posted has some compilation issues. But here is the modified
code that I used and it seemed to work as expected.

Public Class HoverLinkLabel
 Inherits System.Windows.Forms.LinkLabel

 Public Sub New()
   MyBase.New()
 End Sub

 Private _hoverColor As Color = MyBase.LinkColor
 Private _linkColor As Color = MyBase.LinkColor

Public Property HoverColor() As Color
 Get
   Return _hoverColor
 End Get
 Set(ByVal Value As Color)
   _hoverColor = Value
 End Set
End Property

 Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
   MyBase.OnMouseEnter(e)
   Me.LinkColor = _hoverColor
 End Sub

 Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
   MyBase.OnMouseLeave(e)
   Me.LinkColor = _linkColor
 End Sub
End Class

Signature

Tim Wilson
.Net Compact Framework MVP

Michael Palmer - 04 May 2005 14:40 GMT
Hi Tim... thanks for your reply. The compilation issue stems from a missing
ControlsHelper class. I failed to remove that before posting. The problem I
was having was that VS.NET wasn't letting me put my derived LinkLabel
control onto a form. But... using the same code, I'm able to choose the
control from within another project. Weird.... it won't show up in the
toolbox like my other controls unless I force it to. Then, when I try to
insert it in a form, it simply does nothing. VS won't draw it on a form.
So.... I don't know what's wrong. None of my other controls have this
problem. But....luckily I'm able to use it from my other project, which is
how I need it anyway.

Thanks for your input, I appreciate it.

-Michael

> The code you posted has some compilation issues. But here is the modified
> code that I used and it seemed to work as expected.
[quoted text clipped - 28 lines]
>  End Sub
> End Class
"Jeffrey Tan[MSFT]" - 06 May 2005 07:14 GMT
Hi Michael,

Have you tried Tim's modified sample code? Does your problem still go with
Tim's sample code?
Currently, I suggest you create a new project and paste your sample code,
does this problem occur? Also, you may test your project on some other
machines. Does this problem go away?

With these tests, we can determine if this problem is machine-specific or
project-specific. If you have any further concern, please feel free to
feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

joeycalisay - 04 May 2005 05:34 GMT
were you able to add it in the toolbox?

Signature

Joey Calisay
http://spaces.msn.com/members/joeycalisay/

> I'm trying to inherit/extend the standard LinkLabel control so I can add a
> couple of additional things to it... but, I can't get it to display on any
[quoted text clipped - 93 lines]
>
> End Class
Michael Palmer - 04 May 2005 14:41 GMT
Hey Joey...

The control won't show up in the toolbox by itself like other custom
controls do... I'm not sure why. I have to explicitly add it. Any idea why?

> were you able to add it in the toolbox?
>
[quoted text clipped - 98 lines]
>>
>> End Class
joeycalisay - 05 May 2005 01:13 GMT
Only UserControls within the same solution shows up at the ToolBox
(UserControl) Section.  If you are developing your own control, you have to
add it explicitly browsing to the assembly (DLL) containing the control and
selecting it from the list.

Signature

Joey Calisay
http://spaces.msn.com/members/joeycalisay/

> Hey Joey...
>
[quoted text clipped - 103 lines]
> >>
> >> End Class

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.