[1] private rectWidth As double ,rectHeight As double
创新互联服务项目包括磐石网站建设、磐石网站制作、磐石网页制作以及磐石网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,磐石网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到磐石省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
[2] return rectWidth
[3] rectWidth=value
[4] return rectHeight
[5] rectHeight=value
[6]这个在注释语句里我也不清楚要怎么填,不会是题目搞错了吧。-_-|||
[7] return 2 *( rectWidth+ rectHeight)
[8] return rectWidth * rectHeight
[9] ,[10] 应该是对rectl的width 和height 属性赋值。
messagebox。show(“长方形rect1的周长是:” rectl.GetSize “长方形rect2的面积是:” rectl.GetArea)
这个类继承自Panel,把它加到你的项目里面,先运行一下,然后从工具箱里把它拖到窗体上,然后再向里面添加其它控件就可以了,支持Shift加选,Alt减选
Imports System.Linq
Imports System.Collections
Public Class MyPanel
Inherits Panel
' 选择模式,相交还是包含
Enum SelectMode
Intersects
Contains
End Enum
Dim down As New Point(-1, -1)
Dim rect As Rectangle
Dim selected As New List(Of Control)
Dim editting As IEnumerable(Of Control)
Dim mode As SelectMode = SelectMode.Contains
Dim shift, alt As Boolean
Public Sub New()
Me.DoubleBuffered = True
End Sub
Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
MyBase.OnMouseDown(e)
down = e.Location
editting = selected.ToArray().ToList()
OnMouseMove(e)
End Sub
Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
MyBase.OnMouseMove(e)
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim loc As New Point(Math.Min(down.X, e.X), Math.Min(down.Y, e.Y))
Dim size As New Size(Math.Abs(down.X - e.X), Math.Abs(down.Y - e.Y))
rect = New Rectangle(loc, size)
Dim cs As New List(Of Control)
For Each c In Controls
cs.Add(c)
Next
Dim a = cs.Where(Function(n As Control) (mode = SelectMode.Contains And rect.Contains(n.Bounds)) Or (mode = SelectMode.Intersects And rect.IntersectsWith(n.Bounds)))
If shift Then editting = a.Union(selected) Else If alt Then editting = selected.Except(a) Else editting = a
Invalidate()
End If
End Sub
Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
MyBase.OnMouseUp(e)
down = New Point(-1, -1)
selected = editting.ToList()
editting = Nothing
Invalidate()
End Sub
Protected Overrides Function ProcessKeyPreview(ByRef m As Message) As Boolean
Dim KeyCode As Keys = CInt(m.WParam) And CInt(Keys.KeyCode)
Dim d As Boolean
If m.Msg = H100 Or m.Msg = H104 Then d = True Else If m.Msg = H101 Or m.Msg = H105 Then d = False Else Return MyBase.ProcessKeyPreview(m)
If KeyCode = Keys.ShiftKey Then
shift = d
ElseIf KeyCode = Keys.Menu Then
alt = d
End If
Return MyBase.ProcessKeyPreview(m)
End Function
Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
For Each c As Control In IIf(editting Is Nothing, selected, editting)
e.Graphics.DrawRectangle(New Pen(Color.Gray) With {.DashStyle = Drawing2D.DashStyle.DashDot}, c.Left - 1, c.Top - 1, c.Width + 1, c.Height + 1)
Next
If (down.X 0) Then e.Graphics.DrawRectangle(New Pen(Color.Gray) With {.DashStyle = Drawing2D.DashStyle.DashDot}, rect)
End Sub
End Class
Picture1.Line (oldx, oldy)-(oldx, Y)
Picture1.Line (oldx, oldy)-(X, oldy)
Picture1.Line (oldx, Y)-(X, Y)
Picture1.Line (X, oldy)-(X, Y)
这个是vb6.0画长方形的代码,可以供你参考下
dim a as single=...'自己输入长方形的长
dim b as single=...'自己输入长方形的宽
dim c as single=a*b'计算面积
textbox1.text=c'显示面积