Important alert: (current site time 7/16/2013 2:38:13 AM EDT)
 

winzip icon

MorphBorder v1.00 - Gradient Border UserControl AND Class

Email
Submitted on: 3/10/2006 7:00:17 PM
By: Option Explicit 
Level: Intermediate
User Rating: By 24 Users
Compatibility: VB 6.0
Views: 16373
author picture
(About the author)
 
     (Added MorphBorder *Class* 09 Mar 2006) MorphBorder is a simple usercontrol that allows you to frame other controls with an attractive gradient border. Just drop it on the form, and point it to any control (intrinsic or usercontrol) that has the following exposed properties: .hDC, ScaleMode, ScaleHeight, ScaleWidth, and AutoRedraw. Also contains a class that does the same thing. I recommend the class although they should both work fine. See demo project for usage particulars. As always, constructive feedback welcome, votes appreciated.

 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 8 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
3/7/2006 7:18:58 PMRussell Sanders

Looks good I'll give it a run, thanks.
(If this comment was disrespectful, please report it.)

 
3/7/2006 7:36:08 PMOption Explicit

Hi everyone, I have no idea if this useful to anybody. It's just something I've been wanting for my own projects and the region shaping code I learned doing MorphDisplay was the key to doing this the way I wanted to. Have fun.
(If this comment was disrespectful, please report it.)

 
3/8/2006 1:24:57 AMRobert Rayment

Nice one ***** and so easy to use!
(If this comment was disrespectful, please report it.)

 
3/8/2006 4:28:04 AMLight Templer

Nice! I thought to this type of ucs, too. (But never get the time to do it.) Suggestion: Expand it to handle multiple controls. A property page could show the enumaration of all available controls in a listbox with checkboxes to select. On start you have to check now: Do every of the selected controls still exists (No -> Remove from list). Regards - LiTe
(If this comment was disrespectful, please report it.)

 
3/8/2006 7:07:20 AMjeremyxtz

My reaction to this is that you've made something very easy incredibly more complicated. Drawing a gradient border is as simpe as drawing a few rectangles. Minus the declares here's code to draw a red gradient border round a form

Private Sub Form_Paint()
Me.Cls
Me.DrawWidth = 2
Dim R As RECT
With Me
SetRect R, 0, 0, .ScaleWidth, .ScaleHeight
End With
For j = 204 To 0 Step -51
InflateRect R, -2, -2
With R
Me.ForeColor = RGB(255, j, j)
Rectangle Me.hdc, .Left, .Top, .Right, .Bottom
End With
Next
End Sub

One underated border submission everyone should take a look at is txtCodeId=12629&lngWId=1
(If this comment was disrespectful, please report it.)

 
3/8/2006 7:24:01 AMjeremyxtz

Here are the declares for my last post

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SetRect Lib "User32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function InflateRect Lib "User32" (lpRect As RECT, ByVal X As Long, ByVal Y As Long) As Long

Form scalemode should be set to pixels

(If this comment was disrespectful, please report it.)

 
3/8/2006 8:02:51 AMOption Explicit

Jeremy, I agree there are different ways to do any project... this just happens to be one way. This is something I put together from my growing library of routines that make up my controls. As with LaVolpe's color chooser post, I think you've missed the point. Could his chooser have been done more simply? Could my border? Sure. However, there are techniques demonstrated in these types of posts that might be valuable learning tools for people. I learned so much about VB by studying posts like Keith's. That's why I put so much commentary into my projects, to help people like I have been helped. Like I said in Keith's post sometimes it's not the destination, it's the journey. Plus, my method seems to work well. Thanks for the feedback.
(If this comment was disrespectful, please report it.)

 
3/8/2006 8:06:26 AMOption Explicit

LiTe, I too have thought about making this work for multiple controls. When I have a bit more time maybe I can make that work. Thanks. Robert, Avi and Umega, thanks for the comments/votes. Robert, it was nice to post something short and sweet for a change! :)
(If this comment was disrespectful, please report it.)

 
3/8/2006 9:55:12 AMRichard Mewett

^^ Jeremy, no doubt you can create a simple gradient border with less code but this offers finer control, superior output and its all wrapped up in a resuseable package (which actually makes it MUCH simpler to use). This is seriously small by Morph standards ;)

