怎么实现一个窗体,由下到上消失,或者由上到下消失。
之前通过透明设置能控制整体渐变。
但是怎么实现上下渐变,或者左右渐变,这种自定义的渐变效果呢。
[解决办法]
LinearGradientBrush
http://www.csharpwin.com/csharpspace/9197r5587.shtml
[解决办法]
搜索winform 渐出效果
http://www.cnblogs.com/JieNet/archive/2008/05/27/1208651.html
[解决办法]
http://www.codeproject.com/Articles/13288/Animating-Windows-Forms
修改源码 可以到达你要的效果
[解决办法]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace 水果机
{
public partial class login : Form
{
public login()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1 frm = new Form1();
frm.ShowDialog();
}
private void button2_Click(object sender, EventArgs e)
{
answer frm = new answer();
frm.ShowDialog();
}
double i = 0.05;
FormShow fs = new FormShow();
private void timer1_Tick(object sender, EventArgs e)
{
this.Opacity += i;
if (this.Opacity == 1)
{
timer1.Stop();
i = -0.05;
//timer2.Start();
}
else if (this.Opacity == 0)
{
timer1.Stop();
Exam.GetExam();
fs.GetShow(Exam.GetExam());
}
}
private void login_Load(object sender, EventArgs e)
{
this.Opacity = 0;
timer1.Start();
}
}
}
[解决办法]
这个问题挺有意思的啊
[解决办法]


[解决办法]
form设置为无边框即可。
不过总体效果一般,建议其他方案。
[解决办法]
类似这样的动画效果要能换WPF的话好实现的多啦。。。
只要XAML这样加个动画就好了。
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ControlTemplateBrowser" Height="300" Width="200" Loaded="Window_Loaded" Background="Transparent" AllowsTransparency="True" WindowStyle="None">
<Window.Resources>
<Storyboard x:Key="Storyboard1">
<DoubleAnimation From="0" To="1" Duration="0:0:2.5" Storyboard.TargetProperty="(UIElement.OpacityMask).(LinearGradientBrush.GradientStops)[0].Offset" Storyboard.TargetName="LayoutGrid"/>
<DoubleAnimation From="0.1" To="1" Duration="0:0:2" Storyboard.TargetProperty="(UIElement.OpacityMask).(LinearGradientBrush.GradientStops)[1].Offset" Storyboard.TargetName="LayoutGrid"/>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>
</EventTrigger>
</Window.Triggers>
<Grid Margin="10" Name="LayoutGrid">
<Grid.OpacityMask>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="Black" Offset="0" />
<GradientStop Color="Transparent" Offset="0.1" />
</LinearGradientBrush>
</Grid.OpacityMask>
.....
</Grid>
</Window>
这段是窗体打开的时候渐变显示的效果。
消失的效果只要把动画里From跟To换一下就好了。
效果跟QQ的基本一样。
[解决办法]
要实现这个效果不是不可以,只是窗体上将无法显示所有的控件,因为将使用到层窗体效果。它的原理是这样的:
1 绘制一个渐变,除窗体本身大小为不透明区域外,从上到下为255-0的透明度。
2 一边移动这个渐变图层的垂直坐标,一边将这个渐变图层当前位置的透明度设置为窗体背景图的透明度。
以前仿QQ时写过,但这个效果本质上不好看,被我删了。只能告诉你思路了,只会VB不会C#,没办法。