Hello
I wondering how to do a fade in and out with a form, and also making sure the form is centered of the computer screen?
C# fade in and out form
Started by Siten0308, Jan 08 2010 02:29 PM
4 replies to this topic
#1
Posted 08 January 2010 - 02:29 PM
Its only funny till someone gets hurt.... THEN ITS HILARIOUS :)
|
|
|
#2
Posted 08 January 2010 - 09:07 PM
Here's a way to make your form fade in tel you move the mouse over it then it's opacity turns to full.
This will center your form.
Hope I help.:) not sure what you ment by the form fading in and out.
namespace fader1
{
public partial class Form1 : Form
{
Timer timer1 = new Timer();
Timer timer2 = new Timer();
int mState = 0;
public Form1()
{
InitializeComponent();
this.Opacity = 0.10;
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 200;
timer1.Enabled = true;
timer2.Tick += new EventHandler(timer2_Tick);
timer2.Interval = 15;
}
void timer2_Tick(object sender, EventArgs e)
{
// Adjust opacity until end-value is reached
double op = this.Opacity + mState * 0.03;
timer2.Enabled = false;
if (op >= 0.99) op = 0.99;
else if (op < 0.10) op = 0.10;
else timer2.Enabled = true;
this.Opacity = op;
if (!timer2.Enabled) mState = 0;
}
void timer1_Tick(object sender, EventArgs e)
{
Point pos = Control.MousePosition;
bool inForm = pos.X >= Left && pos.Y >= Top && pos.X < Right && pos.Y < Bottom;
if (inForm && mState <= 0)
{
// Fade in
timer2.Enabled = true;
mState = 1;
}
if (!inForm && mState >= 0)
{
// Fade out
timer2.Enabled = true;
mState = -1;
}
}
}
}
This will center your form.
//Get the working area of the screen and assign it to a rectangle object
Rectangle rect = Screen.PrimaryScreen.WorkingArea;
//Divide the screen in half, and find the center of the form to center it
this.Top = (rect.Height / 2) - (this.Height / 2);
this.Left = (rect.Width / 2) - (this.Width / 2);
Hope I help.:) not sure what you ment by the form fading in and out.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.
#3
Posted 08 January 2010 - 09:07 PM
Here's a way to make your form fade in tel you move the mouse over it then it's opacity turns to full.
This will center your form.
Hope I help.:) not sure what you ment by the form fading in and out.
namespace fader1
{
public partial class Form1 : Form
{
Timer timer1 = new Timer();
Timer timer2 = new Timer();
int mState = 0;
public Form1()
{
InitializeComponent();
this.Opacity = 0.10;
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 200;
timer1.Enabled = true;
timer2.Tick += new EventHandler(timer2_Tick);
timer2.Interval = 15;
}
void timer2_Tick(object sender, EventArgs e)
{
// Adjust opacity until end-value is reached
double op = this.Opacity + mState * 0.03;
timer2.Enabled = false;
if (op >= 0.99) op = 0.99;
else if (op < 0.10) op = 0.10;
else timer2.Enabled = true;
this.Opacity = op;
if (!timer2.Enabled) mState = 0;
}
void timer1_Tick(object sender, EventArgs e)
{
Point pos = Control.MousePosition;
bool inForm = pos.X >= Left && pos.Y >= Top && pos.X < Right && pos.Y < Bottom;
if (inForm && mState <= 0)
{
// Fade in
timer2.Enabled = true;
mState = 1;
}
if (!inForm && mState >= 0)
{
// Fade out
timer2.Enabled = true;
mState = -1;
}
}
}
}
This will center your form.
//Get the working area of the screen and assign it to a rectangle object Rectangle rect = Screen.PrimaryScreen.WorkingArea; //Divide the screen in half, and find the center of the form to center it this.Top = (rect.Height / 2) - (this.Height / 2); this.Left = (rect.Width / 2) - (this.Width / 2);
Hope I help.:) not sure what you ment by the form fading in and out.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.
#4
Posted 19 January 2010 - 11:08 PM
Thanks for the reply thegamemaker, just wanted to ask, how do you have it appear, which it does, but it waits about 10 seconds, then it fades out?
also... the name, thegamemaker, do you really make games? do you use xna etc.? what language do you use? just wondering if the name is what you do, not trying to be a jerk or anything :)
also... the name, thegamemaker, do you really make games? do you use xna etc.? what language do you use? just wondering if the name is what you do, not trying to be a jerk or anything :)
Its only funny till someone gets hurt.... THEN ITS HILARIOUS :)
#5
Posted 20 January 2010 - 09:43 AM
Um I'm not sure you'll just have to mess with the timers and stuff I just googled it for you.:)
Yes I really was making games when I made the account I was using Game Maker 7 and was starting to use XNA but then I decided I'd learn to program before game programming and am now learning C# which I think will be handy if I decide I want to make games.:)
Yes I really was making games when I made the account I was using Game Maker 7 and was starting to use XNA but then I decided I'd learn to program before game programming and am now learning C# which I think will be handy if I decide I want to make games.:)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.


Sign In
Create Account


Back to top









