Jump to content

Fixar posição de Form


sergiofer
 Share

Recommended Posts

Bom dia

Não sei se é isto que queres, mas se quiseres defenir a posição da janela podes usar:

Me.Location = New Point(30, 90)

mas se a quiseres fixar sem o utilizador poder arrastar, nas propriedades da form em FormBorderStyle colocas "None"

Espero que seja isto que procuras..

Link to comment
Share on other sites

Vê este exemplo de como o fazer:

Imports System.ComponentModel
Imports System.Windows.Forms

Public Class MoveableForm
    Inherits Form

    Private Const WM_NCLBUTTONDOWN As Int32 = &HA1
    Private Const WM_SYSCOMMAND As Int32 = &H112

    Private Const HTCAPTION As Int32 = &H2

    Private Const SC_MOVE As Int32 = &HF010

    Private m_Moveable As Boolean

    Public Sub New()
        MyBase.New()
        Me.Moveable = True
    End Sub

    < _
        Category("Behavior"), _
        Description("Allows the form to be moved.") _
    > _
    Public Property Moveable() As Boolean
        Get
            Return m_Moveable
        End Get
        Set(ByVal Value As Boolean)
            m_Moveable = Value
        End Set
    End Property

    Protected Overrides Sub WndProc(ByRef m As Message)
        If Not m_Moveable Then
            If _
                ( _
                    m.Msg = WM_SYSCOMMAND AndAlso _
                    m.WParam.ToInt32() = SC_MOVE _
                ) _
                OrElse _
                ( _
                    m.Msg = WM_NCLBUTTONDOWN AndAlso _
                    m.WParam.ToInt32() = HTCAPTION _
                ) _
            Then
                Return
            End If
        End If
        MyBase.WndProc(m)
    End Sub
End Class

Fonte: Preventing a form from being moved

Link to comment
Share on other sites

Vê este exemplo de como o fazer:

Imports System.ComponentModel
Imports System.Windows.Forms

Public Class MoveableForm
    Inherits Form

    Private Const WM_NCLBUTTONDOWN As Int32 = &HA1
    Private Const WM_SYSCOMMAND As Int32 = &H112

    Private Const HTCAPTION As Int32 = &H2

    Private Const SC_MOVE As Int32 = &HF010

    Private m_Moveable As Boolean

    Public Sub New()
        MyBase.New()
        Me.Moveable = True
    End Sub

    < _
        Category("Behavior"), _
        Description("Allows the form to be moved.") _
    > _
    Public Property Moveable() As Boolean
        Get
            Return m_Moveable
        End Get
        Set(ByVal Value As Boolean)
            m_Moveable = Value
        End Set
    End Property

    Protected Overrides Sub WndProc(ByRef m As Message)
        If Not m_Moveable Then
            If _
                ( _
                    m.Msg = WM_SYSCOMMAND AndAlso _
                    m.WParam.ToInt32() = SC_MOVE _
                ) _
                OrElse _
                ( _
                    m.Msg = WM_NCLBUTTONDOWN AndAlso _
                    m.WParam.ToInt32() = HTCAPTION _
                ) _
            Then
                Return
            End If
        End If
        MyBase.WndProc(m)
    End Sub
End Class

Fonte: Preventing a form from being moved

Funciona

Será possivel explicares o que faz mais concretamente, e se para fazer isto noutras Forms tenho que colocar o código dentro dessas forms, ou posso colocar na main, e depois utilizar essa propriedade nas restantes forms?

Obrigado a todos pela ajuda

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.