Create the "frozen window" effect - c#

You know when you have a window that is frozen, but when you drag another window over the top it leaves a trail? Sometimes it looks a little bit like the end of Solitaire for Windows 3 :) when you get done (like my screenshot).
I'd like to make a C# windows (winforms/wpf) application that creates a surface like this and allows me to capture the image, but I'm a little bit at a loss of where to start.
Picture:

It would be easier with WPF. You can create a VisualBrush from any control, including a Window or FrameworkElement. Once you have that VisualBrush, you can paint it all over your form and it will create that same effect. Alternatively, you could use an ImageBrush if you want to do it with a picture rather than a UI element.
When you paint, just offset it by a couple X/Y each time and it will look just like that as it overwrites (er.. overpaints?) itself!
You can create your own class FrozenVisualHost that derives from FrameworkElement to host a DrawingVisual that you render. See: MSDN: Using DrawingVisual Objects
Overriding your FrozenVisualHost.OnRender() method would allow you to draw your 'frozen snapshots' as you recorded mouse movement (via MouseMove). Just make sure that you call the InvalidateVisual() method to update the host control.
One caveat: Creating a VisualBrush from a window will not capture the title bar or window border chrome. If you want that, you'll have to grab a snapshot manually (GDI): As described here. You can use that Bitmap however for your ImageBrush and do rendering similarly.

Related

Custom cursor above every other visual component

I have a Windows Modern App with a custom cursor, that is implemented by having an image that follows the system's cursor.
I just add the custom cursor image to the main grid of my application and everything works fine.
public MainPage() : base(true)
{
this.InitializeComponent();
MainPageGrid.Children.Add(new CustomCursor());
}
But when a popup opens, it gets above my custom cursor. Is there anyway that I can set the Z-index (or something similar) of a component in order for it to be the uppermost visual component of my modern application?
I would recommend using an actual custom cursor. I think this article looks like a decent intro to using these. You could also check this question for some tips on changing cursors. Other than that - I don't think you can tell when a random popup opens. You can poll for these with VisualTreeHelper.GetOpenPopups(), and then do something to make your popup show on top (maybe just reopening would work or maybe you'd need to create a new one every time) but that might not give you a good user experience or performance. You could also figure out all the events that could display a popup from ComboBoxes, Flyouts etc, but that sounds painful. It would probably be best to create an attached behavior that you could attach to all such popup-source-elements to trigger z-index fix-ups of your XAML-rendered custom cursor...
There is no need to implement a component as a custom cursor, as it is possible to override the maximum size limitation:
How to override maximum 32x32 mouse size in Windows like this program can

Create Animated Button

