【问题标题】:VSTUDIO2012 How to make a "borderstyle = none" form MOVEABLEVSTUDIO2012 如何制作“borderstyle = none”表格 MOVEABLE
【发布时间】:2012-11-07 15:25:39
【问题描述】:

我正在学习 vstudio 2012,我正在尝试使用“borderstyle = none”制作可移动的表单,但我做不到。

我在 Google 中找到的所有关于 vb4 5 和 6 的信息都谈到了这个问题,版本对我来说太早了,我无法使用它们(我不知道如何使用)。

我的声明很简单,我只需要通过单击应用程序(表单上的任何位置)使窗口可移动:

Public Class Form1

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Label2.Text = "X: " & MousePosition.X
        Label3.Text = "Y: " & MousePosition.Y

    End Sub

    Sub Form1_KeyPress(ByVal sender As Object, _
      ByVal e As KeyPressEventArgs) Handles Me.KeyPress
        If e.KeyChar >= ChrW(3) Then
            Clipboard.SetDataObject(Label2.Text & " " & Label3.Text)
        End If
    End Sub

End Class

有什么帮助吗?谢谢阅读

【问题讨论】:

  • Resize WinForm, with no border? 的可能重复项
  • 我认为不是,这个问题是关于 C# 的!
  • Windows、.NET 和 Winforms 都不关心您使用什么语言。如果您无法弄清楚,请使用在线 C#-to-VB.NET 转换器。

标签: winforms visual-studio forms visual-studio-2012


【解决方案1】:

我已经解决了,谢谢。

Private ArrastrarForm As Boolean
Private PosicionMouseHeader As Point
Private tmpPoint As Point


Private Sub Form1_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
    If e.Button = Windows.Forms.MouseButtons.Left Then
        ArrastrarForm = True
        PosicionMouseHeader = e.Location
    End If
End Sub

Private Sub Form1_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
    If ArrastrarForm Then
        tmpPoint = Me.Location + e.Location - PosicionMouseHeader
        Me.Location = tmpPoint
    End If
End Sub

Private Sub Form1_MouseUp(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
    If e.Button = Windows.Forms.MouseButtons.Left Then
        ArrastrarForm = False
    End If
End Sub

再见!

【讨论】:

    猜你喜欢
    • 2014-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多