|
-
Mar 2nd, 2004, 05:20 AM
#1
Thread Starter
Hyperactive Member
kinda transparent, kinda not
Well, I'm sittin here with a GDI(+) thing I guess, but not knowing how to proceed. I wish to make a form darker, instead of transparent. One "solution" was to put a black form behind it, and then make the form a bit transparent. But it gave some slow performance, and other painting issues when I tried showing other forms on top.
Does someone have some guidance on how I could completely make a form darker, very quick, without much (or any) flickerin', and then perhaps show a brand new form on top of it, without having to see an ugly hole on the transparent/darker form first?
The form i wish to transform is about 796, 565, and has controls and stuff on it, even an owner-drawn listview control.
Thanks.
-
Mar 3rd, 2004, 08:39 AM
#2
I wonder how many charact
Here is a small chunk of code (bout 2-3 lines), that you can put in a function, which will take a color, and return the color slightly darker. You could simply loop this function using the default percentage( or if it darkens too fast, use a small percentage,say 2, for the second parameter).
VB Code:
Private Function darkencolor(ByVal c As Color, Optional ByVal percent As Integer = 10) As Color
Dim rr As Byte = c.R
Dim gg As Byte = c.G
Dim bb As Byte = c.B
Dim r As Integer = rr - Convert.ToInt32(percent * (rr / 100))
Dim g As Integer = gg - Convert.ToInt32(percent * (gg / 100))
Dim b As Integer = bb - Convert.ToInt32(percent * (bb / 100))
Return Color.FromArgb(Math.Min(r, 255), Math.Min(g, 255), Math.Min(b, 255))
End Function
Last edited by nemaroller; Mar 3rd, 2004 at 08:57 AM.
-
Mar 4th, 2004, 02:33 AM
#3
Thread Starter
Hyperactive Member
Thanks for the reply.
This is a very good function. However it's not exactly what I was looking for. Well, it will be useful if I was drawing the entire form and every control on it myself. But that'd take ages and it'd be kinda difficult and "overdone". Isn't there a simpler method for making the entire form darker, and all the controls on it?
To give you an idea of what I need, just take a simple dialog form, paint it black, give it no title, and no border, and no control box, and no icon, then take another form, make it the same size, drop some controls on it, listbox, combobox, listview, treeview, buttons and stuff, put some data in them, and make the form's opacity 70% (0.7) Run the first form (black one), then display the second form (with the controls) on top of the first form. Now THAT is the kind of "darker" I need.
I know, it sounds like I have just given myself the answer, and to an extend, it is a solution. But only temporary. There's much slow performance, and some flickeren' goin' on. Firstly, I don't want to see the black form at all. Secondly, when I display another form window on top of the translucent form, there's a black hole for a second or a half on it, then the other window apears, and then for a few moments, all the controls of the new window appear black, until the entire form is finished painting. This is not what I want. There must be an alternative way of making a form a little bit darker. The entire form (including title, control box, border and stuff).
Again, thanks for helpin.
-
Mar 4th, 2004, 04:41 AM
#4
Hi.
I think this could be achieved by using the BitBlt API.
Maybe have an image with the color to draw, and then use one of the BitBlt API's to draw the color with Multiply or something like that directly on to the forms DC.
That should draw ontop of the controls as well.
I think the trick is to let controls paint first, otherwise they will redraw after the paint, and the controls will not be covered
I have no idea how to do it, though , but I believe it could be done using those principles.
I hope this is of any help to you at all. (if not, please ignore )
Last edited by pax; Mar 4th, 2004 at 04:57 AM.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Mar 4th, 2004, 05:39 AM
#5
Thread Starter
Hyperactive Member
Hmmmm. It's a reasonable idea you got there. It might just work. So, what I understand is, let the form draw itself and the controls, then I come afterwards, and alpha each and every pixel on the form with a greyish color and plot it down there? Hmmm. I wonder if things might get a lil slow.
I don't mind the form showing it's bright original colors and stuff first. The idea is to darken it during the progress and runtime of my app. Not before it displays. But I guess if that was my idea, it would have been much more difficult. Heh.
-
Mar 4th, 2004, 08:07 AM
#6
I wonder how many charact
I don't think you can expect a reasonable performance. The transparency feature is really just do displaying transparent forms, not fading them to black per se. I mean, if you have windows XP, you will notice MS treated fading of menus as an option, so less powerful computers could bypass it.
Perhaps you could try fading in the black form over the form you want cover ....keep the original form at the same transparency, and just place the black form on top of it, and opaque the black form instead. It may be a far less expensive painting operation.
-
Mar 5th, 2004, 02:59 AM
#7
Thread Starter
Hyperactive Member
cheese... am I speaking a foreign language here or sumthin'?
-
Mar 5th, 2004, 03:03 AM
#8
Thread Starter
Hyperactive Member
on second thought... you both have good points. lol.
but i have to stress the fact that I didn't want to fade the form in or out, or to black or white or whatever. I just need it to darken a little bit ONCE. I need more coffee.
-
Mar 5th, 2004, 08:35 AM
#9
I wonder how many charact
In that case... use the function above and this code.
It darkens the form once... 
VB Code:
'''in a button click
Me.BackColor =darkencolor(Me.BackColor)
Me.ForeColor = darkencolor(Me.ForeColor)
Dim X As Control
For Each X In Me.Controls
X.ForeColor = darkencolor(X.ForeColor)
X.BackColor = darkencolor(X.BackColor)
Next
'''
-
Mar 8th, 2004, 07:49 AM
#10
Thread Starter
Hyperactive Member
using the code above, the following things are not darkened:- Textbox borders
- Button borders
- GroupBox borders
- Listbox -, Treeview -, ComboBox - and ListView borders
- Window borders
- Window Titlebar and ControlBox
- Other graphical controls. (i.e PictureBox, GDI+ graphics (lines and shapes), etc.)
Last edited by jovton; Mar 8th, 2004 at 07:52 AM.
jovton
-
Mar 8th, 2004, 12:36 PM
#11
I wonder how many charact
Yes, unfortunately, the standard controls don't allow you to access those colors because they are part of the 'window' that contains them, which is why most people end up building their own 'custom' controls that override onpaint.
-
Mar 8th, 2004, 01:23 PM
#12
Thread Starter
Hyperactive Member
Looks like I'll have to go with compatible device contexts and bitblt. Does anyone remember what the term is called for "mixing" colors? Earlier I proposed that I had to "alpha" each pixel. Well, thinking again, that was a "misthought". I'm not talking transperancy here. Just plain "multiplying" as pax said.
Last edited by jovton; Mar 8th, 2004 at 01:26 PM.
jovton
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|