我曾嘗試創建一個調整大小的影片,但它并沒有真正發揮作用,而且也不流暢。
static System.Windows.Forms.Timer _Timer = new System.Windows.Forms.Timer()。
private void timer_Tick(object sender, EventArgs e)。
{
double _Width = ScreenSizeHelperPanel.Width;
double _Height = ScreenSizeHelperPanel.Height;
if (MainWindow.Width != _Width || MainWindow.Height != _Height)
{
MainWindow.Width = 50;
MainWindow.Height = 50;
CenterWindowOnScreen()。
}
elseprivate void Animate()
{
_Timer.Tick = new EventHandler(timer_Tick)。
_Timer.Interval = (20);
_Timer.Start();
}
private void CenterWindowOnScreen()
{
double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;
double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight;
double windowWidth = this.Width;
double windowHeight = this.Height;
this.Left = (screenWidth / 2) - (windowWidth / 2) 。
this.Top = (screenHeight / 2) - (windowHeight / 2) 。
}
ScreenSizeHelperPanel XAML:
<DockPanel Width="{x:Static SystemParameters.MaximizedPrimaryScreenWidth}"
Height="{x:Static SystemParameters.MaximizedPrimaryScreenHeight}"。
x:Name="ScreenSizeHelperPanel"/>
有誰知道我怎樣才能做到這一點? 我已經看到了這種方法,但是它出現了關于整數/雙數不存在的錯誤,我不知道如何解決,因為自動系統進一步破壞了代碼而不是修復。
uj5u.com熱心網友回復:
從你對我的評論的回答中,我可以給你一個超級簡單的方法來制作一個平滑的調整大小的影片,只需要3行代碼。
基本上你可以做的,是將視窗的樣式改為singleborder或3dborderwindow,并將它的視窗狀態設定為maximized,因為無邊界的視窗沒有調整大小的影片,緊接著你可以將它設定為無邊界的視窗,這其實是不明顯的,因為它發生在不到3s內。
WindowStyle = WindowStyle.SingleBorderWindow;
WindowState = WindowState.Maximized;
WindowStyle = WindowStyle.None。
然而,如果你確實想要自定義影片,較慢的影片等。你可以研究評論中提到的WPF影片,但是如果這個答案符合你的需求,我很高興能幫助你!
如果你想要自定義影片,那么你可以研究WPF影片。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/307902.html
標籤:
上一篇:動態添加一個用戶控制元件
