-
2 Attachment(s)
Label control that supports hyperlinks, different colors and font styles
I've created a control that can be used as a replacement for the regular VB Label control. This HyperLabel control supports a mixture of regular text and hyperlinks. The hyperlinks shows the hand cursor when the mouse is hovering over them and can also automatically navigate to that link if the AutoNavigate property is set to True, otherwise a HyperlinkClick event is raised and you can write your own logic of what should happen when the user click on a hyperlink. This could for example be to open a dialog box, show a help file, or anything else you can think of.
This is however not all this control can do. It supports a mixture of different font styles like bold, italic, and underlined text. You can also use different colors for different words. Moreover you can also create bullet lists inside the control.
This is done by simply using BBTags (the same kind of tags you use to format text in different forums, like this one) inside the Caption property. The supported tags are (without the spaces between the brackets):
[ b ] bold [ /b ]
[ i ] italic [ /i ]
[ u ] underline [ /u ]
[ color = #RRGGBB ] colored text [ /color] - Can also used these named color constants: black, white, red, green, blue, yellow, magenta, and cyan.
[ url=http://www.vbforums.com ] hyperlink [ /url ]
[ list ][*] bullet list.[*] item 2 [ /list ]
[ ] - Empty tag (no space) = NewLine
The fact that you can use an empty tag to create a newline inside the Caption allows for faster assignment of text since you don't need to use the slow concatenation operation of different strings just to insert a line break.
The control is very light-weight and competly user-drawn (it doesn't contain any constituent controls). If you like you can even make it even lighter by setting the WindowLess property of the UserControl to True, however you'll need to remove the BorderStyle property for that.
The attached ZIP file contains a project group with the HyperLabel control and a demo project that shows the different properties and events. Please also take the time to read the short Help.txt file for complete information about the control. To try it out simply open the gHyperLabelTest.vbg project group file.
Here's a screenshot of the demo application (the image got a bit blurred when I used MS Paint to convert it to a JPG but you'll get the idea).
Please note that this demo have the RenderToContainer property set to True and the Visible property set to False (see post #7 below). You must change that for the BackColor and BorderStyle properties to work.
http://www.vbforums.com/attachment.p...id=44115&stc=1
-
Re: Label control that supports hyperlinks, different colors and font styles
New version added in original post above. Fixed a minor bug + added an AutoSize property.
-
Re: Label control that supports hyperlinks, different colors and font styles
can i also use this in Data report of VB?
thanks,
alexis
-
Re: Label control that supports hyperlinks, different colors and font styles
I don't think so since the VB Data report has its own set of controls. You can't add any of the other VB intrinsic controls since you must use the ones designed for the Date Report designer. But since I never use this designer I'm not 100% sure.
-
Re: Label control that supports hyperlinks, different colors and font styles
-
Re: Label control that supports hyperlinks, different colors and font styles
-
Re: Label control that supports hyperlinks, different colors and font styles
This control has just been updated. Since many people wanted a transparent background, I've added a property called RenderToContainer. This property is only available at run-time. By setting it to True, the Caption will be drawn on the containing Form (or PictureBox), please note that this will only work if the control is contained on a Form or PictureBox. If not the property will not change value and still be False (no errors will occure).
So if you want a transparent control, use this as you normally would, then set the RenderToContainer property to True and also set the Visible property to False, to hide the control. Voila, the caption is drawn directly on the containing Form. The hyperlinks still works as usual. However there is a couple of things you should be aware of: First, the control will change the MouseIcon property of the Form or PictureBox (if the RenderToContainer property is set to True). Also it will clear the Form (or PictureBox) by calling the Cls method, so if you draw your own text you must do that after changing the Caption of the control.
-
Re: Label control that supports hyperlinks, different colors and font styles
Looks like something that I'd like to use but the Backcolor button doesn't change the backcolor of the HyperLabel and the BorderStyle doesn't seem to work.
-
Re: Label control that supports hyperlinks, different colors and font styles
That's because the sample app sets the RenderToContainer property to True and hides the control. Change that and you'll see that both the BackColor and BorderStyle properties will work just fine.
-
Re: Label control that supports hyperlinks, different colors and font styles
Using the test project as is (with RenderToContainer = True), the HyperLabel is displayed and as I posted the backcolor and border don't work. When I change RenderToContainer to False, the HyperLabel doesn't display at all so I can't tell anything about the backcolor and border.
-
Re: Label control that supports hyperlinks, different colors and font styles
RenderToContainer means that everything is printed directly to the Form instead of to the control. Set the Visible property to True to see the control during run-time :)
-
Re: Label control that supports hyperlinks, different colors and font styles
Yes that does it but it sure isn't intuative that you aren't actually looking at the label when you run the project as-is.
-
Re: Label control that supports hyperlinks, different colors and font styles
I know, I updated it a while back (see post #7 above) and that's when I added the RenderToContainer property and I wanted the demo to reflect that. This was the simpliest way I could create the label with a transparant background... by simply not using the control itself :).
I've edited my initial post to point this out.
-
Re: Label control that supports hyperlinks, different colors and font styles
Nice control!
I added an [IMG] tag to it so it can download and display pictures too. :)
Thanks!
-
Re: Label control that supports hyperlinks, different colors and font styles
Quote:
Originally Posted by Edgemeal
Nice control!
I added an [IMG] tag to it so it can download and display pictures too. :)
Thanks!
That's pretty nice :) Would you consider uploading your changes?
-
1 Attachment(s)
Re: Label control that supports hyperlinks, different colors and font styles
Quote:
Would you consider uploading your changes?
OK but it's just a basic addition, just to see if it was possible.
One problem tho, if .RenderToContainer = True and the control is resized the images tend to flicker, though I'm using it as a forum post previewer and have .RenderToContainer = False and seems to work fine for my needs.
-
Re: Label control that supports hyperlinks, different colors and font styles
Joacim, just a quick question. Can I use hyperlinked text to open another form in the same program at runtime? E.G. I AM ON FORM1 AND I WANT THE HYPERLINKED TEXT TO TAKE ME TO FORM 2.
-
Re: Label control that supports hyperlinks, different colors and font styles
Yes, just set the AutoNavigate property to False and show Form2 in the HyperlinkClick event.
-
Re: Label control that supports hyperlinks, different colors and font styles
Thanks Joacim. Another problem has cropped up. I make a HyperLabel transparent (RenderToContainer = true, Visible = false). Now I change the HyperLabel's font. The problem is that at runtime, the HyperLabel still has the default font, which is MS Sans Serif! Any ideas on how to get around this problem?
-
Re: Label control that supports hyperlinks, different colors and font styles
In the HyperLabel.ctl change the Set Font property to this:
Code:
Property Set Font(ByVal oNew As StdFont)
Set m_Font = oNew
Set UserControl.Font = oNew
If Not oRender Is Nothing Then
oRender.Font = oNew
End If
DrawCaption
PropertyChanged "Font"
End Property
Also add the following lines to the bottom of the Let RenderToContainer property procedure:
Code:
If Not oRender Is Nothing Then
Set oRender.Font = UserControl.Font
End If
-
Re: Label control that supports hyperlinks, different colors and font styles
Thanks again, Joacim. Another question:
In one HyperLabel, I have some hyperlinked text. As you suggested to me before, I changed the HyperlinkClick Event so that I could open another form. What I want to do now is to add some more hyperlinked text in the same HyperLabel, which will allow me to open a different form. I am thinking of an IF Statement - How should I do this?
-
Re: Label control that supports hyperlinks, different colors and font styles
The hyperlink tag looks as this (without spaces): [ url=SomeURL ]SomeText[ /url ]. The SomeURL can be any text (without spaces) and the HyperlinkClick event will recieve that text as an argument. So you could for example have this text:
Code:
Click [ url=MyConfig ]here[ /url ] to open the Configuration and [ url=MyOption ]here[ /url ] to open the Options.
In the HyperlinkClick event you could then do something like this:
Code:
Private Sub HyperLabel1_HyperlinkClick(ByVal URL As String)
Select Case URL
Case "MyConfig"
frmConfig.Show
Case "MyOption"
frmOption.Show
End Select
End Sub
-
Re: Label control that supports hyperlinks, different colors and font styles
Yay! That worked. I decided to add another HyperLabel to my Form. I need them both to be transparent so I did that. However, the new HyperLabel is acting strangely e.g. it loses its transparency and does not display any text at all - it does nothing. This only happens when I have two HyperLabels in one form. Any idea how to sort this out, Joacim?
Sorry Joacim, I'll explain it the problem more clearly. When I add a second HyperLabel to my Form, then it doesn't function properly. This means that the second HyperLabel doesn't display text, doesn't show transparency, etc.
Any ideas on how to sort this problem out?
-
Re: Label control that supports hyperlinks, different colors and font styles
hi i need too add HyperLabel as colored Logger in my project but its based on label and label cant scroll as i know
how can i do that guys???
-
Re: Label control that supports hyperlinks, different colors and font styles
-
Re: Label control that supports hyperlinks, different colors and font styles
thank you MartinLiss its awesome i combine two controls and result is my favorite but how about auto scrolling how can i doing for that??
-
Re: Label control that supports hyperlinks, different colors and font styles
Please define 'auto scrolling'.
-
Re: Label control that supports hyperlinks, different colors and font styles
scroll down to bottom of text without need to drag thumb of scroller
-
Re: Label control that supports hyperlinks, different colors and font styles
Okay I need to ask another question. Do you want it to scroll by way of the mouse? If not then please describe when and how you want it to scroll.
-
1 Attachment(s)
Re: Label control that supports hyperlinks, different colors and font styles
I made some changes to the ScrollableLabel control and added a MaxValue and Value property. MaxValue is read-only. To scroll to the bottom via code simply set the Value property to the MaxValue property during run-time. (See the code in the new command button I added to the form).
-
Re: Label control that supports hyperlinks, different colors and font styles
thank you Joacim its completely solve my issue i shared combined of these code together and attach it here soon
P.S:
this forum is awesome :)
-
Re: Label control that supports hyperlinks, different colors and font styles
Oh boy! This is just what I needed, Thank you!
Please excuse my ignorance however:
I have added the Hyperlabel.ocx to VB6 and can add a hyperlabel but right clicking the new hyperlabel
exposes a menu but has no properties menu selection. Should it? Or do I have to change all the hyperlabel properties at runtime?
Thanks so much.
:Ron Anderson
-
1 Attachment(s)
Re: Label control that supports hyperlinks, different colors and font styles
It doesn't have property pages but you can still set all the properties during design time in the property window (press the F4 key if you don't see it).
-
Re: Label control that supports hyperlinks, different colors and font styles
Tusen Tack!
This is going to be so cool!
:thumb:
-
Re: Label control that supports hyperlinks, different colors and font styles
Now that we have this for VB, has anyone seem something similar for the Vc 200x static text control?
I have some dialogs in C++ that cold use some sprucing up.
-
Re: Label control that supports hyperlinks, different colors and font styles
Hi Joacim,
I finally got around to replacing the labels on a form that are in a label array
of 40 items.
I created one hyperlabel and set it's attributes as I wanted them. Then I created another so that vb6 would create an array, but all other labels created after the first one in the array show no caption text in design mode.
Does Hyperlabel support vb6 arrays?
My app is obviously old code but works as is just needing some more juice. :)
Thanks,
:Ron Anderson
-
1 Attachment(s)
Re: Label control that supports hyperlinks, different colors and font styles
-
Re: Label control that supports hyperlinks, different colors and font styles
Ok thanks.
I'll try harder. :-)
-
Re: Label control that supports hyperlinks, different colors and font styles
Would center alignment be too much to ask for? :blush:
I have it working by the way.
And I like it a bunch!
But I do need center alignment in the worst way.
:Ron
-
Re: Label control that supports hyperlinks, different colors and font styles
Sorry, it's almost 6 years since I wrote this and I don't even have VB6 installed on my computer anymore since I use VB.Net and C#. But you have the source code so you can try to implement it yourself. Since it might use different font styles it's not as easy though.
-
Re: Label control that supports hyperlinks, different colors and font styles
I have it sorted.
I ended up doing the center alignment at runtime in the form that uses the hyperlabel as try as I might, I cannot get my head around how to align what nothing within something as I have never done an ocx custom control.
-
Re: Label control that supports hyperlinks, different colors and font styles
Hi Joacim,
Long time no pester! :wave:
I finished my form with hyperlabels in it.
The form is compiled down to an ActiveX exe file.
It has worked like a charm on the xp32 development machine but when I installed it on a fresh xp32 box the .exe object would not create. CoCreateInstance was returning Unknown Facility of all things but would show up in task manager.
This Activex exe when previous to it's hyperlabel upgrade been portable with no dependencies. After chasing the problem for days with no change, I replaced the ActiveX exe with one from the day before hyperlabel. This version has plain vanilla labels where the hyperlabels are on the non portable one.
And it runs. CoCreateInstance returns S_OK
While I know this doesn't mean that hyperlabel is the culprit, I thought I would see if you had any insight.
Btw. I have tried hand registering hyperlbl.ocx on the target box but it's did not change things.
Thanks.
:Ron Anderson
-
Re: Label control that supports hyperlinks, different colors and font styles
Instead of compiling the label to an ocx, just add the source code files to your project.
-
Re: Label control that supports hyperlinks, different colors and font styles
Firstly Joacim, thank you for watching this old thread.
I found out that my problem had nothing to do with hyperlabel but did try to include the source files into my project anyway. I added the Hyperlink.cls file to the classes folder and adding the Hyperlabel.ctl created the expected user control folder with it inside. It compiles to a size that reflects the addition of the hyperlink code alright, but if I place that compiled activex exe on a virgin machine it runs but spits out an vb error 339 that hyperlbl.ocx is not registered or it's dependency is missing. Placing hyperlbl.ocx on the offending machine and registering it takes care of the problem but tells me I am not doing something correct at the first.
Any ideas?
Thanks again.
:Ron Anderson
-
Re: Label control that supports hyperlinks, different colors and font styles
The labels you have on the Form is probably not from the source you added to the project but from the earlier compiled OCX. You need to recreate these and remove the reference you have to the OCX file.
-
Re: Label control that supports hyperlinks, different colors and font styles
I was afraid of that.
Thanks.
-
Re: Label control that supports hyperlinks, different colors and font styles
Quote:
Originally Posted by
Joacim Andersson
It doesn't have property pages but you can still set all the properties during design time in the property window (press the F4 key if you don't see it).
So glad this thread isn't dead!. I have VB5 [waits for laughter to stop...] , have made most VB6 code samples work in VB5, but never worked with making controls until I had to compile the OCX for HyperLabel. It works and really is a great item. I am using Hyperlabel to colorize output from a Folder Watcher program (red for Deletes, green for Adds, blue for Renames, etc in a long string separated by vbCrLf) . I can have it autoresize when the main form is resized, but the visible output is basically limited to the vertical size of the user's screen. It screams out for Scrollbars. I did find something at VBAccellerator that can actually add Scrollbars to forms and controls, even buttons, but Hyperlabel however does not have the required ".hwnd" property. My question is how can I get the .HWND property without using an external app like FindWind.exe. (I assume the Handle could change) I got linked back here searching the internet this morning for How to find the handle of a window or control and just downloaded your other program FindWind.
Tony
-
Re: Label control that supports hyperlinks, different colors and font styles
You can easily add a read-only hWnd property to the source.
Code:
Public Property Get hWnd() As Integer
hWnd = UserControl.hWnd
End Property
-
Re: Label control that supports hyperlinks, different colors and font styles
Thanks for the fast reply! I will try that this week!
-
Re: Label control that supports hyperlinks, different colors and font styles
Thanks for the fast reply! I will try that this week!
=========== reply delayed 2 weeks ==============
Finally added .HWND property. Needed "As Long" like other HWND references, and I ended up giving the OCX a different name. The VB5 IDE and underlying Windows had to have all OCX and OCA references renamed or removed after each attempt. Now I have scrollbars on Hyperlabel and cannot get them to function. I haven't figured out the code the scrollbars need to go thru the Hyperlabel contents. It is basically a long string with each line separated by vbCrLf. The example I saw at VBAccellerator.com didn't have label control, just picturebox and form, so I'm wondering if I have to add something else ( 'way over head now). Hyperlabel1 gets resized when the Form gets resized; that still works. I'm lnow ooking at your re-write of Labelscroller next as a sample to try to get Hyperlabel1.Caption to scroll thru a string.
In checking the old VB5 reference books, it mentions regular Label.Caption can hold only 1024 characters. I need to check Hyperlabel.Caption's capacity. It occurs to me now after an intense few days, that if output will require periodic 'dumping' of data to a file anyway, maybe scrolling shouldn't be that important. Thanks again, I appreciate your help.
-
Re: Label control that supports hyperlinks, different colors and font styles
I stopped counting at 5000 chars for .Caption. So that should be plenty.
-
Re: Label control that supports hyperlinks, different colors and font styles
The HyperLabel doesn't really have a limit on the Caption property as long as the process has memory you could (at least in theory) have as much text as you want (it will probably be terribly slow to process if you get over 64KB of text or so). But in theory you could have close to 2GB of text.
-
Re: Label control that supports hyperlinks, different colors and font styles
(lack of ) progress report. Tried 4 different things.
1) compared original LabelScrol code and tried "interpolating" and combining. Gave up. It's a mess.
2) Downloaded the Labellscroller you had modified. The names in many cases matched those in Hyperlabel and I tried copying relevant Labelscroller sections into HyperlabelWell, and after a few versions it compiles to an OCX without errors but none of the scrollbars actually MOVE the Hyperlabel contents up/down. In fact none of them show the "thumb" (??the square in the middle of the scrollbars you grab.
3) the HWND property is now there in Hyperlabel and I can add the VBAccellerator.com CLS file and actually get scrollbars WITH a thumb. But nothing I have tried since then can get the Hyperlabel.Caption to scroll up or down. Their examples add scrollbars to Form; nothing about controls except picturebox. I don't want to try that as it doesn't 'seem' (what do I know?) to be what I am trying to do.
4) [the easiest] I rearranged the .Caption to always show the latest line of Hyperlabel output at the top. This way I can at least see the 30-40 lines that are most recent. That was the OutOfBox solution that occured to me after a long walk.
Still trying... In my many many internet searches, I have run across many references to "Hyperlabel" and people trying to sell Hyperlabel as shareware by the way.
-
1 Attachment(s)
Re: Label control that supports hyperlinks, different colors and font styles
For about a month, I've been trying to add VScrollbar to Hyperlabel and finally got it. I had gone back to # 2) in a previous msg, giving another try to adapting LabelScroller to HyperLabel. This time instead of adding LabelScroller code TO Hyperlabel, I deleted Label1 (a VB control) from LabelScroller and replaced it with HyperLabel.ctl, changing very little except references to lblMessage. Finally 1003AM 1/4/12 I got some RED text in HyperScroller, along with Vertical scrolling! Doesn't need Horizontal, due to word wrapping.
I am trying to upload a ZIP file with VB5 code used but not the EXE per Forum rules. this is just a demo Project showing that it works.
1) To make HyperScroller, I had to delete the Sub oForm_MouseMove from Hyperlabel. I forget the exact error but it occurs in my VB5 IDE when LOADING the HyperLabel.ctl into the Project. Later testing (not tested in the demo) in my app shows that the URL BB code in HyperLabel works, except
there is no "finger icon" when you hover over the URL. Don't know how to fix this. Not sure how important it is; not for my purposes. I tried moving the Sub from Hyperlabel.ctl to HyperScroller.ctl as a total guess, but didn't work either.
2) hyperlabel.plaincaption does not work in my app. I did not test this in the demo app either, as my last months daily task has been to get my app scrolling with color. I don't know much, but it seems like the m_sPlainCaption variable is not "exposed" where I can use it from my app. If I use Hyperlabel1.PlainCaption in my app, the error is undefined variable. if I use HyperScroller.PlainCaption the error is no such Member.
Again, HyperScroller contains HyperLabel; you need both controls, plus the CHyperlink class in your app. I will have to find a way to manually strip out the brackets and characters inside the brackets.
odd thing: later, when trying to run ActiveX wizard on hyperscroller.ctl (a second time. worked okay first time) get 2 consistent errors: runtime error 5, then automation error 440, then VB5 IDE locks up. It doesn't do this with hyperlabel.ctl, just hyperscroller.ct. Control itself works. I may have broken something in my wizard.
That's my first and probably last major effort at trying to modify Controls. Source code for controls on the internet is very hard to come by.
If there was source code for TextBox, might have been easier to add the BB tags there?
Thanks Joacim for a great control and giving us the source!
-
Re: Label control that supports hyperlinks, different colors and font styles
If you read this far, in your main Form1, this would take the place of .PlainCaption, stripping BBtags from the .Caption. I did not test this in the uploaded demo Project, but in my other Project I needed this:
Private Sub cmdNoTags_Click()
Dim txt As String
'I think .plaincaption has to be 'exported' to hyperscroller.
'txt = HyperScroller1.PlainCaption 'error: Method or data member not found
'txt = HyperScroller1.PlainCaption 'error: Variable not define
'can't compile to EXE, can't save output without BBtags like I used to:
'txt = HyperLabel1.PlainCaption
' WriteFile App.Path & "\filemon.dat", txt
'This would be equivalent of hyperlabel1.plaincaption:
'NOT as it would be difficult and will NOT be a folder name
'NOT [][*] as italic too hard to read. won't be any lists.
txt = HyperScroller1.Caption 'save a copy, operate on the copy
txt = Replace(txt, "[color=black]", "")
txt = Replace(txt, "", "")
txt = Replace(txt, "", "")
txt = Replace(txt, "[color=#0A9C02]", "") 'dark green
txt = Replace(txt, "[color=red]", "")
txt = Replace(txt, "[color=blue]", "")
'test document used magenta, cyan, and green too. white and yellow not likely foreground colors
txt = Replace(txt, "[color=magenta]", "")
txt = Replace(txt, "[color=cyan]", "")
txt = Replace(txt, "", "")
'so far didn't use underline
txt = Replace(txt, "", "")
txt = Replace(txt, "", "")
'didn't use the following, but you never know
txt = Replace(txt, "", "")
WriteFile App.Path & "\filemon.dat", txt
VB6 has a builtin Replace function. You have to add it to VB5 yourself.
-
Re: Label control that supports hyperlinks, different colors and font styles
HyperlabelClick or yet unsupported "disable"?
I love hyperlabel. What a great thing it is.
As is well known, with standard vb6 labels, one can implement click through on the labels by setting the label to disabled. It is also well known that without some serious hoop jumping, that disabled label is forever gray. But this permits the right click and left click to be fired on the underlying form.
I hoped that hyperlabel would provide the best of both worlds, that is color yet click through but hyperlabel has no enable feature.
Is it possible without great pain to implement .enable?
I havn't got the HyperlableClick to work yet on a vast array of hyperlabels, so as to move the form or pop up a menu in response to right and laft click of that arrayed hyperlabel.
But I'll keep trying.
:Ron
-
Re: Label control that supports hyperlinks, different colors and font styles
Is there a control like this for vb.net? Please let me know, I've been looking everywhere.
-
Re: Label control that supports hyperlinks, different colors and font styles
Quote:
Originally Posted by
babyjesus
Is there a control like this for vb.net? Please let me know, I've been looking everywhere.
Did you look in the VB.NET codebank?
-
Re: Label control that supports hyperlinks, different colors and font styles
I tried to search for the .NET equivalent class, someone needs to port this. Can make life a heck of a lot easier.
-
Re: Label control that supports hyperlinks, different colors and font styles
Quote:
Originally Posted by
Nightwalker83
Did you look in the VB.NET codebank?
To be fair the CodeBank isn't organized enough for a search for something this specific to be effective.
@babyjesus
Is there something specific about this HyperLabel that you like ? I haven't tried it so I don't know. Perhaps I could replicate whatever it is about it that everyone loves in a VB.Net version. A direct port from VB6 to VB.Net is an exercise in frustration if the code is not simple enough.