Nice job Matt *****
(If this comment was disrespectful, please report it.)

 
3/8/2006 11:23:17 AMOption Explicit

Thanks Richard. Yeah this is microscopic by my usual MorphBloat standards! Anyway Jeremy I really appreciate your feedback, imo you use this site exactly as it is meant to be used - you submit code and you not only leave quality feedback, you provide an alternative. Exactly what feedback should be. Keep it up ;)
(If this comment was disrespectful, please report it.)

 
3/8/2006 11:41:00 AMtonyn

i'll give you 5 blobs just for the kitty
(If this comment was disrespectful, please report it.)

 
3/8/2006 12:02:01 PMHeriberto Mantilla Santamaria

Complicated where?, if I understood with my scarce knowledge, do I believe that it won't be difficult for other to understand it.

Matt Excellent work as always, this can be used in a form About, this would give him much more presence.
(If this comment was disrespectful, please report it.)

 
3/8/2006 1:54:40 PMOption Explicit

tonyn, my cat thanks you :).

Thanks Heriberto. Jeremy was just pointing out there's more than one way to skin a cat. Uh, maybe wrong choice of words :D

(If this comment was disrespectful, please report it.)

 
3/8/2006 3:22:28 PMdalmare2000

Simple,easy, usefull, nice end exellent *****
(If this comment was disrespectful, please report it.)

 
3/8/2006 4:42:07 PMJeff Mayes

Nice, easy to use. 5 planets.
(If this comment was disrespectful, please report it.)

 
3/8/2006 9:13:35 PMOption Explicit

Thanks dalmare2000 and Jeff. Ok, some news... I have a new version of MorphBorder that implements Light Templer's suggestion of expanding it to handle multiple controls. As it happened, the more I changed the control, the more it started looking like a class, not a control. Funny how things morph :P Anyway, it seems to work fine and I'll resub soon with both the original control as well as the new class. Jeremy, the class has 171 less lines of code than the control so hopefully you'll hate it less :D
(If this comment was disrespectful, please report it.)

 
3/9/2006 5:08:38 AMUlli

looks good - minus a little flaw: when the border width is an even number there is an ugly black line inside left and bottom
(If this comment was disrespectful, please report it.)

 
3/9/2006 5:33:41 AMjeremyxtz

I'm was just making sure everyone knows the easy way and knows about that other submission.

I see drawing a gradient border as a simple sub. IN MY VIEW a usercontrol for every border with all the resource costs is inefficient and a bad way of doing it.

People clearly disagree... but all I'm giving is constructive comment... my genuine honest view of this... nothing personal or malicious to it - it happens to be negative this time that's all!...

Option Explicit's other stuff fabulous...
(If this comment was disrespectful, please report it.)

 
3/9/2006 7:27:46 AMOption Explicit

Ulli, thanks for letting me know, I don't know why I didn't spot it before. Probably an easy fix. Jeremy, like I said above, yours is a welcome view. And I partially agree with you. Keep it up!
(If this comment was disrespectful, please report it.)

 
3/9/2006 7:31:24 AMOption Explicit

OK, by the time this comment gets posted the new version (with both the control and the class) should be up. Jeremy, this class addresses your concerns at least partially. One class with ONE set of resources takes care of any eligible control on the form. LiTe, not the way you evisioned it exactly but it *does* do multiple controls! Thank you for spurring me to do this upgrade. I recommend the class over the control. It's smaller, better written and even easier to use imo.
(If this comment was disrespectful, please report it.)

 
3/10/2006 7:53:02 AMOption Explicit

Ulli, I haven't found the exact source of the black line yet although I believe it is based somewhere in the actual region-generating routine. In the submission I got that code from, LaVolpe forces the width to an even number. That might be related; I'll ask him. In the meantime people, if you use a border color scheme that makes the black line obvious, just make sure the .BorderWidth property is set to an odd number and no black line will appear.
(If this comment was disrespectful, please report it.)

 
3/10/2006 10:26:07 AMPhantom Man

Well done Option.
Looks good and the code is very neatly produced.
(If this comment was disrespectful, please report it.)

 
3/10/2006 2:10:33 PMOption Explicit

Thanks Phantom Man. Haven't seen you around in a while. And thanks Mark T. (bossman!) for the vote.
(If this comment was disrespectful, please report it.)

 
3/10/2006 5:22:13 PMOption Explicit

