本文介绍了在按钮上绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我正在尝试在按钮上绘制一个矩形.我将按钮的宽度"和高度"设置为200.
请尝试我的代码,并告诉我为什么将鼠标置于我设置的点(20,20)时实际上显示为(30,30)

这是代码:

班级

Hello,
I am trying to draw a rectangle on a button. I set the Width and Height of the button to be 200.
Please try my code and tell me why when you put the mouse on the point that I set (20,20) it is actually (30,30) shown on the Window title.

Here is the code :

Class

Window1

Window1

 

昏暗 Pt0

Dim Pt0 As Point

 

昏暗 Pt1

Dim Pt1 As Point

 

昏暗 Pt2

Dim Pt2 As Point

 

昏暗 Pt3

Dim Pt3 As Point

 

昏暗 矩形 新建 多边形

Dim Rectangle As New Polygon

 

私有 Btn_MouseMove( ByVal 发送者 As 对象 ByVal e As System.Windows.Input.MouseEventArgs) 手柄 Btn.MouseMove

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

 

.Title = e.GetPosition(Btn).X& " ," & e.GetPosition(Btn).Y

Me.Title = e.GetPosition(Btn).X & " , " & e.GetPosition(Btn).Y

 

结束

End Sub

私有 Btn_SizeChanged( ByVal 发送者 As 对象 ByVal e As System.Windows.SizeChangedEventArgs) 手柄 Btn.SizeChanged

Pt0 =

Private Sub Btn_SizeChanged(ByVal sender As Object, ByVal e As System.Windows.SizeChangedEventArgs) Handles Btn.SizeChanged

Pt0 =

点(20,20)

Pt1 =

New Point(20, 20)

Pt1 =

点(180,20)

Pt2 =

New Point(180, 20)

Pt2 =

点(180,180)

Pt3 =

New Point(180, 180)

Pt3 =

点(20,180)

Rectangle.Points.Add(Pt0)

New Point(20, 180)

Rectangle.Points.Add(Pt0)

Rectangle.Points.Add(Pt1)

Rectangle.Points.Add(Pt1)

Rectangle.Points.Add(Pt2)

Rectangle.Points.Add(Pt2)

Rectangle.Points.Add(Pt3)

Rectangle.Points.Add(Pt3)

Rectangle.Stroke =刷子.黑色

Rectangle.Stroke = Brushes.Black

Btn.Content =矩形

Btn.Content = Rectangle

结束

结束

End Sub

End

Class

推荐答案


这篇关于在按钮上绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:30