C# - 移动时使形式半透明 [英] C# - Make form semi-transparent while moving
问题描述
有没有办法使表格在半透明的同时被移动,然后在不再被移动时变得不透明?我已经尝试了没有运气的 Form_Move
事件。
我被卡住了,有任何帮助吗?
Is there any way to make the form semi-transparent while it is being moved and then become opaque when it's not being moved anymore? I have tried the Form_Move
event with no luck.
I'm stuck, any help?
推荐答案
表单加载为半透明的原因是因为表单必须移动到起始位置,这会触发Move事件。您可以通过根据是否设置不透明度来确定是否设置了透明度,可以克服这种情况。
The reason the form loads as semi-transparent is because the form has to be moved into the starting position, which triggers the Move event. You can overcome that by basing whether the opacity is set, on whether the form has fully loaded.
表单完成移动后,ResizeEnd事件会触发,所以这样的事情应该工作:
The ResizeEnd event fires after a form has finished moving, so something like this should work:
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.5;
}
}
private void Form1_ResizeEnd(object sender, EventArgs e)
{
this.Opacity = 1;
}
这篇关于C# - 移动时使形式半透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!