C# 移动表单时淡入和淡出透明度
我有代码可以使表单在移动时部分透明,但我想知道当我开始移动和停止移动表单时是否可以添加淡入和淡出效果。
编辑
我用来添加表单透明度的代码是:
bool canMove = false;
private void Form1_Load(object sender, EventArgs e)
{
canMove = true;
}
private void Form1_Move(object sender, EventArgs e)
{
if (canMove)
{
this.Opacity = 0.7;
}
}
private void Form1_ResizeEnd(object sender, EventArgs e)
{
this.Opacity = 1;
}
I have the code to make the form partially transparent when is being moved, but I want to know if it's possible to add fade-in and fade-out effects when I start moving and stop moving the form.
EDIT
The code I am using to add transparency to the form is:
bool canMove = false;
private void Form1_Load(object sender, EventArgs e)
{
canMove = true;
}
private void Form1_Move(object sender, EventArgs e)
{
if (canMove)
{
this.Opacity = 0.7;
}
}
private void Form1_ResizeEnd(object sender, EventArgs e)
{
this.Opacity = 1;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用
Timer
控件,在计时器的滴答事件中设置不透明度。直到表单停止移动(定义一个变量,如isMoving
并根据表单的状态将其设置为 true/false)。您可以在我的文章中找到在计时器的滴答事件中设置不透明度的示例 关于褪色标签。使用谷歌翻译来阅读它。
希望这有帮助。
You should use a
Timer
control, set the opacity in timer's tick event. until the form stops moving (define a variable likeisMoving
and set it to true/false based on form's status).You can find an example of setting opacity in timer's tick event in my article about a fading label. Use Google translator to read it.
Hope this helps.
您可以采用
Timer
控件,然后可以在表单开始移动时启动计时器,并将表单的透明度
设置为某个值,并在每个tick<
定时器
的/code>,将透明度
设置为减少
,并在某个值上将其增加
。如果您想在窗体停止移动时具有淡入淡出效果,可以在窗体移动时执行相同的操作。You could take a
Timer
control, you could then start the timer when form starts moving and set thetransparency
of the form to some value, and on eachtick
of theTimer
, make thetransparency
todecrease
and on some value make it toincrease
. If you want to have the fadein fadeout effect when form stops moving, you can do the same when the form has moved.