|
|
|
Non-transparent controls on the semi-transparent window |
|
|
|
||||
IntroductionThere is an opportunity to improve the user’s interface for the windows in Windows by setting the transparency. In Windows versions beginning from 2000 it is implemented by setting theWS_EX_LAYERED style for the window.
But here we are faced with a problem – the style can’t be set for the child
windows. The semi-transparent window looks showy but everything that is drawn
on it (including controls) will also be semi-transparent. And it considerably
worsen the ergonomics of the user’s interface. The article
|
describes the SkinTooltip control developed by the KB_Soft Group
company for its internal needs that allows the effect of the non-transparent
controls on the semi-transparent window to be reached. The approach described
below also allows different animation to be implemented on the control while
displaying it. It is necessary to note that the control is not really
semi-transparent but it only imitates the transparency. In this connection,
some restrictions to its usage appear that will be described below.
|
|||
2. The description of the control’s workThe essence of our approach to the solution of the given problem is as follows. The control itself (and all the child controls on it) is not semi-transparent. |
The semi-transparency of the window is imitated. Two steps are performed for
this.
|
|||
On the first step the screenshot of the parent window is made using the following function:
public static void GetControlScreenshot( Control control, ref Bitmap bitmap )
{
if (control == null || control.Handle == IntPtr.Zero)
return;
if (control.Width < 1 || control.Height < 1) return;
if (bitmap != null)
bitmap.Dispose();
// preparing the bitmap.
bitmap = new Bitmap(control.Width, control.Height);
Graphics destGraphics = Graphics.FromImage(bitmap);
// setting the flag indicating that we need to print both the client's and
// the non-client's window rectangles.
int printFlags = (int)( Win32API.PRF_NONCLIENT | Win32API.PRF_CLIENT);
System.IntPtr param = new System.IntPtr(printFlags);
System.IntPtr hdc = destGraphics.GetHdc();
// sending the WM_PRINT message to the control window.
Win32API.SendMessage(control.Handle, Win32API.WM_PRINT, hdc, param);
destGraphics.ReleaseHdc(hdc);
destGraphics.Dispose();
}
|
||||
|
The function draws the control window to the “bitmap” |
bitmap’s pixel is multiplied according to the timer’s message on a multiplier in
the range from 0 to 1.0; as a result, the image varies from the complete
transparency to the value initially set in the image that is specified as a
control’s background on the 2 step. To perform it, the .NET Framework library
has a standard mechanism basing on the |
|||
3. The description of the control’s usageThe control was inherited from theSkinControl base class. The
class usage was described in the “The controls of an arbitrary shape” article.
The most important properties and functions of the class are described below.
|
|
|||
Add the application a link to the KBSoft.Components.dll library, and add the corresponding using directives to the beginning of the file
containing the form:
using KBSoft.Components;Now add the class a new item:
private SkinTooltip skinTooltip = new SkinTooltip();
private Button btn = new Button();
Add the following code to the constructor:
//getting the assembly for extracting the resources. The result is shown in the screenshot below.
|
||||
|
Offshore software development which feels in-house © 2000 - 2008 KB_Soft Group |
|
info@kbsoft-group.com
|