在按钮上绘图 [英] Drawing on a button

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

问题描述

你好,
我正在尝试在按钮上绘制一个矩形.我将按钮的宽度"和高度"设置为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 System.Windows.Input.MouseEventArgs) 手柄

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 System.Windows.SizeChangedEventArgs) 手柄

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

推荐答案



您不显示您在哪里定义按钮.按钮的大小可能取决于窗口或包含它的控件的大小.由于Rectangle具有固定的大小,不会改变,因此按钮可以增加边距以便将Rectangle置于其内容区域的中心.除此之外,30,30可能是从按钮边框的外边缘算起的,而20,20可能是从其内容区域的角落算起的,即,您必须添加边框粗细和填充以使坐标彼此匹配.
Hi,

you don't show where you define the Button. The size of the button probably depends on the size of the window or control that contains it. Since the Rectangle has a fixed size which it doesn't change, the button may add margin in order to center the Rectangle in its content area. In addition to that, the 30,30 probably is counted from the outer edge of the button's border, while the 20,20 is counted from the corner of its content area, i.e. you have to add border thickness and padding in order to make the coordinates match each other.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