Animation in .gif is not showing in windows Form - c#

I am very new to c# and windows form.
What I am trying is to add a PictureBox to a windows form and display an animated .gif image before I display the data in the form.
Here is the code for the PictureBox :
private System.Windows.Forms.PictureBox pictureBox1;
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.SystemColors.AppWorkspace;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(374, 442);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(16, 16);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 19;
this.pictureBox1.TabStop = false;
this.pictureBox1.Visible = false;
Now, on a button click the gif image should be loaded in the picture box . The code for that goes like this :
private void scanButton_Click(object sender, EventArgs e)
{
pictureBox1.Visible = true;
pictureBox1.Refresh();
}
Now, when I click the button "Scan Button", the image becomes visible,but the animation is not working.
Please can anyone help me what is happening here ?
Thanks!

For your .gif animation to work, your main (UI) thread should be free. If you are performing any process on main thread then you will not get animation effect.
From your question, it seems like you are performing Scanning operation on click of button. That may be the problem.
To get rid of this problem, you will have to make sure that your main thread is free and any operation (like Scanning) should be on separate thread.

Just assign the path to the image in ImageLocation.
pictureBox1.ImageLocation = "C:\\throbber.gif";
The PictureBox will understand that it's an animated image and play it. Disabling the PictureBox or the Form will stop the animation from playing.

If you really need to use picture box you can iterate over a collection of images. But i strongly recommend using WebBrowser (mind it is basically IE)
This should help you with all animations using windows forms
Simple animation using C#/Windows Forms

Related

Give blinking effect on overlapping image/panels in c#.net Windows Application

I am developing an application using c#.net windows form application. I have a form size background image & multiple star images. I tried picturebox control/panel as background for a large background image. Star images will be placed on background image & I want to give a blinking effect to those star images. It is working fine(blinking), if star the image is in individual picturebox control/panel, but when put on the background image/panel, it is not working... & if I place image on image, it is showing background also though it is set as transparent...can anybody tell me the solution.?
Code used for blinking effect
private void timer1_Tick(object sender, EventArgs e)
{
pictureBox2.Visible = !pictureBox2.Visible;
pictureBox3.Visible = !pictureBox3.Visible;
panel2.Visible = !panel2.Visible;
panel3.Visible = !panel3.Visible;

C# Can I take screenshot of everything below active window

Is there any method / API allow calling something like CopyFromScreenAtDepth
I try to capture a preview of GUI below active window
then blur it to achieve something like Aero glass / OS X frosted glass blur effect
I have tried many workaround
Set the Form opacity to 0 then capture and setting back to 1, this cause my form blinking.
Make the Form background Blue with same transparent key, this will work at first time but GUI won't updating, so if I call this.Update() it will update the GUI, but cause blinking too.
My code:
private void MyForm_Load(object sender, EventArgs e) {
Timer timer1 = new Timer();
timer1.Tick += new EventHandler(UpdateBackground);
timer1.Interval = 100; // in miliseconds
timer1.Start();
}
private void UpdateBackground(object sender, EventArgs e)
{
this.BackgroundImage = null;
Bitmap myImage = new Bitmap(this.Width, this.Height);
using (Graphics g = Graphics.FromImage(myImage))
{
this.Update();
g.CopyFromScreen(new Point(this.Location.X, this.Location.Y), Point.Empty, new Size(this.Width, this.Height));
}
ImageTools.FastBlur(myImage, 4);
this.BackgroundImage = myImage;
}
There is no such CopyFromScreenAtDepth() method call for Windows.
The best you can do is to use the Windows Magnification API for C++.
There are a TONs of drawback using it, like not having control over the Window position and size, limited capabilities, to none at all, at having both copy of screen below form and being able to have other controls, and the WOW64 problem when using a 32bits application with the API under 64bits OS...
I know it's an old question, but since it's a valid question with no answer so far, I thought it would be fair to answer it.
There are also other questions like this one around (which doesn't have answer either, and may be called duplicates...)

WPF Using an image as a cursor but mouse events are not working over buttons

I am using a PNG image as a cursor by translating the image with the mouse coordinates and it moves very nice. The problem is when I tried to click a button, for some reason the button flashes as I move the mouse over it. The button goes inactive or not focused and mouse clicks are not working until for some fraction of a second where if I keep moving the mouse and clicking over the button, then the mouse click works. I tried also to play with the z-index having no results.
When I tried the hidden cursor without the image, the mouse events works without problems. This is the code I am using:
TranslateTransform T = new TranslateTransform();
public GameTitle()
{
InitializeComponent();
Mouse.OverrideCursor = Cursors.None;
this.MouseMove += GameTitle_MouseMove;
CompositionTarget.Rendering +=CompositionTarget_Rendering;
}
void CompositionTarget_Rendering(object sender, EventArgs e)
{
CursorImage.RenderTransform = T;
}
void GameTitle_MouseMove(object sender, MouseEventArgs e)
{
T.X = e.GetPosition(this).X;
T.Y = e.GetPosition(this).Y;
}
This is with the image cursor:
And this is without the image cursor and the mouse cursor hidden:
How can I make the buttons works with the image cursor?
Thanks in advance for your help!
While I was writing the question, I keep searching for answers and I found this nice software (http://www.aha-soft.com/artcursors/cur-editor.htm) that helped me reading a PNG image and saving it as a Cursor (*.cur) file. Then I added the file to the project resources in Visual Studio and added the following code as described in one of the answer in https://stackoverflow.com/a/8715560/1278771:
Mouse.OverrideCursor = new Cursor(new System.IO.MemoryStream(MyNameSpace.Properties.Resources.TheResourceName));
Now, it works very nice!:

C# Form's background image as pictureBox parent?

I have a picturebox with some transparency. I found out I can use picturebox.Parent to set the parent image, but it only works when Parent is another picturebox. But what if i want form's background image to be picturebox's parent?
pictureBox1.Parent = PictureBox2; //works fine (of course if there is a pbox2)
pictureBox1.Parent = Form1; //??? magic goes here
If I understood well, you want that your background would be transparent. If so, use:
pictureBox1.BackColor = Color.Transparent;
Are you trying to use an image with transparency as the background to your form? If so, you can't do that you have to use a transparency key.
what you are trying to do above works this way but I don't know what that would accomplish...
Form1 theForm = new Form1();
pictureBox1.Parent = theForm;

Load image in PictureBox before make control visible

I have a form with black background, with 9 picture boxes.
When the program starts, I want to show 9 images using these picture boxes.
However, the picture boxes take time to load the picture. It is quite ugly that the picture boxes show up first while waiting.
Is there a way I can move from blank black screen to straightaway 9 images, without the visible loading in between?
Thanks.
How are you loading your Form (I guess you are talking about Windows.Forms here)?
You can just create a new Window class and load your pictures and then after all is done call the Show method.
MyForm form = new MyForm ();
form.DoLoadImages ();
form.Show ();
Or you can just set the WaitOnLoad property of the PictureBox to true.
private void startButton_Click(object sender, EventArgs e)
{
// Ensure WaitOnLoad is false.
pictureBox1.WaitOnLoad = false;
// Load the image asynchronously.
pictureBox1.LoadAsync(#"http://localhost/print.gif");
}
Courtesy of MSDN: http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.waitonload(v=VS.100).aspx1

Categories