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

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

概述  WPF可是很好的设置空间与窗体透明,通过属性Opacity设置(属性值介于0-1),窗体透明还需设置窗体的AllowTransparency属性为True(允许透明),以及WindowStyle为None(窗体无边框), 示例如下图: 代码如下:     <Grid Opacity="0.5">  <Ellipse Height="89" HorizontalAlignment="Left"

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

总结

以上是内存溢出为你收集整理的自学WPF--第三课透明与混色全部内容,希望文章能够帮你解决自学WPF--第三课透明与混色所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1292059.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-10
下一篇 2022-06-10

发表评论

登录后才能评论

评论列表(0条)

保存