Jump to content

Windows Form sobre tudo


manuelito
 Share

Recommended Posts

Bom dia pessoal, sou iniciante em programação e estou desenvolvendo um menuzim.

- Tem apenas um Form e preciso que ele fique em tela cheia e bloqueie o ctrl + alt + del e a barra de ferramentas(menu iniciar).

Resumindo: o Form q tem ficar sobre tudo e não deixar fazer nada fora dele nem sair dele sem fechar ele.

ObrigadoWindows Form acima de tudo

Link to comment
Share on other sites

Crias uma classe com isto.

Imports System.Drawing
Imports System.Windows.Forms
Imports System.Runtime.InteropServices

Namespace Org.Vesic.WinForms
    ''' <summary>
    ''' Selected Win AI Function Calls
    ''' </summary>

    Public Class WinApi
        <DllImport("user32.dll", EntryPoint:="GetSystemMetrics")> _
        Public Shared Function GetSystemMetrics(ByVal which As Integer) As Integer
        End Function

        <DllImport("user32.dll")> _
        Public Shared Sub SetWindowPos(ByVal hwnd As IntPtr, ByVal hwndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal width As Integer, ByVal height As Integer, _
   ByVal flags As UInteger)
        End Sub

        Private Const SM_CXSCREEN As Integer = 0
        Private Const SM_CYSCREEN As Integer = 1
        Private Shared HWND_TOP As IntPtr = IntPtr.Zero
        Private Const SWP_SHOWWINDOW As Integer = 64
        ' 0x0040
        Public Shared ReadOnly Property ScreenX() As Integer
            Get
                Return GetSystemMetrics(SM_CXSCREEN)
            End Get
        End Property

        Public Shared ReadOnly Property ScreenY() As Integer
            Get
                Return GetSystemMetrics(SM_CYSCREEN)
            End Get
        End Property

        Public Shared Sub SetWinFullScreen(ByVal hwnd As IntPtr)
            SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY, _
             SWP_SHOWWINDOW)
        End Sub
    End Class

    ''' <summary>
    ''' Class used to preserve / restore state of the form
    ''' </summary>
    Public Class FormState
        Private winState As FormWindowState
        Private brdStyle As FormBorderStyle
        Private topMost As Boolean
        Private bounds As Rectangle

        Private IsMaximized As Boolean = False

        Public Sub Maximize(ByVal targetForm As Form)
            If Not IsMaximized Then
                IsMaximized = True
                Save(targetForm)
                targetForm.WindowState = FormWindowState.Maximized
                targetForm.FormBorderStyle = FormBorderStyle.None
                targetForm.TopMost = True
                WinApi.SetWinFullScreen(targetForm.Handle)
            End If
        End Sub

        Public Sub Save(ByVal targetForm As Form)
            winState = targetForm.WindowState
            brdStyle = targetForm.FormBorderStyle
            topMost = targetForm.TopMost
            bounds = targetForm.Bounds
        End Sub

        Public Sub Restore(ByVal targetForm As Form)
            targetForm.WindowState = winState
            targetForm.FormBorderStyle = brdStyle
            targetForm.TopMost = topMost
            targetForm.Bounds = bounds
            IsMaximized = False
        End Sub
    End Class
End Namespace

Depois basta:

Dim formstate As New NomeDoProjecto.Org.Vesic.WinForms.FormState

formstate.maximize(me)

E tem o fullscreen 😕

Cumps.cmd

Link to comment
Share on other sites

cmd eu criei uma class com o codigo que tens:

Imports System.Drawing
Imports System.Windows.Forms
Imports System.Runtime.InteropServices

Namespace Org.Vesic.WinForms
    ''' <summary>
    ''' Selected Win AI Function Calls
    ''' </summary>

    Public Class WinApi
        <DllImport("user32.dll", EntryPoint:="GetSystemMetrics")> _
        Public Shared Function GetSystemMetrics(ByVal which As Integer) As Integer
        End Function

        <DllImport("user32.dll")> _
        Public Shared Sub SetWindowPos(ByVal hwnd As IntPtr, ByVal hwndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal width As Integer, ByVal height As Integer, _
   ByVal flags As UInteger)
        End Sub

        Private Const SM_CXSCREEN As Integer = 0
        Private Const SM_CYSCREEN As Integer = 1
        Private Shared HWND_TOP As IntPtr = IntPtr.Zero
        Private Const SWP_SHOWWINDOW As Integer = 64
        ' 0x0040
        Public Shared ReadOnly Property ScreenX() As Integer
            Get
                Return GetSystemMetrics(SM_CXSCREEN)
            End Get
        End Property

        Public Shared ReadOnly Property ScreenY() As Integer
            Get
                Return GetSystemMetrics(SM_CYSCREEN)
            End Get
        End Property

        Public Shared Sub SetWinFullScreen(ByVal hwnd As IntPtr)
            SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY, _
             SWP_SHOWWINDOW)
        End Sub
    End Class

    ''' <summary>
    ''' Class used to preserve / restore state of the form
    ''' </summary>
    Public Class FormState
        Private winState As FormWindowState
        Private brdStyle As FormBorderStyle
        Private topMost As Boolean
        Private bounds As Rectangle

        Private IsMaximized As Boolean = False

        Public Sub Maximize(ByVal targetForm As Form)
            If Not IsMaximized Then
                IsMaximized = True
                Save(targetForm)
                targetForm.WindowState = FormWindowState.Maximized
                targetForm.FormBorderStyle = FormBorderStyle.None
                targetForm.TopMost = True
                WinApi.SetWinFullScreen(targetForm.Handle)
            End If
        End Sub

        Public Sub Save(ByVal targetForm As Form)
            winState = targetForm.WindowState
            brdStyle = targetForm.FormBorderStyle
            topMost = targetForm.TopMost
            bounds = targetForm.Bounds
        End Sub

        Public Sub Restore(ByVal targetForm As Form)
            targetForm.WindowState = winState
            targetForm.FormBorderStyle = brdStyle
            targetForm.TopMost = topMost
            targetForm.Bounds = bounds
            IsMaximized = False
        End Sub
    End Class
End Namespace

Depois deveria declarar isto :

Dim formstate As New NomeDoProjecto.Org.Vesic.WinForms.FormState

formstate.maximize(me)

mas esta declaraçao faço-a onde? e a parte do

 formstate.maximize(me)

e para chamar a classe?

Nao percebi bem. e que eu quero que ao clicar num botao ela execute o teu codigo....

Link to comment
Share on other sites

A declaração fazes na form que queres que fique em fullscreen.

Esse formstate.maxime(me) deves colocar no evento do botão, ou outro controlo, quando quiseres que a form fique grande.

A class cria-te a parte ou tambem foi na parte onde se encontra o codigo do form1 por ex?

Link to comment
Share on other sites

futero_gallery é o nome do projecto ?

E o Impossível foi criado por pessoas fracas pra acabar com o sonho das pessoas fortes. Não deixes que acabem com o teu. Sonha , luta , ambiciona e realiza. Se amas , se gostas tu vais conseguir. Cala todas as pessoas que um dia duvidaram de ti e prova que foste mais forte de qualquer outro.

Link to comment
Share on other sites

cmd esqueci de te agradecer ... por acaso funcionou e guardei a classe em  .vb pra depois usar noutro programa 😄

E o Impossível foi criado por pessoas fracas pra acabar com o sonho das pessoas fortes. Não deixes que acabem com o teu. Sonha , luta , ambiciona e realiza. Se amas , se gostas tu vais conseguir. Cala todas as pessoas que um dia duvidaram de ti e prova que foste mais forte de qualquer outro.

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.