Create a GUI for Application - winforms

I have to create a program that starts with a splash screen and a transparent image, but in windows form not working there always the white background, how can I do?

You need to set a transparency key. If you set it to white, it will make everything that's white on the form transparent (doesn't work well with the picturebox control though).
So for instance, you create a panel, and give it the background image you want to be displayed, then set the transparency key to whatever color should be made transparent ;p

Related

Need overlapping button in round cornered Winform

Need a quick suggestion for styling a WinForm. I made it with rounded corners even when re-sized. Now trying to add a close button with a image (ControlBox=false), overlapping or clipped to top right corner. This is what I could end with.
But I wish to make it more like in this example image.
How could I achieve this in WinForm.
Here's the trick : your window doesn't just end with the white part. It extends a little bit further. The close button comes under the 'extra' part. The other sides where the window appears to not be there is actually transparent...or in the case of the image, semi-transparent.
The glow effect is provided by the window. Set the TransparencyKey property of the window to Color.Magenta (its a convention as Magenta is the color least likely to be used in a window). Then set the background image to a white background with a little bit of Magenta in the edges. The Magenta will appear transparent when set as the background image.
Fiddle around with TransparencyKey and you'll understand what I mean
Winforms itself cannot provide this for you without outside manipulation of the windows,
because it still uses win32 windows classes in the background.
If you want transparancy in windows: see articles like:
Cool, Semi-transparent and Shaped Dialogs with Standard Controls
And the method in Win32 to do it:
SetLayeredWindowAttributes

Is this how I make custom controls both transparent and flicker-free in Windows? Or do I have one of these steps wrong?

I could begin by asking the question outright or by citing my sources (this, this, this, and this) descriptively, but I'll walk you ll through what I'm trying to do instead.
Let's start with a main window. It has its own window class whose hbrBackground is set to COLOR_BTNFACE + 1. Now let's do
EnableThemeDialogTexture(hwnd, ETDT_ENABLE | ETDT_USETABTEXTURE)
so the tab control we're about to add will be drawn with visual styles. (Try Windows XP with the standard Luna theme for best results.) Now let's add a tab control and two tabs.
On the first tab, we create an instance (let's call it container) of a new window class. This window class is going to hold various controls. I could set hbrBackground to COLOR_BTNFACE + 1, but then it will draw over the tab background. So I want this new child window to be transparent. So what I do is
set the class hbrBackground to GetStockObject(HOLLOW_BRUSH)
set container's extended style to WS_EX_TRANSPARENT
set the class WM_ERASEBKGND handler to do SetBkMode((HDC) wParam, TRANSPARENT); return 0; to set the device context and have Windows draw the transparent background.
So far so good, right? I'm not sure if I'm really doing all this correctly, and I'd like this to also be flicker-free, which doesn't seem to happen: when I resize the window (at least in wine) I get either flicker or garbage drawn (even in child controls, somehow!). Windows XP in a VM just shows flicker. I tried tweaking some settings but to no avail.
But wait, now I want to have another control, one that just draws some bitmap data. On the next tab, create another container, then have a third window class area as a child of that. area only draws in the upper-left 100x100 area and has scrollbars; the rest of the window area should be transparent.
Right now, what I have for area is:
the window class hbrBackground set to NULL and styles CS_HREDRAW and CS_VREDRAW set
the extended window style being 0
the WM_ERASEBKGND simply doing return 1;
the WM_PAINT filling the entire update rect with COLOR_BTNFACE + 1 before drawing, and rendering all of it
This is flicker-free, but obviously not transparent. NOW I'm really not sure what to do, because I want the area to be transparent in such a way that it shows the tab control background. Again, I tried tweaking settings to bring them closer to what I tried above with container, but I got either flicker or invalidation leftovers when I tried.
So how do I get both of these custom control types (the container and the drawing area) to be both flicker-free and transparent?
I presently must target Windows XP at a minimum, though if the solution would be easier with Vista+ only I'd be happy to keep that solution on the side in case I ever drop XP support (unfortunately Stack Overflow doesn't let me hand out silver medals...).
Thanks!
To paint your window in a manner that is "flicker free", you will need to paint your window to a bitmap, then copy the bitmap to the destination device context. On Windows XP, you will need to create a bitmap, adjust the origin of the drawing DC and then paint your window. On Vista and later you can use BeginBufferedPaint and its associated routines to do the buffering for you.
Once you have buffered painting working, you can then use WM_PRINTCLIENT to paint your window's parent window into the your drawing DC before you do any actual drawing. Unfortunately, not all windows will support WM_PRINTCLIENT.
You could consider using DrawThemeParentBackground, rather than WM_PRINTCLIENT directly.
Combining these two methods together will leave you with transparent flicker-free drawing.

How to overlay white text on a white background in WPF so that it is viewable

My WPF VS 2008 application is working with many different images that are assembled and displayed at runtime. I would like to display some white text on top of those images. My problem is that some images contain a white or light color background.
My question is - is it possible to somehow specify a property or specify a setting in the image object, BitmapImage object (where the image is loaded from), or some other WPF object such that when white pixels from one image overlap white pixels from the other image - they turn a different color so the text will be viewable?
I think it depends on how you 'draw' your text on the images. If you use e.g. a Label, you can try out the 'DropShadowEffect', see: http://msdn.microsoft.com/en-us/library/ms748273.aspx
This effect should work with all WPF objects and you can try out some transparent black soft shadows surrounding the text (a little bit like a glow).
This will only be visible in bright environments if you adjust the opacity right.
Decided to use a dark background color for the text that is only partially (.35) opaque. This means that the background color of the image comes through for the most part, but for lighter colors it yields enough contrast so that the text is viewable.

how to Paint non-client area in winForms transparent? .Net 4

im developing a custom form and i want that the non-client area be transparent. im handling the non client area painting via message number "0x85" and this is what i have tried so far:
Paint using the color "Color.Transparent" -> the non-client area was painted black. If I had used an image of red or black or green, it works perfectly, but transparent = black
Created a transparent image of the size of the form and used the method "myGraphics.DrawImage("img.png")". the background remained black. If I had used an image of red or black or green, it works perfectly also...
Not paint anything (hoping that i just would stay transparent)... not worked
Getting parts of a window transparent requires hardware support, a video adapter feature called layering. Use the form's TransparencyKey property. Set it to an unusual color, like Color.Fuchsia. And draw with that color to get the video adapter to omit the pixels.

Flood fill text based on a percentage in silverlight splash screen

I want to create a custom splash screen where some text on the page will end up being the progress bar. I need the text to flood fill with color from left to right based on the % loaded. My first thought (since I'm not use to doing this type of UI related stuff) was to have a textblock with the forecolor being trasparent layered over something like a border with its backcolor set and then grow the border control based on the %, but this is such a hack, there has to be something better with all the wonderful things silverlight can do. I had also thought about using a image so I could outline the text, but noticed the image was slow and was the last thing to load on my splash screen.
Any ideas on the right way to acomplish this?

Resources