自学WPF--第三课透明与混色

前端之家收集整理的这篇文章主要介绍了自学WPF--第三课透明与混色前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

WPF可是很好的设置空间与窗体透明,通过属性Opacity设置(属性值介于0-1),窗体透明还需设置窗体的AllowTransparency属性为True(允许透明),以及WindowStyle为None(窗体无边框),

示例如下图:

代码如下:

<Grid Opacity="0.5">

<Ellipse Height="89" HorizontalAlignment="Left" Margin="57,44,0" Name="ellipse1" Stroke="Black" VerticalAlignment="Top" Width="163" Fill="Red" Opacity="0.5" />

<Ellipse Height="88" HorizontalAlignment="Left" Margin="149,0" Name="ellipse2" Stroke="Black" VerticalAlignment="Top" Width="185" Fill="Lime" Opacity="0.5" />

<Ellipse Height="100" HorizontalAlignment="Left" Margin="88,95,0" Name="ellipse3" Stroke="Black" VerticalAlignment="Top" Width="200" Fill="Blue" Opacity="0.5" />

</Grid>

设置鼠标控制窗体移动事件代码如下

C#:

private double oldx,oldy;

private void Window_MouseDown(object sender,MouseButtonEventArgs e)

{

oldx = e.GetPosition(this).X;

oldy = e.GetPosition(this).Y;

}

private void Window_MouseMove(object sender,MouseEventArgs e)

{

if (e.LeftButton == MouseButtonState.Pressed)

{

double x = e.GetPosition(this).X;

double y = e.GetPosition(this).Y;

double dx = x - oldx;

double dy = y - oldy;

this.Left += dx;

this.Top += dy;

oldx = x;

oldy = y;

}

}

vb.net代码

Class MainWindow
Dim oldx As Double
Dim oldy As Double


Private Sub MainWindow_MouseDown(ByVal sender As Object,ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Me.MouseDown
oldx = e.GetPosition(Me).X
oldy = e.GetPosition(Me).Y
End Sub

Private Sub MainWindow_MouseMove(ByVal sender As Object,ByVal e As System.Windows.Input.MouseEventArgs) Handles Me.MouseMove

If e.LeftButton = MouseButtonState.Pressed Then
Dim x As Double = e.GetPosition(Me).X
Dim y As Double = e.GetPosition(Me).Y
Dim dx As Double = x - oldx
Dim dy As Double = y - oldy
Me.Left += dx
Me.Top += dy
oldx = x
oldy = y
End If

End Sub End Class

猜你在找的VB相关文章