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;
Related
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
I made a Windows Forms application with C# and the Form size is 1200x800. There's a Picture Box called RivalCube which moves at runtime at the bottom left using the command RivalCube.Location = new Point(0, 677);. It works fine, but if you make the Application full screen and you start it it places the Picture Box somewhere in the middle of the screen because being Maximized makes it bigger so 0,677 is no longer the bottom left of the screen. So how do I make sure it stays at the bottom even if the application resizes?
I'v tried anchoring it but it still does not work.
Thanks alot !
On the resize event of the form add your code for the picture box's movement
Like this:
private void Form1_Resize(object sender, EventArgs e)
{
RivalCube.Location = new Point(0, 677);
}
How could you - in WinForms - create a black area that (over time) loses/gains transparency and is redrawn constantly so a kind of transition is created? I dont want to create a seperate form, so this would be very helpful and I could rearrange my new items as soon as the black area reaches a transparency of 0.
Left: What i have what at the moment:
Right: What the program looks like on startup
What I would want: A totally black screen
Override the OnPaint method of the form, and fill a rectangle the size of the form with the desired transparency. In this example, transparency keeps increasing:
var transparency = 0;
protected override OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
// e.Graphics.DrawImage(Image, imageLeft, imageTop, imageWidth, imageHeight);
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(transparency, Black)), this.ClientRectangle);
}
If you want to do this from a Timer event, inside the Tick event Invalidate the form to force the paint.
protected void MyTimer_Tick(object sender, eventArgs e) {
transparency++;
MyForm.Invalidate();
}
If you need to draw on top of the PictureBox, that presents a problem. One way to solve it is to get rid of the PictureBox and draw the image using Graphics.DrawImage before you draw the fade. If you want to show the image but have the black go up against the edges of your animal, then make it's background color of the PictureBox transparent and convert your image to use a PNG or GIF with all around the animal transparent in the original image.
For more complex effects, Check out the dot-net-transitions project on Google Code. It supports a variety of linear/non-linear transitions.
I am making a BCI system i Windows Form Application in Visual Studio, and I ned my buttons to flicker between black and white on the Back.Color.
I need to have the opportunity to set the flickering to a predefined frequency, and ther flickering to follow a square wave form. At the moment I am using a timer to get the flickering, however it is just to see if the interface looks the way it should.
Is this possible ? and can anyone help wiht this?
Here is my flicker code at the moment:
timer11.Start();
timer11.Interval = 37;
timer11.Enabled = true;
private void timer11_Tick(object sender, EventArgs e)
{
if (BlinkOn)
{
Exit.ForeColor = Color.Black;
Exit.BackColor = Color.White;
}
else
{
Exit.ForeColor = Color.White;
Exit.BackColor = Color.Black;
}
BlinkOn = !BlinkOn;
}
I need this to be rewritten into a square wave form, where I can specify the frequency I need. I am a novice in C#, so this was the easiet for to start with, however I need it to be flickering of a square wave form. I have seen some examples in UnityEngine, however I am writing in Wondows Form.
Thanks.
hi
How to display a wait gif over the screen for 5 second
i want to show a loading image(Gif) over a picturebox. eg when i click on the picturebox , before load another image into this picturebox my loading image(animation image(gif)) showing on the screen for 3 second and this gif image unvisible then another image load into picturebox.
on the other hand How to display a wait gif until image is fully loaded in c#.net 3.5
please help me
thanks
You could use the PictureBox.LoadAsync(string url). The PictureBox will then raise
LoadProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
and
LoadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
events.