加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-16 22:51:47 所属栏目:大数据 来源:网络整理
导读:WPF可是很好的设置空间与窗体透明,通过属性Opacity设置(属性值介于0-1),窗体透明还需设置窗体的AllowTransparency属性为True(允许透明),以及WindowStyle为None(窗体无边框), 示例如下图: 代码如下: Grid Opacity="0.5" Ellipse Height="89" Horizontal

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读