i need create my custom user control to support opacity percent between 0 to 100.
for example i need create my custom label or my custom text box or my custom picture box with opacity percent?
Printable View
i need create my custom user control to support opacity percent between 0 to 100.
for example i need create my custom label or my custom text box or my custom picture box with opacity percent?
Maybe the following link is useful to you:
http://www.vbforums.com/showthread.p...47#post5244547
if i where to do something like this i would "not" use any of the vb own components, instead creating it from scratch, use a image as base and use API to draw it, as you know we have alphablend that can do the opacity for you.
if you use a usercontrol you could set it to transparent/+invisible (at runtime) and visible in IDE, and draw directly into the parent hdc.
Just FYI. GDI+ has methods to draw strings at any opacity you desire. Maybe search the forum for examples of GDI+ and strings.
We covered this in earlier threads. Easy enough on a modern version of Windows, not so much for the dying Windows 7 or any dead OS earlier than that though.
Example:
Attachment 154771
This demo bounces the opacity up and down on a Timer.
Windows 8 or later is required. Anything older probably means a lot more work painting the entire UI yourself.
Note:
For this to work it requires a manifest, so for most of us the IDE doesn't have the required manifest and only in the compiled program will the UC have alpha transparency.
dying windows 7? my work, my computers all have windows 7. so its not dying at all.
like windows xp, 7 will be around for many years.
the only thing that would force people to move to 10 is directx12, nothing else.
Windows 7 is in Extended Support and Microsoft says even then it cannot be made secure.
Microsoft warns Windows 7 is dangerously insecure in 2017
Besides that, Win7 SP1 has several updates that introduced erroneous binary compatibility breaks that will never be fixed. The fixes are in Win8 and later only.
New features like the one I used above will never be back-ported to Win7. It is a sinking ship in flames. We don't have to like it, but fighting reality has its limits.
we could argue about this a lot, but i will leave it as it is, instead i will go back to the OP's question.
no matter, people still uses 7 and even xp, if you have 10 and you don't plan to share it with others, i would go with dilettante's suggestion, if not, then check the forum for API examples about GDI/GDI+. its not that hard to make, you only need a few API's and a bit of code to emulate the different controls you plan to have.
Properly emulating controls from dirt can be a ton of work. If you have to support obsolete OSs then you might be better off with a 3rd party widget library instead... and at that point you may as well be writing in FreeBASIC or C.
Here is all of the "plumbing" used to get the desired effect on Win8 and later:
Code:Option Explicit
'Requires Windows 8 or later.
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongW" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" ( _
ByVal hWnd As Long, _
ByVal crKey As Long, _
ByVal bAlpha As Byte, _
ByVal dwFlags As Long) As Long
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongW" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Const GWL_EXSTYLE = -20
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_COLORKEY = &H1&
Private Const LWA_ALPHA = &H2&
Private mAlpha As Byte
Public Property Get Alpha() As Byte
Alpha = mAlpha
End Property
Public Property Let Alpha(ByVal RHS As Byte)
mAlpha = RHS
If Extender.Visible Then ApplyAlpha
PropertyChanged "Alpha"
End Property
Private Sub ApplyAlpha()
SetLayeredWindowAttributes hWnd, 0, mAlpha, LWA_ALPHA
End Sub
Private Sub UserControl_InitProperties()
Alpha = 255 'Default.
End Sub
Private Sub UserControl_Paint()
Size 3030, 2280
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Alpha = PropBag.ReadProperty("Alpha", 255)
End Sub
Private Sub UserControl_Show()
If Ambient.UserMode Then
SetWindowLong hWnd, _
GWL_EXSTYLE, _
GetWindowLong(hWnd, GWL_EXSTYLE) Or WS_EX_LAYERED
ApplyAlpha
End If
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "Alpha", Alpha, 255
End Sub
problem not fixed yet,any sample for work on win 7? just a simple user control with opacity property.i found many example usercontrol to hv opacity properties too but was been complicated.i need simple sample.
Any custom control, ultimately is a bitmap. Prior to Windows 8 where we could not make controls semitransparent, there were only a couple solutions and none are 'easy'.
1. Create a windowless control and draw your control onto the parent DC via UserControl_Paint at whatever opacity you want.
2. Capture the background behind the usercontrol and blend your usercontrol into the background and paint that. This is problematic if the usercontrol's parent background can change, i.e., background color changes or anything behind the control changes like animation, etc.
Edited: this option not suitable if the control requires user-input, like a textbox. Why? Because what you have drawn is a snapshot of the control not the control itself. Suitable for pictures, labels. If used for textboxes or other user-input type of controls, becomes much more difficult.
3. Complicated subclassing routines used to intercept the parent's Paint event to take over the drawing of the area occupied by your usercontrol, then drawing in that area what you want to be drawn. Similar limitations as in #2 above.
As newer O/S come from Microsoft, sometimes they offer easier ways of doing things. Win8 offered semitransparency for child controls when only the form-level was offered before. Prior to Win2k, form-level semi-transparency wasn't offered. Safer methods of subclassing in the IDE were offered in Win2k and before that, required more complex methods for safety. The list goes on and on. In another 20 years, if VB is still supported, people may look back and say, "Holy crap, you mean you had no easy way to do [fill in the blank] back then?"
If the UserControl is just a static image things don't get too complex. But once you add a Textbox or even a Label that can display a blinking caret or changing text it becomes another story... not to mention more complex controls.
Even using layered windows can be problematic. For example a dropdown list for a ComboBox appears solid and opaque even when the textbox part of it is translucent.
If you are writing games or other funky UIs that break Windows design conventions you are better off just drawing everything manually instead of using controls at all.
Alpha transparency is more of a stunt than anything else and should be used sparingly when at all.
my langauge is not english so i always have problem for understand descriptions but can send a exmplae work on win 7 ? and i want have been a user control and then when i seted opacity to 50% so my user controls opacity change to 50% (with any contains like text box in it or ... )
This isn't perfect or complete, but it is one way that might give you some idea where to begin. Should work even on Windows 95 since you want to support obsolete OSs.
It relies on MSWLESS.OCX for a TextBox though.
Attachment 154923
It sounds like you need a lot more help though. If you need custom programming services this isn't the place to ask for it.
Here is an updated version that corrects a flaw in the transparent OmegaLabel UserControl that caused dynamic changes to Caption to produce muddy overwritten images.
There are lots of other improvements that could be made to these as well of course, such as additional properties or events if you need them.
mswless.ocx what is that and how to get it?
im not sure its legal to copy from an early os.
It comes with VB6 but must be installed from the CDs separately. Browse your CDs to find it, the location varies with Edition.
See: "Q184687: INFO: Lightweight Controls in Visual Basic 6.0"
You can find this on your MSDN CDs by searching for Q184687
will look into it when i get home, interesting, i never looked into that folder, i always thought that it would be copied when installing.
very odd that they don't include an option when installing. im sure a lot of people don't even know about it!
Makes you wonder where they have been for 20 years.
There's been a lot of talk about copyright and piracy around here lately, and this is the only reason I bring this up now: that GitHub KB archive is kinda interesting in that it maintains the Microsoft copyright notice, and even going to the top page at https://jeffpar.github.io/kbarchive/ does, but I don't see any permission to republish posted anywhere? Is this pirated material too? Normally it's the kind of stuff I'd just pass over without issue, but due to all the re-examination of copyright law lately, I'm interested as to what the status of stuff like this is.
Hard to say, but I removed the link and replaced it with an alternative source.