3
A
回答
6
我自己回答了这个问题。这里是一些示例代码。
static System.Windows.Forms.Timer _Timer = new System.Windows.Forms.Timer();
int _Stop = 0;
private void This_Loaded(object sender, RoutedEventArgs e)
{
_Timer.Tick += new EventHandler(timer_Tick);
_Timer.Interval = (20);
resize(500,500)
}
private void timer_Tick(Object myObject, EventArgs myEventArgs)
{
if (_Stop == 0)
{
_RatioHeight = ((this.Height - _Height) /12)* -1;
_RatioWidth = ((this.Width - _Width) /12)* -1;
}
_Stop++;
this.Height += _RatioHeight;
this.Width += _RatioWidth;
if (_Stop == 12)
{
_Timer.Stop();
_Timer.Enabled = false;
_Timer.Dispose();
_Stop = 0;
this.Height = _Height;
this.Width = _Width;
}
}
public void resize(double _PassedHeight, double _PassedWidth)
{
_Height = _PassedHeight;
_Width = _PassedWidth;
_Timer.Enabled = true;
_Timer.Start();
}
非常快速地调整窗口在12个“滴答”中的速度,可以在_Timer.Interval中减慢。经过12次剔除后,将最终调整至确切大小。
希望这有助于someome。
-1
System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += dispatcherTimer_Tick;
dispatcherTimer.Interval = new TimeSpan(0,0,0,0,10); // Control animation speed/how often the tick will be called.
dispatcherTimer.Start();
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
if (this.Width < 500)
{
this.Width += 10;
}
else
{
DispatcherTimer timer = (DispatcherTimer)sender;
timer.Stop();
}
}
4
您可以使用窗口动画此这里是XAML
<Window x:Class="dlgControls" Name="dlgControls"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="" Height="300" Width="300">
<Window.Resources>
<Storyboard x:Key="showWin">
<DoubleAnimation Storyboard.TargetName="dlgControls" Storyboard.TargetProperty="Height" Duration="0:0:.5" To="300" BeginTime="0:0:1"/>
</Storyboard>
<Storyboard x:Key="hideWin">
<DoubleAnimation Storyboard.TargetName="dlgControls" Storyboard.TargetProperty="Height" Duration="0:0:.5" To="150" BeginTime="0:0:1"/>
</Storyboard>
</Window.Resources>
<Grid RenderTransformOrigin="0.5,0.5">
<Button Name="btnOpen" Content="Open" HorizontalAlignment="Left" Margin="184,98,0,0" VerticalAlignment="Top" Width="75"/>
<Button Name="btnClose" Content="Close" HorizontalAlignment="Left" Margin="184,222,0,0" VerticalAlignment="Top" Width="75"/>
</Grid>
</Window>
动画使用这样的代码
Imports System.Windows.Media.Animation
Public Class dlgControls
Dim showWin As Storyboard
Dim hideWin As Storyboard
Private Sub btnOpen_Click(sender As Object, e As Windows.RoutedEventArgs) Handles btnOpen.Click
BeginStoryboard(showWin)
End Sub
Private Sub dlgControls_Loaded(sender As Object, e As Windows.RoutedEventArgs) Handles Me.Loaded
showWin = Me.Resources("showWin")
hideWin = Me.Resources("hideWin")
End Sub
Private Sub btnClose_Click(sender As Object, e As Windows.RoutedEventArgs) Handles btnClose.Click
BeginStoryboard(hideWin)
End Sub
End Class
相关问题
- 1. 相对于高度的自动宽度+调整窗口大小
- 2. 窗口宽度和调整大小
- 3. 调整窗口大小的Webview的宽度/高度调整大小
- 4. jQuery窗口调整大小问题 - 高度/宽度计算
- 5. 设置高度和宽度的控制窗口wihtin大小WPF
- 6. 调整窗口大小的div宽度
- 7. 在窗口调整大小设置最小高度和最小宽度
- 8. 为WPF窗口宽度和高度设置动画效果
- 9. Div的自动调整大小的窗口的宽度和高度
- 10. WPF行标题宽度和列标题高度调整大小
- 11. 在窗口调整大小的iframe的宽度调整大小
- 12. 宽度:调整窗口大小(CSS)时调整大小100%
- 13. 在窗口调整大小元素宽度调整大小jquery
- 14. 动画宽度调整大小100%
- 15. 在调整窗口大小时调整滑块的宽度/高度
- 16. C++如何获得窗口大小(宽度和高度)?
- 17. 当窗口高度调整大小时调整图像大小
- 18. 调整窗口大小调整页眉和页脚宽度
- 19. 动画大小调整UIView的高度
- 20. WPF Storyboard无法调整窗口宽度与高度
- 21. 根据内容宽度和高度调整弹出窗口的大小
- 22. 更改图像的宽度和高度,同时窗口调整大小
- 23. 在调整浏览器窗口大小时,背景图像的宽度和高度都会调整大小
- 24. jQuery:动态设置div高度和窗口大小调整
- 25. PHP图像大小调整 - 设置高度和宽度自动
- 26. AutoLayout动态调整大小UILabel的高度和宽度
- 27. 将画布调整为完整的浏览器窗口宽度和高度
- 28. 自动调整大小画布到浏览器宽度和高度
- 29. 最大高度和宽度与jQuery的大小调整
- 30. 调整窗口大小时更新窗口内部高度
不能相信这不会有更多的选票。非常优雅,只是解决我的问题 – TaterJuice 2016-08-18 08:18:08