我们在学习一门编程语言的时候,需要通过不断的实践去积累经验,来加深我们对这门语言的理解程度。对于 VB.NET的学习同样也是如此。在这里我们先通过一段VB.NET中心旋转图像的实现代码来初步的了解一下这门语言的编写方式和应用方法。
目前创新互联已为上千的企业提供了网站建设、域名、虚拟空间、网站托管、服务器租用、企业网站设计、盐城网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
鼠标拖拽旋转。实现任意角度的VB.NET中心旋转图像。
- Public Class Form1
- Dim bmp As Bitmap
- Dim bmpsize As Single
- Dim gr As Graphics
- Dim pb As Point
- Dim po As PointF
- Private Sub Form1_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load- bmpsize = Math.Sqrt(Me.Icon.Width ^
2 + Me.Icon.Height ^ 2)- bmp = New Bitmap(CInt(bmpsize), CInt(bmpsize))
- gr = Graphics.FromImage(bmp)
- po = New PointF((bmpsize - Me.Icon.Width)
/ 2, (bmpsize - Me.Icon.Height) / 2)- gr.DrawIcon(Me.Icon, po.X, po.Y)
- PictureBox1.Image = bmp
- End Sub
- Private Sub PictureBox1_MouseDown(ByVal
sender As Object, ByVal e As System.Windows.
Forms.MouseEventArgs) Handles PictureBox1.MouseDown- pb = e.Location
- End Sub
- Private Sub PictureBox1_MouseMove(ByVal
sender As Object, ByVal e As System.Windows.
Forms.MouseEventArgs) Handles PictureBox1.MouseMove- If Not pb = Point.Empty Then
- 'O\-----------B
- ' \
- ' \
- ' \
- ' E
- Dim vOB, vOE As Windows.Vector
- vOB = New Windows.Vector(bmpsize / 2,
bmpsize / 2) - New Windows.Vector(pb.X, pb.Y)- vOE = New Windows.Vector(bmpsize / 2, bmpsize / 2)
- New Windows.Vector(e.X, e.Y)- '可以用叉乘求面积,正负号代表旋转方向,而后正弦定理求角度,
- Dim O As Double = Windows.Vector.AngleBetween(vOB, vOE)
- '若角度为有效值
- gr.TranslateTransform(bmpsize / 2, bmpsize / 2)
'移动坐标至图像中心- gr.RotateTransform(O) '按角度旋转
- gr.TranslateTransform(-bmpsize / 2, -bmpsize / 2)
'移回- gr.Clear(Color.Transparent) '清除原有图像
- gr.DrawIcon(Me.Icon, po.X, po.Y) '绘制新图像
- PictureBox1.Image = bmp
- pb = e.Location
- End If
- End Sub
- Private Sub PictureBox1_MouseUp(ByVal sender As
Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Handles PictureBox1.MouseUp- pb = Point.Empty
- End Sub
- End Class
VB.NET中心旋转图像的具体操作方法就为大家介绍到这里,希望对大家有所帮助。
标题名称:VB.NET中心旋转图像实现技巧分享
地址分享:http://www.csdahua.cn/qtweb/news43/231643.html
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网