silverlight   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了SilverLight鼠标绘制矩形大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

技术要点: 1.Canvas控件布局用到的Canvas.TopProperty以及Canvas.LeftProperty属性 2.MouSELEftButtonDown,MouseMove,MouSELEftButtonUp方法处理程序的调用 VB.NET代码如下:     Private isAddMouseEvent As Boolean = false     Private rectang

技术要点:

1.Canvas控件布局用到的Canvas.TopProperty以及Canvas.LeftProperty属性

2.MouSELEftButtonDown,MouseMove,MouSELEftButtonUp方法处理程序的调用

VB.NET代码如下:

    Private isAddMouseEvent As Boolean = false
    Private rectangle As Rectangle
    Private point as Point
    Private Sub btnMain_Click(ByVal sender As System.object,ByVal e As System.Windows.RoutedEventArgs) Handles btnMain.Click
        If Not isAddMouseEvent Then
            AddHandler canvasmain.MouSELEftButtonDown,AddressOf MouseEventDown
            isAddMouseEvent = True
            Me.btnMain.IsEnabled = false
        End If
    End Sub
    Private Sub MouseEventDown(ByVal sender As Object,ByVal e As MouseEventArgs)
        rectangle = New Rectangle()
        point = e.GetPosition(canvasmain)
        rectangle.SETVALue(Canvas.LeftProperty,point.X)
        rectangle.SETVALue(Canvas.TopProperty,point.Y)
        rectangle.opacity = 1
        rectangle.Fill = New SolidColorBrush(Colors.bluE)
        rectangle.RadiusX = 10
        rectangle.RadiusY = 10
        AddHandler canvasmain.MouseMove,AddressOf MouseMove
        AddHandler canvasmain.MouSELEftButtonUp,AddressOf MouseUp
        canvasmain.Children.Add(rectanglE)
    End Sub
    Private Sub MouseMove(ByVal sender As Object,ByVal e As MouseEventArgs)
        Dim tempPorint = e.GetPosition(canvasmain)
        If tempPorint.X > point.X Then
            rectangle.Width = tempPorint.X - point.X
        End If
        If tempPorint.X <= point.X Then
            rectangle.SETVALue(Canvas.LeftProperty,tempPorint.X)
            rectangle.Width = point.X - tempPorint.X
        End If
        If tempPorint.Y > point.Y Then
            rectangle.Height = tempPorint.Y - point.Y
        End If
        If tempPorint.Y <= point.Y Then
            rectangle.Height = point.Y - tempPorint.Y
            rectangle.SETVALue(Canvas.TopProperty,tempPorint.Y)
        End If
    End Sub
    Private Sub MouseUp(ByVal sender As Object,ByVal e As MouseEventArgs)
        RemoveHandler canvasmain.MouSELEftButtonUp,AddressOf MouseUp
        RemoveHandler canvasmain.MouseMove,AddressOf MouseMove
        RemoveHandler canvasmain.MouSELEftButtonDown,AddressOf MouseEventDown
        isAddMouseEvent = false
        btnMain.IsEnabled = True
    End Sub

布局@L_674_6@代码如下:

<Grid x:Name="LayoutRoot" BACkground="White">        <Canvas x:Name="canvasmain" Width="1000" Height="1000" BACkground="Black" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">                    </Canvas>        <Button x:Name="btnMain" Width="90" Height="28" Content="点我开始绘制矩形" Margin="0 0 0 0" VerticalAlignment="Top" HorizontalAlignment="Left">                    </Button>    </Grid>

大佬总结

以上是大佬教程为你收集整理的SilverLight鼠标绘制矩形全部内容,希望文章能够帮你解决SilverLight鼠标绘制矩形所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。