OK a slight revision is posted that corrects the glitch observed by Ulli. Thanks again Ulli for pointing it out.
(If this comment was disrespectful, please report it.)

 
3/10/2006 9:13:58 PMPaul Turcksin

There may be simpler/easier ways to do this. But: 1. the result is great; 2. this post has excellent documentation, making it an outstanding learning tool for anybody interested in GUI enhancements. Thanks for sharing this jewel. 5 stars rom me.
(If this comment was disrespectful, please report it.)

 
3/11/2006 9:18:40 AMOption Explicit

Hi Paul! Haven't heard from you in quite some time. Thanks for the nice words and the vote. The educational aspect is indeed why I posted this. In roughly 350 lines of code (the class) you can learn to generate virtual DCs/bitmaps, calculate and store gradients, paint to virtual bitmaps, form regions, move regions, select clipping regions and bitblt to that clipping region. I agree it's a useful little learning example, plus it does something I needed. Thanks again.
(If this comment was disrespectful, please report it.)

 
3/15/2006 11:59:42 AMEvilgenious

I want Usnar's lucky cat.
(If this comment was disrespectful, please report it.)

 
3/15/2006 3:21:08 PMOption Explicit

Sorry EvilG, I've had her since she was eight weeks old and next month she's turning nine years old. I think I'll keep her, thanks. However, everybody's invited to her birthday party :D
(If this comment was disrespectful, please report it.)

 
3/15/2006 3:22:15 PMOption Explicit

B.Y.O.C. (Bring Your Own Catnip)
(If this comment was disrespectful, please report it.)

 
3/16/2006 2:53:41 AMEvilgenious

Usnar. Send me her birthday cake picture. I want to taste the RGB's of her cake.:):):)
(If this comment was disrespectful, please report it.)

 
3/16/2006 9:02:35 PMOption Explicit

Ummm.....
(If this comment was disrespectful, please report it.)

 
3/20/2006 6:02:00 PMOption Explicit

Btw Jeremy I tried the code you supplied above... I get a thick red line surrounded by a thin pink line. The concept you presented may work but the example you gave doesn't. I'll stick with mine, thanks :D
(If this comment was disrespectful, please report it.)

 
4/5/2006 6:13:35 PMOption Explicit

I'm shocked this won a COTM... it's just something I threw together for myself and thought I'd throw it this way as well. Thanks for the support people I really appreciate it! On the other hand, I think a submission with only 19 votes winning COTM shows that not enough people are voting for the many quality submissions that are shared each month. If you like something, and especially if you find it useful in your own apps, show your appreciation to the author with a vote (and more importantly, constructive feedback). Thanks again (and sorry for the editorializing ;))
(If this comment was disrespectful, please report it.)

 
4/6/2006 9:12:14 AMPriyank Modi

hi
This is priyank modi.
really Nice work .
but can i know ur name...
Thanks once again.., why??? u know...
byee
(If this comment was disrespectful, please report it.)

 
4/6/2006 4:15:40 PMOption Explicit

Thanks for the comment and vote Priyank. And congrats on your contest win, you had a nice submission there.
(If this comment was disrespectful, please report it.)

 
6/4/2006 9:45:13 AMOption Explicit

One thing I have noticed about using this to border a usercontrol. Do nor use the usercontrol's Show event to draw the control's graphics. If you do, the MorphBorder will be overwritten. Call the control's graphics drawing from the ReadProperties event instead.
(If this comment was disrespectful, please report it.)

 
6/16/2006 6:14:56 PMMicro-Coder

You are psychotic dude....how do you think this stuff up??!!
(If this comment was disrespectful, please report it.)

 
6/16/2006 7:34:08 PMOption Explicit

Psychotic? Ahhh... someone finally understands me... :D Actually M-C, I've been programming bland text-base apps for work for over 20 years. When I decided to start learning VB, I latched on to usercontrols and gradient-based graphics because they were totally foreign to me. Turns out I latched onto a good thing, because anything you can do with vb you can incorprate into a control. I've learned a lot from this site and the many brilliant coders here. Every one of my MorphControls is descended (at least inspirationally) from one submission:

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=59869&lngWId=1

So if I'm psychotic it's Cameron Grove's fault :D Thanks for the comment and vote.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.