Results 1 to 28 of 28

Thread: Form With 2 Back Colors!

  1. #1

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Question Form With 2 Back Colors!

    I want the BackColor of a Form to be a haphazard combination of 2 colors. Can this be done? Of course, an image can be added to the Form so that it looks like the Form's background but apart from this, is there any way to set the BackColor of a Form with 2 colors?

    Thanks,

    Arpan

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Form With 2 Back Colors!

    hello arpan

    You mean like gradient forms?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Form With 2 Back Colors!

    I like to use this in my About boxs
    VB Code:
    1. Private Sub Form_Paint()
    2. Dim lngY As Long
    3. Dim intColor As Integer
    4. ScaleMode = vbPixels
    5. DrawStyle = 5
    6. FillStyle = 0
    7. For lngY = 0 To ScaleHeight
    8.     intColor = (255 - (lngY * 255) \ ScaleHeight)
    9.     FillColor = RGB(intColor, intColor, intColor)
    10.     Line (-1, lngY - 1)-(ScaleWidth, lngY + 1), , B
    11. Next lngY
    12. End Sub

  5. #5

  6. #6

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Form With 2 Back Colors!

    I had a look at all the 3 codes & all 3 seems to do almost the same thing but Hack's example is the shortest one; so I will go for that!

    Hack, how do I change the colors to blue & lime using your code? I tried changing a few values here & there but wasn't successful!

    Thanks to all,

    Regards,

    Arpan

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Form With 2 Back Colors!

    To create a little color effect using Hack's code try changing values for RGB function. Here are few to begin with:

    FillColor = RGB(0, intColor, 255) ' blue
    FillColor = RGB(0, 255, intColor) ' green
    FillColor = RGB(255, intColor, intColor) 'red
    FillColor = RGB(255, 0, intColor) ' magenta/red
    FillColor = RGB(255, intColor, 0) ' yellow/red

    and so on ...

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Form With 2 Back Colors!

    You are not stuck with standard RGB colors either. You can use the ShowColor feature of the commondialog to create your own colors. If you want, play around with this
    VB Code:
    1. Private Sub Command1_Click()
    2. CommonDialog1.ShowColor
    3. Text1.Text = CommonDialog1.Color
    4. Text2.Text = Hex(Val(Text1.Text))
    5. End Sub
    Using that, I've come up with some of my own color concoctions that I really like and use as follows
    VB Code:
    1. Option Explicit
    2.  
    3. Private Enum MyOwnColors
    4.    clrMistyRose = &HE1E4FF
    5.    clrSlateGray = &H908070
    6.    clrDodgerblue = &HFF901E
    7.    clrDeepSkyBlue = &HFFBF00
    8.    clrSpringGreen = &H7FFF00
    9.    clrForestGreen = &H228B22
    10.    clrGoldenrod = &H20A5DA
    11.    clrFirebrick = &H2222B2
    12. End Enum
    13.  
    14. Private Sub Form_Load()
    15. Dim ctrl As Control
    16. For Each ctrl In Me.Controls
    17.     If TypeOf ctrl Is Textbox Then
    18.        ctrl.Backcolor = MyOwnColors.clrMistyRose
    19.     End If
    20. Next
    21. End Sub

  9. #9

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Form With 2 Back Colors!

    Here are few to begin with:

    FillColor = RGB(0, intColor, 255) ' blue
    FillColor = RGB(0, 255, intColor) ' green
    FillColor = RGB(255, intColor, intColor) 'red
    FillColor = RGB(255, 0, intColor) ' magenta/red
    FillColor = RGB(255, intColor, 0) ' yellow/red

    and so on ...
    I tried out some combinations & permutations but I can't seem to get blue & lime.

    FillColor = RGB(0, 0, intColor) 'this renders blue & black
    FillColor = RGB(0, 255, intColor) 'this renders cyan & lime
    FillColor = RGB(intColor, 255, intColor) 'this renders white & lime

    But somehow I am not getting the blue & lime combination! Any idea what could be that combination?

    Thanks,

    Arpan

  10. #10
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Form With 2 Back Colors!

    I like it!!!

  11. #11

  12. #12

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Form With 2 Back Colors!

    FillColor = RGB(25, intColor, 140)

    The above renders lime & blue but the blue is the navy blue or dark blue. Have a look at the image below:


    I want that shade of blue & lime.

    Arpan

  13. #13

  14. #14
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Form With 2 Back Colors!

    Quote Originally Posted by RhinoBull
    It appears to me arpan that you may mark this thread as [RESOLVED] - all that's left for you is to play with numbers.
    I'm actually playing around to see if I can add a clrBlueLime to my bag of color tricks, but I would agree with your assessment.

  15. #15
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Form With 2 Back Colors!

    I put Hack's code into an obscure form as a test. Man, does that look nice! Maybe I have just gotten too bored with the "Button face" color scheme.

  16. #16
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: Form With 2 Back Colors!

    Quote Originally Posted by Pasvorto
    I put Hack's code into an obscure form as a test. Man, does that look nice! Maybe I have just gotten too bored with the "Button face" color scheme.
    Yep, me too! I never even thought of trying to make my own colors.
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  17. #17
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Form With 2 Back Colors!

    Yea but you have to be carefull with multicolor schemas - lot of people hate'm so you might want to give a choice. Besides, if you're business user then you are most likely to get tired from just looking at that rainbow day long ... Greyish colors were choosen to be default for a reason: they are not pretty but relaxing.

  18. #18
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Form With 2 Back Colors!

    Quote Originally Posted by RhinoBull
    Yea but you have to be carefull with multicolor schemas - lot of people hate'm so you might want to give a choice. Besides, if you're business user then you are most likely to get tired from just looking at that rainbow day long ... Greyish colors were choosen to be default for a reason: they are not pretty but relaxing.
    Sage advice my friend, which is why I only use a form covering color scheme for my Aboutbox (really now, how many people ever bother to look at the Aboutbox, or, for that matter, know what it is or where it is).

    The individual colors I will use to for things like highlighting a textbox that has focus (and returning the backcolor to the standard vbWhite on LostFocus) or highlighting required fields.

  19. #19
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Form With 2 Back Colors!

    Microsoft Great Plains software uses a Blue scheme. I have not heard any complaints from any of ther users about it. Certainly you have to be careful about "known" bad combinations (eg; red and green) and people who are color blind. But on the whole, I think color is good.

    A couple issues, however. Command buttons, for one, do not have a background color that I can change. So I am stuck with a cool color scheme, and a "Button Face" command button. So, I either have to get a different control, or make my own. I thought I read somewhere that I could change the back & fore colors of the command buttons in VB.NET 2005. Anyone else hear that?

    Now, how to modify this so that it will work with the background of an MDI parent. There is no "ScaleMode" property.

  20. #20
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Form With 2 Back Colors!

    If you set a command button to Graphical, you CAN change the colors of it. Enjoy!

  21. #21
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Form With 2 Back Colors!

    WOW!! Man, I learn something new everyday. There's no stopping me now :-)

  22. #22
    Addicted Member
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    135

    Re: Form With 2 Back Colors!

    The best way is to use a photo editor which has an eye dropper that you can select the part of an image and it will display the RGB values.

    (I know the problem has been resolved, just adding my 2 cents)

  23. #23

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Form With 2 Back Colors!

    It appears to me arpan that you may mark this thread as [RESOLVED] - all that's left for you is to play with numbers.
    That's exactly what I have been doing but I guess you are right.....it's high time I mark this post [RESOLVED]. Actually I thought that there must be a specific combination for blue which, maybe, I am not aware of......that's the reason I asked you. Anyways, as I already said, you are right RhinoBull

    Thanks to all for your ideas, suggestions & comments,

    Regards,

    Arpan

  24. #24

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Form With 2 Back Colors!

    (I know the problem has been resolved, just adding my 2 cents)
    Well, Jason, to be very honest, it hasn't been resolved yet. Till now I must have tried 500 combinations but I don't know why, either I am getting blue or lime but not the 2 of them together. Driving me crazy......will have to start pulling my hair soon I guess

    & the worst thing is my work is getting hampered on this trivial issue as I am not able to proceed forward with the other aspects of the project!

    Arpan

  25. #25
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Form With 2 Back Colors!

    Quote Originally Posted by arpan_de
    Well, Jason, to be very honest, it hasn't been resolved yet. Till now I must have tried 500 combinations but I don't know why, either I am getting blue or lime but not the 2 of them together. Driving me crazy......will have to start pulling my hair soon I guess

    & the worst thing is my work is getting hampered on this trivial issue as I am not able to proceed forward with the other aspects of the project!

    Arpan
    As I said earlier, I've been playing around with it as well and so far I've had no more success than have you. What is so important about this particular color that the entire project is being hung up? I've had plenty of stumbling blocks thrown at me before, but I've never been hung up on a color.

  26. #26

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Form With 2 Back Colors!

    What is so important about this particular color that the entire project is being hung up?
    My boss wants me to go step by step! Quite unbelievable, isn't it but that's the fact!!

    The best way is to use a photo editor which has an eye dropper that you can select the part of an image and it will display the RGB values.
    Jason, I implemented your idea & used PhotoImpact to get the RGB values. For blue, R=0, G=0 & B=255 & for green, R=0, G=255 & B=0 but how do I combine these 2 RGB values to paint the Form?

    Arpan

  27. #27
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Form With 2 Back Colors!

    Hack's version worked on greyscale, so the RGB parameters were all the same value, but your new values vary.

    The R is always 0, so that can be fixed inside the RGB() function. The G and B are (luckily) exact opposites, so for a gradient between them you can decrease one while increasing the other, eg:
    VB Code:
    1. FillColor = RGB(0, intColor, 255 - intColor)

  28. #28
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: Form With 2 Back Colors!

    The blue is 2, 3, 253
    The green is 2, 254, 2

    Hope this helps you. (They are in RGB format, thanks to Photoshop CS2)
    Zeegnahtuer?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width