我已将以下参数添加到我的 Window
:
WindowStyle="None"
WindowStartupLocation="CenterScreen"
AllowsTransparency="True"
ResizeMode="NoResize" Background="Transparent"
现在我无法移动 Window
,所以我将以下部分代码添加到我的 Window
:
#region Window: Moving
private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DragMove();
}
#endregion
我还必须指定我的 Window
中的 XAML
代码如下(Window
看起来像 Polygon
):
<Window Title="New Science"
Height="588" Width="760" MinHeight="360" MinWidth="360"
WindowStyle="None" WindowStartupLocation="CenterScreen"
AllowsTransparency="True"
ResizeMode="NoResize" Background="Transparent"
xmlns:my="clr-namespace:Bourlesque.Lib.Windows.Media;assembly=Bourlesque.Lib.Windows.Media">
<Grid>
<my:UniPolygon DefaultRadiusIn="10" DefaultRadiusOut="10" Fill="#FF92C2F2" Name="m_tPlgOuter" Offset="0" Points=" 0;26;; 10;19;10;; 10;0;; 265;0;20;; 290;20;20;; -60,1;20;3;; -60,1;5;10;; -40,1;5;10;; -40,1;20;2.5;; -35,1;20;2.5;; -35,1;5;10;; -15,1;5;10;; -15,1;20;3;; 0,1;20;; 0,1;0,1;; 0;0,1;; " Stretch="None" Stroke="#FF535353" StrokeThickness="0.1" />
</Grid>
</Window>
我想知道我应该怎么做才能让 Window
改变它在鼠标拖动时的位置,以及添加什么来调整窗口大小,前提是我要添加的控件和其他东西会也调整大小(我发现这段代码可以调整大小,我想知道是否合适 here)。
最佳答案
我使用了 MouseDown 事件:
<Window .....
MouseDown="Window_MouseDown" >
使用此代码:
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if(e.ChangedButton == MouseButton.Left)
this.DragMove();
}
关于C# WPF 移动窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16608523/