I have button it possible create animate on click?
with photoshop i have created a two image (enabled and disabled). Insert the picturebox in Windows Forms and Click event..Click the image changes from enabled to disabled, but you can have an animation?
Like this:
It looks like you mentioned WinForms so I'll address that. Yes animation is possible but in general it's going to be a bit of work.
There appears to be an implementation of a general purpose animation framework (although limited) over on CodeProject. In the comments schallos posted a better implementation of the reflection code using expression trees.
The general principle is:
Use a PictureBox so you get double buffering
Use a timer control to control repainting (calling Invalidate() on your PictureBox)
You'll probably want to add some easing into the animation so it appears smoother; a bit of acceleration added to it when the user clicks goes a long way.
A timer is not required using a GIF.
Using windows forms you could start by creating an animated GIF for each button. It would have to include both the forward and backwards direction. You can do this through Photoshop via the "Animation" panel. On the PictureBox click event you can set the image to play or stop.
The code below would set your image on the beginning frame.
imgButtonDimension = new FrameDimension(imgButtonDimension.FrameDimensionsList[0]);
imgButton.SelectActiveFrame(imgButtonDimension, 0);
pictureBox.Image = imgButton;`
If this is the approach you'd like to take I can provide further elaboration.

Animation Effects in WinForms/C#

I'm pasting an image from the game im building.
the matrix of empty cells you see are made of PictureBox[][].
I wan't whenever I drop a coin to one of the columns... I want it to go down but the purple stuff will hide the falling coin and the gray color you see wont hide it.
How do I make this effect?
please notice that in each PictureBox control I have set the BG Image as you can see
Don't do it like that.
Create custom control. In custom control, override Paint, and then draw COIN sprite first, then draw mask over it. Be sure that you use double-buffered painting here.
It will work like a charm, trust me!
And, since you are (I gueess) building 5-in-a-row game here, your custom control will be able to paint occupied slots as well.
By designing custom control, you'll be able to hide all the animation and graphics stuff away from your main form.
I don't think it is possible like that. Controls in WinForms cannot be transparent, that is the problem
I would think in three directions:
Forgetting about controls and
painting everything OnPaint event of
the form. It is not too complicated
(well it would be more complicated
to detect some mouse events like you
did now, as you wouldn't know which
graybox is hit, but rather just
mouse coordinates)
Experimenting with coin as a form
(forms can be transparent)
Possibly using WPF with same logic
you did, as controls can be
transparent there
Controls in Windows Forms can be transparent. You need to set the TransparencyKey of the Form to some color that you never plan on using (many people seem to love/hate Magenta for this), and then set the BackgroundColor of each PictureBox to the same color. The result should be a transparent PictureBox with its Image drawn over it. I'm pretty sure this won't work with the BackgroundImage property, mind you- just the Image property.
One potentially unwanted side effect of this method is that you'll be able to see whatever's behind your form (the desktop, other application windows, etc.) through the transparent places in the PictureBox.

WPF Create Bitmap of Window that hasn't been shown

Is it possible to create a bitmap of a window that hasn't been shown without using screenshots?
What I want to do is start my application, and have a main window that displays other windows. I use visual brush to display them after they've been shown, and the image stays after the window is closed, but how do I show an image of the window prior to Window.Show()?
I would guess that the window isn't rendered until it is needed, so there would be no way to get the flattened bitmap of it. I wonder if you could somehow make it "show" without being shown? Can you use Window.Hide() to your advantage? Just throwing it out there.
Also makes me think--why would you want to get a bitmap of a Window? Windows are for presenting UI, not for displaying as an abstract representation of a UI choice. Maybe creating an abstract icon for each choice would be more usable?
No way to do this without creating the Window first, as it won't be in the visual tree until it is created. You may create it in an area outside your working area and generate the bitmap from there. You need it laid-out first also because of bindings, layout transforms, etc.
You should get everything you need here: http://www.west-wind.com/weblog/posts/150676.aspx and here: http://www.codeproject.com/KB/WPF/WPF-Image-to-WebPage.aspx
The key is the RenderTargetBitmap class

Form looks like a balloon

I am just trying to create a form control in winform in .net with custom shaped of balloon shape.
There is need of a balloon tooltip which is transparent and I can put buttons on tooltip,but
tooltip in .net does not provide facality that we can put the buttons on tooltip control so
I want to make a form control looks like a balloon tooltip and so I can put buttons on that form looking like a tooltip.But I cannot show window form control look like a balloon tooltip.
So what should I do??
I tried in one way that I create a image in powerpoint of balloon shape and set it to as background image of form property.But there is no solution with that.
The Control class supports a BackColor with an alpha < 255, it is automatic. It asks the Parent to draw itself to produce the background of the control, then draws itself on top of that. However, you'll want a top-level window for a balloon. That's a window type that can arbitrarily overlap another window and isn't confined by the client area of an underlying window. It has no Parent. A ToolTip is such a window.
The only control available in Windows Forms that can be an top-level window is a Form. Problem is: the transparency trick no longer works. Since a top-level window doesn't have a Parent, there isn't any obvious window to ask to draw the background. It could be many windows, belonging to other processes. You can get transparency in a Form with its TransparencyKey property. But that's a "hard" transparency, equivalent to an alpha of 0. You probably want a soft one. Another nasty problem is that drawing anti-aliased (ClearType) text no longer works since there is no reliable background pixel color anymore.
Long story short: you can't make this work well unless you confine the balloon to the client area of a form. A control, not a form.
You can try to hook on the Paint event of the control and draw the Visual of the button there.

Categories