How to achieve multi layer transparency in Klik! DesignerLib.Net

by Özden Irmak 13. December 2008 21:38

I'm sure you already heard our screen designer product, Klik! DesignerLib.Net. It's based on the same base classes of the Windows Forms designer you use everyday on Visual Studio. Having the same common base, it brings you lots of advanced features you find in Visual Studio as well it's limitations, well actually a limitation of using windows to draw items into the screen...

The most advanced screen designers as of today are graphical tools such as Adobe Photoshop, where you can create layers and have them blend over each other if you play with their transparency level. In one of the custom projects where we used Klik! DesignerLib.Net, we had to have such a capability. Without going into it's details, it's was used in a part of an enterprise digital signage product where you could create content screens to be played by the players.

The player was already created with WPF and as you already know, WPF does not use controls as we know as controls Smile. To be more clear, in traditional windows form, every element (textbox, combo, etc.) you add into it is actually a window again where each has it's own handle. In WPF, every control you create are actually simple drawings which are drawn into the same form background. So in WPF, a centralized drawing mechanism is responsible for all those drawings into the same canvas and effects such as transparency/translucency can be supported easily, where in regular window world each window is separate on drawing it's inner elements thus there is no multi layer transparency support out of the box.

A little bit magic and some trick to get it right...

Windows Forms controls does have a style flag called SupportsTransparentBackground and with it you can achieve a partial transparency, good for a start. But what it does is a simple hack of drawing it's parent background into it's background to emulate the transparency and there is no consideration of other controls in between itself and the background. What we did is to only add this consideration and also limit to a level of controls, as otherwise with a crowded amount of controls in the screen, the application would become very unresponsive due to the amount of paint calls.

Without going any further, the code we used to do that is like that and is used in the base usercontrol for all other controls :

protected override void OnPaintBackground(PaintEventArgs e)

{

//Call our layered paint method instead of the regular one

PaintLayeredBackground(e);

}

//Paints the Layers

private void PaintLayeredBackground(PaintEventArgs e)

{

e.Graphics.SetClip(e.ClipRectangle);

//This is the call for painting the parent background

base.OnPaintBackground(e);

int StartIndex = Parent.Controls.Count-1;

int EndIndex = Parent.Controls.IndexOf(this);

//3 is our draw level

if (StartIndex - EndIndex > 3)

{

StartIndex = EndIndex + 3;

}

//Now draw 3 level of other controls which their bounds intersect with our control

for (int i = StartIndex; i > EndIndex; i--)

{

if (Bounds.IntersectsWith(Parent.Controls[i].Bounds))

{

e.Graphics.TranslateTransform(Parent.Controls[i].Left - Left, Parent.Controls[i].Top - Top);

InvokePaint(Parent.Controls[i], e);

e.Graphics.ResetTransform();

}

}

e.Graphics.ResetClip();

}

And the result is looking something like this :

Not bad ha? Laughing We set a limitation of 3 level drawing which was good enough for us both on performance and visual wise. To simple summarize, what the code does is simply drawing the parent background like .Net Windows Forms transparency does and than drawing the foreground elements of in between controls. Thes in between controls are also choosen from the ones which their bounds intersect with the control we are actually drawng. Than, at last the control draws it's own elements on top of all these merged drawings.

We hope that you'll find it usefull and hope to see you at the next post...

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Klik! DesignerLib.Net v1

What's new on Klik! EntryLib.Net v2 - Part 2

by Özden Irmak 7. December 2008 11:04

Hello and welcome back to the second part of what's new in Klik! EntryLib.Net. In this part we continue to give further clues about visual enhancemens as well as representing another new control...

Give me more pretty interfaces...

In the first part we had informed you about the drawing speed improvements and new Office 2007 styles. Let's continue to look into the enhancements on drawing different parts of the controls :

- BackgroundImageStyle / ForeGroundImageStyle: Background and Foreground Image classes now have 2 additional image effects added. The first one is called Mirror (Reflection is another common name for it). What it simply does is that it creates a reflection effect of your image which looks incredibly cool and very common nowadays. The second one is called Fade and what it does is to slowly fade your image from it's top to bottom.

- BorderStyle : Borders can now be painted using LinearGradient brushes, where you could only use solid colors in the last version.

- TextStyle : A new text type has been introduced, which is called Glow. When activated, it creates a glow effect around the drawn text with your choosen color.

A nicer way to list your data, ELDataGridView...

Since it's introduction in .Net v2, DataGridView was one of my favorite list controls, despite it's performance problems when you try to display large amount of data. At this point, let me also inform you that our list controls library is coming soon as well, infact just after Klik! EntryLib.Net v2, which will include a nice grid alike control in it Wink.

Thankfully, DataGridView is flexible enough so you can ownerdraw nearly all of the elements in it. Our implementation, although does not add anything to it's functionality, adds some nice visual properties to the original control which can be used to create a consistent look with other Klik! EntryLib.Net controls. It supports Office 2007, Office 2003 and other built-in custom styles out of the box and you can adjust those new properties to create your own unique look where you can change the header and selection styles of the control. It's also fully compatible with the old DataGridView, so you can simply replace you old controls with it easily. The above screenshot shows you the look of Office 2007 ModernBlue style, not bad ha? Smile

This was all for this time and see you soon in the next part...

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Klik! EntryLib.Net v2

What's new on Klik! EntryLib.Net v2 - Part 1

by Özden Irmak 1. December 2008 07:14

Since we progressed a lot in the new version of Klik! EntryLib.Net, it's time to share those new features with you.

General Improvements

I'm sure most of you want to hear about the changes in drawing/loading of form speed changes as a first thing. I'm glad to inform you that we have completely re-engineered all the drawing routines as well as all other things which might affect form load speed and there is a significant improvement on those areas. Even with the largest amount of controls on a screen, both the load and draw speed is very close to native .Net controls, so you won't bother about this again Smile.

The second thing is that now we have native Office 2007 styles built into our controls. We provide styles available for 3 Office 2007 color schemes and each of them is also provided in modern and classic styles. Modern styles are rendered considering the new drawing style which you can see in Ribbon, etc. where the classic style mimics the look in Outlook 2007.

A new Control, ELProgress

ELProgress is a new addition to our library. There are situations in our applications where we need to notify the user about a long process and this control is an elegant way to do this. As you might noticed, it's not named ProgressBar but only Progress, because it offers you 2 types of view as Bar and Circle. The bar type is like the regular ProgressBar control in .Net but you have total control on the look and can style it in Office 2007 or any other custom look you want. Circle type is the type which is popular on ASP.Net AJAX interfaces nowadays and using it's properties can mimic different type of progress circles you see in Internet Explorer, FireFox, etc.  You'll also have total control over the progress using Maximum, Minimum, Value, etc. properties.

One nice thing is also the Animation feature. Some processes you'll do won't have any specific start and end so you'll need to show some kind of progress animation. When this property is set true, it does exactly this and shows a nice endless animation till you turn it off Wink.

That's all for now for the first part, see you at the next one soon...

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Klik! EntryLib.Net v2

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

Calendar

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar