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.
Related
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
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.
I have an image, And I want to create an effect like Windows 8 start menu when user clicks on it.
I mean, if this is my image:
When user clicks on it, it should change to something like this:
I mean, a little 3D effect.
How to create this effect in code behind? (On MouseDown event)
As you requested I'm posting my answer again:
Solution to your issue is covered by another SO question:
C#/WPF image transformation over a trapezoid
Hope this time it wont be automatically converted to comment :)
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.
I am currently creating a custom control that needs to handle animation in a C# project. It is basically a listbox that contains a fixed number of elements that are subject to move. An element (another user control with a background image and a couple of generated labels) can move upwards, downwards or be taken out of the list.
I would like to create animated movement as the elements get moved around within the container custom control but it seems to me that moving controls around using lines such as
myCustomControl.left -= m_iSpeed;
triggered within a timer event is flickery and has a terrible rendering, even with double buffering turned on.
So here's the question : What is the best way to achieve a flicker-free animated C# control? Should I just not create custom controls and handle all of the drawing within a panel's background image that I generate? Is there a super animation method that I have not discovered? :)
Thanks!
your best bet for flicker-free animation is to do the painting yourself (use the Graphics object in the Paint event handler) and use double-buffering. In your custom control you will need code like this in the constructor:
this.SetStyle(ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint | ControlStyles.SupportsTransparentBackColor,
true);
A similar discussion took place this morning on this question. visual c# form update results in flickering. so I will be lazy and give the same answer I gave there:
You could try to call this.SuspendLayout(); before you start your move and this.ResumeLayout(false); when you have finished moving all of the controls. In this way all controls should draw at once and you should have less of a flicker.
On a side note I have tried to reproduce this here at work, but seem to be failing. Can you give some more sample code that I can fix maybe?
See How to double buffer .NET controls on a form.
The normal way to get flicker-free animation is to implement double-buffering. Take a look at this Code Project article
http://www.codeproject.com/KB/GDI-plus/flickerFreeDrawing.aspx
Minimizing calls to paint until you are ready is also a good idea.