五、源码 建立一个窗体,放置一个按钮,点击该按钮创建动态建立一个可以拖动和缩放的按钮。全部源码如下: Public Class Form1 Inherits System.Windows.Forms.Form Enum EnumMousePointPosition MouseSizeNone = 0 '无 MouseSizeRight = 1 '拉伸右边框 MouseSizeLeft = 2 '拉伸左边框 MouseSizeBottom = 3 '拉伸下边框 MouseSizeTop = 4 '拉伸上边框 MouseSizeTopLeft = 5 '拉伸左上角 MouseSizeTopRight = 6 '拉伸右上角 MouseSizeBottomLeft = 7 '拉伸左下角 MouseSizeBottomRight = 8 '拉伸右下角 MouseDrag = 9 '鼠标拖动 End Enum Dim m_MousePointPosition As EnumMousePointPosition Dim p, p1 As Point Private Sub MyMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) p = New Point(e.X, e.Y) '记录光标开始拖动点 p1 = New Point(e.X, e.Y) End Sub Private Sub MyMouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) m_MousePointPosition = EnumMousePointPosition.MouseSizeNone Me.Cursor = Cursors.Arrow End Sub Private Sub MyMouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) If e.Button = MouseButtons.Left Then Select Case m_MousePointPosition Case EnumMousePointPosition.MouseDrag sender.Location = New Point(sender.Left + e.X - p.X, sender.Top + e.Y - p.Y) Case EnumMousePointPosition.MouseSizeBottom sender.Size = New Size(sender.Width, sender.Height + e.Y - p1.Y) p1 = New Point(e.X, e.Y) '记录光标拖动的当前点 Case EnumMousePointPosition.MouseSizeBottomRight
|
正在阅读:编程必学:控件的拖动和缩放技术全解编程必学:控件的拖动和缩放技术全解
2004-12-09 10:11
出处:CSDN
责任编辑:linjixiong
键盘也能翻页,试试“← →”键