Transparent OptButtons & ChkBoxes

JDYoder
10-09-2001, 08:36 AM
Hand -- I was just now able to take a look at this. And it ROCKS!! Thanks for much! You da man! BTW, I want to give credit where credit is due. So is it enough that your name is in the code? Or in the actual exe that uses it, would you like your name in credits as well?

JDYoder
10-18-2001, 02:29 PM
The Hand -- Thanks again for this code, however I'm running into a snag. When my form comes up, I want the optionboxes and checkboxes to already be transparent. However, placing this code in the Form_Load or Form_Activate with Autoredraw equal to True or False doesn't seem to work. The only way it seems to work is if the form is already up, and something else calls the Function against the various controls.

Do you happen to know how I can effectively call your procedure on my controls before the form is up and the user sees anything?

Derek Stone
10-18-2001, 05:18 PM
Place this before you call the code:
<pre>Me.Refresh

</pre>

Good Luck
-cl

JDYoder
10-18-2001, 05:46 PM
There's a pause before they change which is very noticable -- especially since my form has several optionbuttons. So I figured maybe I could do it while their invisible, and then make them visible. But if their invisible, it doesn't seem to work at all.

Any other suggestions? BTW, thanks for helping me out here!

Thinker
10-18-2001, 05:55 PM
Split off from the original thread in Code Library.
Wish I had some ideas that could help here. Hopefully, The Hand will.

Garrett Sever
10-19-2001, 07:58 AM
How many option buttons!?!??!? I tried it with 9 on a 600MHz processor and it was fine!

I used the following code in my project, which worked fine for making them transparent during the Form_Load():

<pre>
Private Sub Check1_Click()
Dim anOpt As OptionButton
For Each anOpt In Option1
anOpt.Refresh
TransChkOpt anOpt, (Check1.Value = 1)
Next anOpt
Check1.Refresh
TransChkOpt Check1, (Check1.Value = 1)
End Sub


Private Sub Form_Load()
Me.Show
Check1.Value = 1
End Sub

</pre>


As for the "noticable pause", calling the refresh of the individual option buttons should help
(instead of showing the entire form)

Also, make sure that your OptionButtons/CheckBoxes are sized to be as small as they can be while still displaying all of the info (caption, etc). Remember this routine loops thru each pixel in the control, which means 1) the control MUST be shown before it will work (the DC must be realized) and 2) extra size = extra pixels = slower processing.

You could try optimizing the routine to only perform the CombineRgn API on groups of pixels, but I doubt it will greatly increase performance as you will have more If/Then lines executing with each pixel. You could also try covering up the option buttons with a bitmap or something until they are done, but I have NO idea if that would work.



I actually came up with a better solution.

1) Make the optionButtons only as big as the little circle.
2) Set the caption = ""
3) Put a label with the backmode = transparent next to it for the text

That will DRASTICALLY reduce the amount of pixels it has to loop thru. You could then write some code in the Labels' Click() events to programmatically click the right option button.

JDYoder
10-19-2001, 09:12 PM
I'm running 19 optionbuttons on a P-400 without a graphics card, so maybe that's why. *shrug*

Just now read your post, and I did something similiar to what you suggested. I put a transparent label as my option button, as you suggested. But then I wrote a routine to BitBlt (with a mask) a bitmap graphic of the an unpressed optionbutton so the background comes through around the edges. Then when the label is clicked, I BitBlt a pic of a selected optionbutton. Did the same with the checkboxes.

It works fine and dandy, though took a little more time than what you've suggested, which I probably would have went with had I gotten email notification that someone had replied. (Apparently, moving the thread cut that off). :( However, one thing I like about mine is I can make my own optionbutton and checkbox graphics now, to conform with the "look" of my game if I so choose.

BTW, don't know if you knew this, but I noticed one disadvantage with the original method TransChkOpt. With optionbuttons and checkboxes, when you click on the graphic portion or anywhere on it's label, it's receives the click event. HOWEVER, after the TransChkOpt is run on it, you either have to click on the graphic button OR (this is bizarre) you have to click on part of the actual font since clicking on the "blank space" no longer works. Crazy.

But both our methods take care of that with the label aspect. Thanks again for all your help!

BootData
10-19-2001, 11:03 PM
hi...this might sound silly, I ran the code:
Private Sub Check1_Click()
Dim anOpt As OptionButton
For Each anOpt In Option1
anOpt.Refresh
TransChkOpt anOpt, (Check1.Value = 1)
Next anOpt
Check1.Refresh
TransChkOpt Check1, (Check1.Value = 1)
End Sub


Private Sub Form_Load()
Me.Show
Check1.Value = 1
End Sub

but it didnt work...I believe the required objects are there already..Error message: compile error - sub or function not defined. the error is pointing to TransChkOpt function I believe..
Where do we define this TransChkOpt function??

Thank you for your time and assistance :)

JDYoder
10-19-2001, 11:17 PM
TransChkOpt is some code that The Hand graciously created, showing how to make optionbuttons and checkboxes transparent. It can be found in the Code Reposity section. It's confusing because they broke off our thread from the original one there.

Garrett Sever
10-20-2001, 12:18 AM
BTW, don't know if you knew this, but I noticed one disadvantage with the original method TransChkOpt

Actually, I did know that. What the SetWindowRgn API actually does is limit the window's region or "clickable" area to only the pixels you specify. Normally this is a rectangular area, however by calling the sub that I wrote, you limit it to only the bits that do not have the same value as the system color for button faces (GetSysColor(15)).

To get around this, you could implement the subclassing I mentioned in the <a href="http://www.visualbasicforum.com/bbs/showflat.php?Cat=&amp;Board=visbas&amp;Number=54493&amp;page=&amp;view=&amp;sb=&amp;o=&amp;vc=1">previous thread</a>, which actually passes back a pattern brush handle to the WM_CTLCOLORSTATIC message and colors the background (see my <a href="http://www.visualbasicforum.com/bbs/showflat.php?Cat=&amp;Board=CodeLib&amp;Number=45539&amp;page=0&amp;view=collapsed&amp;sb= 5&amp;o=93&amp;fpart=">SSTab from Heaven</a> example in the code library), however this code would be much more complicated and would need to be implemented for each parent for each group of option buttons. Perhaps I'll look into this a little more and generate an example, although I still believe the SetWindowRgn solution to be much better and more direct solution.

After thinking a little more about it, I believe I could better help you if you told me how the option buttons were arranged (1 group of 19, or multiple groups) and what types of background they were on (one big bitmap image, or a tiled background, or whatever).

I will work you up an example w/ this information.

BootData
10-20-2001, 08:41 PM
thanks..
I saw it in the code section..

cheers..

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum