a3deluxe Posted November 27, 2015 at 07:48 AM Report Share #590134 Posted November 27, 2015 at 07:48 AM Olá, Precisava de uma ajuda no seguinte problema: Tenho um Form com uma PictureBox por cima a ocupar o espaço na totalidade do Form, para funcionar como Botão de fechar num programa externo. O programa externo não tem nenhum Botão para o poder fechar. 1- Quando inicio o Form aparece assim. 2- Quando inicio o programa externo o tamanho e o meu Form que fica sobreposto muda a resolução e fica maior. Fica assim: Acho que pode ter a ver com o programa externo ele muda a resolução do ecran. O que acham? O código: // Public Class ExitButton Private Sub ExtButton_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.WindowState = FormWindowState.Normal End Sub Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click Kill.Process End Sub End Class - No Form defini o Máximo size e na PictureBox Também, pensei que poderia ajudar, mas não. - Se carregar sobre o meu Form ( neste caso botão) funciona bem, fecha o programa. Obrigado Link to comment Share on other sites More sharing options...
Muryllo Posted November 28, 2015 at 06:01 PM Report Share #590161 Posted November 28, 2015 at 06:01 PM (edited) EDIT : Module __RUN ' '++++++++++++++++++++++++++++++++ ENUMERADOR DE POSIÇÕES ++++++++++++++++++++++++++++++++ ' Public Enum Window_Location As Integer Left_Top = 1 Left_Down = 2 Right_Top = 3 Right_Down = 4 End Enum ' '++++++++++++++++++++++++++++ CRIAR E REDIMENSIONAR JANELAS +++++++++++++++++++++++++++++ ' Public Function Resize_Window(ByVal Window As Form, ByVal Position As Point) As Boolean Try If Window Is Nothing Then Return False Else window.Location = Position Return True End If Catch NTSTATUS As Exception Return False End Try End Function ' Public Function Create_Window(ByVal Window As Form, ByVal Position As Point, ByVal Visible As Boolean) As Boolean Try If Window Is Nothing Then Return False Else If Visible = False Then window.TransparencyKey = Color.Fuchsia window.BackColor = Color.Fuchsia End If window.FormBorderStyle = FormBorderStyle.None window.MaximizeBox = False window.MinimizeBox = False window.Show() Resize_Window(Window, Position) Return True End If Catch NTSTATUS As Exception Return False End Try End Function ' '++++++++++++++++++++++++ RETORNAR RESOLUÇÃO DA TELA DO MONITOR +++++++++++++++++++++++++ ' Public Function Return_Resolution() As Point Try Return New Point(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height) Catch NTSTATUS As Exception Return Nothing End Try End Function ' '++++++++++++++++++++++++ RETORNAR PONTO DE ENTRADA NO MONITOR ++++++++++++++++++++++++++ ' Public Function Return_Left_Top(ByVal Window As Form) As Point Try Dim Current_Width As Integer = window.Width Dim Current_Height As Integer = window.Height Dim Current_Resolution As Point = Return_Resolution() Dim New_Position As Point New_Position.X = 0 New_Position.Y = 0 Return New_Position Catch NTSTATUS As Exception Return Nothing End Try End Function ' Public Function Return_Left_Down(ByVal Window As Form) As Point Try Dim Current_Width As Integer = window.Width Dim Current_Height As Integer = window.Height Dim Current_Resolution As Point = Return_Resolution() Dim New_Position As Point New_Position.X = 0 New_Position.Y = Current_Resolution.Y - Current_Height Return New_Position Catch NTSTATUS As Exception Return Nothing End Try End Function ' Public Function Return_Right_Top(ByVal Window As Form) As Point Try Dim Current_Width As Integer = window.Width Dim Current_Height As Integer = window.Height Dim Current_Resolution As Point = Return_Resolution() Dim New_Position As Point New_Position.X = Current_Resolution.X - Current_Width New_Position.Y = 0 Return New_Position Catch NTSTATUS As Exception Return Nothing End Try End Function ' Public Function Return_Right_Down(ByVal Window As Form) As Point Try Dim Current_Width As Integer = window.Width Dim Current_Height As Integer = window.Height Dim Current_Resolution As Point = Return_Resolution() Dim New_Position As Point New_Position.X = Current_Resolution.X - Current_Width New_Position.Y = Current_Resolution.Y - Current_Height Return New_Position Catch NTSTATUS As Exception Return Nothing End Try End Function ' '+++++++++++++++++++++++++++++++++ ALOCAR PICTUREBOX ++++++++++++++++++++++++++++++++++++ ' Public Function Alloc_PictureBox(ByVal Component As PictureBox, ByVal Window As Form, ByVal Location As Window_Location) As Boolean Try Select Case Location Case Window_Location.Left_Top Component.Location = New Point(0, 0) window.Controls.Add(Component) Return True Case Window_Location.Left_Down Component.Location = New Point(0, window.Height - Component.Height) window.Controls.Add(Component) Return True Case Window_Location.Right_Top Component.Location = New Point(window.Width - Component.Width, 0) window.Controls.Add(Component) Return True Case Window_Location.Right_Down Component.Location = New Point(window.Width - Component.Width, window.Height - Component.Height) window.Controls.Add(Component) Return True End Select Return False Catch NTSTATUS As Exception Return False End Try End Function ' '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ' ' 'Utilizando as funções ... (Muryllo Pimenta) ' Dim X As New Form Dim Y As New PictureBox ' Public Sub Main() MsgBox("Executando", MsgBoxStyle.Information, "Teste - Portugal a Programar") 'Alerta de inicialização Create_Window(X, Return_Right_Top(X), False) 'Criando janela na posição desejada de acordo com as quatro extremidades da tela Alloc_PictureBox(Y, X, Window_Location.Right_Top) 'Alocando componente (PICTUREBOX) na janela criada Y.BackColor = Color.Aqua 'Colocando imagem ou cor na PictureBox MsgBox("Sucesso!", MsgBoxStyle.Information, "Sucesso na Operação") 'Sucesso da operação, funções executadas End Sub ' End Module Acho que é isso que está procurando ... Tudo em RUN-TIME ! Demonstração Abraços. Edited November 29, 2015 at 03:24 AM by Muryllo Link to comment Share on other sites More sharing options...
a3deluxe Posted November 30, 2015 at 11:54 AM Author Report Share #590241 Posted November 30, 2015 at 11:54 AM Muryllo muito obrigado pela dica, mas ainda tenho algumas dúvidas, - Quando executo o programa ainda aparece o meu form cor de laranja e agora este novo azul, como coloco só um? - Onde coloco o código para este novo botão executar a acção que eu pretendo? por exemplo um (process.start.) Link to comment Share on other sites More sharing options...
Muryllo Posted November 30, 2015 at 04:27 PM Report Share #590246 Posted November 30, 2015 at 04:27 PM (edited) Boas a3deluxe, vamos por partes. Quanto a cor do form, você deve usar a função : Create_Window(Formulario, Return_Right_Top(Formulario), False) Esse parâmetro "False" faz com que o formulário seja criado mas fique invisível. Só irá aparecer algum elemento que esteja no Form mas que não use a cor Fuchsia. Depois usa-se a função Alloc_PictureBox(PictureBox, Formulario, Window_Location.Right_Top) essa serve para alocar a picturebox, mas tem um detalhe. Você precisa especificar o tamanho do formulário e ele deve ser maior em todos os lados que o do picturebox e também especificar o tamanho do picturebox. Para mostrar a picturebox basta fazer uma imagem de botão close e colocar na picturebox. Para usares instruções de click no componente picturebox é só aceder ao evento dele. Vou postar um exemplo. EDIT: Isto com certeza é oque você procura, o exemplo está perfeito para você adaptar. Analise bem o código. Public Class Exemplo ' '++++++++++++++++++++++++++++++++ ENUMERADOR DE POSIÇÕES ++++++++++++++++++++++++++++++++ ' Public Enum Window_Location As Integer Left_Top = 1 Left_Down = 2 Right_Top = 3 Right_Down = 4 End Enum ' '++++++++++++++++++++++++++++ CRIAR E REDIMENSIONAR JANELAS +++++++++++++++++++++++++++++ ' Public Function Resize_Window(ByVal Window As Form, ByVal Position As Point) As Boolean Try If Window Is Nothing Then Return False Else window.Location = Position Return True End If Catch NTSTATUS As Exception Return False End Try End Function ' Public Function Create_Window(ByVal Window As Form, ByVal Position As Point, ByVal Visible As Boolean) As Boolean Try If Window Is Nothing Then Return False Else If Visible = False Then window.TransparencyKey = Color.Fuchsia window.BackColor = Color.Fuchsia End If window.FormBorderStyle = FormBorderStyle.None window.MaximizeBox = False window.MinimizeBox = False window.ShowInTaskbar = False window.ShowIcon = False window.Show() Resize_Window(Window, Position) Return True End If Catch NTSTATUS As Exception Return False End Try End Function ' '++++++++++++++++++++++++ RETORNAR RESOLUÇÃO DA TELA DO MONITOR +++++++++++++++++++++++++ ' Public Function Return_Resolution() As Point Try Return New Point(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height) Catch NTSTATUS As Exception Return Nothing End Try End Function ' '++++++++++++++++++++++++ RETORNAR PONTO DE ENTRADA NO MONITOR ++++++++++++++++++++++++++ ' Public Function Return_Left_Top(ByVal Window As Form) As Point Try Dim Current_Width As Integer = window.Width Dim Current_Height As Integer = window.Height Dim Current_Resolution As Point = Return_Resolution() Dim New_Position As Point New_Position.X = 0 New_Position.Y = 0 Return New_Position Catch NTSTATUS As Exception Return Nothing End Try End Function ' Public Function Return_Left_Down(ByVal Window As Form) As Point Try Dim Current_Width As Integer = window.Width Dim Current_Height As Integer = window.Height Dim Current_Resolution As Point = Return_Resolution() Dim New_Position As Point New_Position.X = 0 New_Position.Y = Current_Resolution.Y - Current_Height Return New_Position Catch NTSTATUS As Exception Return Nothing End Try End Function ' Public Function Return_Right_Top(ByVal Window As Form) As Point Try Dim Current_Width As Integer = window.Width Dim Current_Height As Integer = window.Height Dim Current_Resolution As Point = Return_Resolution() Dim New_Position As Point New_Position.X = Current_Resolution.X - Current_Width New_Position.Y = 0 Return New_Position Catch NTSTATUS As Exception Return Nothing End Try End Function ' Public Function Return_Right_Down(ByVal Window As Form) As Point Try Dim Current_Width As Integer = window.Width Dim Current_Height As Integer = window.Height Dim Current_Resolution As Point = Return_Resolution() Dim New_Position As Point New_Position.X = Current_Resolution.X - Current_Width New_Position.Y = Current_Resolution.Y - Current_Height Return New_Position Catch NTSTATUS As Exception Return Nothing End Try End Function ' '+++++++++++++++++++++++++++++++++ ALOCAR PICTUREBOX ++++++++++++++++++++++++++++++++++++ ' Public Function Alloc_PictureBox(ByVal Component As PictureBox, ByVal Window As Form, ByVal Location As Window_Location) As Boolean Try Select Case Location Case Window_Location.Left_Top Component.Location = New Point(0, 0) window.Controls.Add(Component) Return True Case Window_Location.Left_Down Component.Location = New Point(0, window.Height - Component.Height) window.Controls.Add(Component) Return True Case Window_Location.Right_Top Component.Location = New Point(window.Width - Component.Width, 0) window.Controls.Add(Component) Return True Case Window_Location.Right_Down Component.Location = New Point(window.Width - Component.Width, window.Height - Component.Height) window.Controls.Add(Component) Return True End Select Return False Catch NTSTATUS As Exception Return False End Try End Function ' '++++++++++++++++++++++++++++ Utilizando as funções ... (Muryllo Pimenta) +++++++++++++++++++++++ ' Dim WithEvents Formulario As New Form 'CLASSE QUE SE REFERE AO FORMULÁRIO (JANELA) Dim WithEvents Picture_Box As New PictureBox 'CLASSE QUE SE REFERE A PICTUREBOX (COMPONENTE) ' Private Sub Exemplo_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' 'NÃO IMPORTA O TAMANHO DA PICTUREBOX, A MEDIDA DE CADA LADO DO FORMULÁRIO DEVE SER MAIOR 'QUE OS LADOS DO PICTUREBOX. ' With Formulario 'AJUSTA O FORMULÁRIO PARA TER UMA ÁREA QUADRADA PERFEITA. .Width = 100 .Height = 100 End With ' With Picture_Box 'AJUSTA A PICTUREBOX PARA TER UMA ÁREA QUADRADA PERFEITA. .Width = 30 .Height = 30 End With ' Create_Window(Formulario, Return_Right_Top(Formulario), False) 'CRIA FORMULARIO (JANELA) NA POSIÇÃO Right_Top (PONTA SUPERIOR DIREITA) Alloc_PictureBox(Picture_Box, Formulario, Window_Location.Right_Top) 'CRIA PICTUREBOX (COMPONENTE) NA POSIÇÃO Right_Top (PONTA SUPERIOR DIREITA) DO FORMULÁRIO ' 'OBSERVAÇÃO : SE A JANELA FOI CRIADA EM RIGHT_TOP O PICTUREBOX TAMBÉM DEVE SER CRIADO EM RIGHT_TOP 'SE FOR CRIADO EM RIGHT_DOWN O PICTUREBOX TEM QUE SER CRIADO EM RIGHT_DOWN E ASSIM SUCESSIVAMENTE ... ' 'APÓS TER CRIADO E CARREGADO OS DOIS COMPONENTES FORMULARIO E PICTUREBOX RESPECTIVAMENTE, A PICTUREBOX DEVE CONTER 'UMA IMAGEM, CASO CONTRÁRIO A PICTUREBOX E O FORMULÁRIO FICARÃO INVISÍVEIS. ' If System.IO.File.Exists("C:\USERS\Murilo\Desktop\Ajuda.png") = True Then Picture_Box.Image = Image.FromFile("C:\USERS\Murilo\Desktop\Ajuda.png") Else MsgBox("Não foi possível carregar o botão. FALTA AJUDA.PNG !", MsgBoxStyle.Critical, "Erro Interno") End If End Sub ' '+++++++++++++++++++++++++++++++ EVENTO CLICK DA PICTUREBOX +++++++++++++++++++++++++++++++++++++ ' Private Sub Picture_Box_Click(sender As Object, e As EventArgs) Handles Picture_Box.Click MsgBox("Instrução executada ao clicar no botão da lupa no canto direito superior da tela.", MsgBoxStyle.Information, "Portugal a Programar") 'SE QUISERES FINALIZAR PROCESSO, INICIALIZA PROCESSO OU OQUE FOR É SÓ ADICIONAR AS INSTRUÇÕES AQUI. 'EXEMPLO 'Process.Start("C:\WINDOWS\SYSTEM32\CMD.EXE") End Sub ' End Class O código está praticamente todo comentado, então não convém que eu explique por aqui. Deixo de seguida um print da minha tela mostrando o resultado que por sinal foi bem satisfatório. Podes ver claramente que funciona direitinho e bem alinhado com a extremidade da tela. Abraços. Edited November 30, 2015 at 05:48 PM by Muryllo Link to comment Share on other sites More sharing options...
a3deluxe Posted December 3, 2015 at 07:48 PM Author Report Share #590332 Posted December 3, 2015 at 07:48 PM Mais uma vez obrigado, Ainda não consegui, quando inicio o programa o meu Form cor de laranja, continua a aparecer juntamente com a nova Picturebox azul. Link to comment Share on other sites More sharing options...
Muryllo Posted December 3, 2015 at 10:24 PM Report Share #590343 Posted December 3, 2015 at 10:24 PM (edited) Boas a3deluxe, posta aqui o teu source para vermos. Ah, esqueci de lembrar. Teu form deve estar com a cor Fuchsia para ficar invisível, podes alterar isso em Create_window. Modifica lá para que ele deixe toda parte que tenha cor laranja invisível. Edited December 3, 2015 at 10:27 PM by Muryllo Link to comment Share on other sites More sharing options...
a3deluxe Posted December 5, 2015 at 05:28 PM Author Report Share #590404 Posted December 5, 2015 at 05:28 PM Quando coloquei o Meu Form da mesma cor, o novo Form ficou invisível. Não era isso que queria que acontece-se. queria que aparecesse só o novo form. O código que estou a usar e esse que postas-te para tentar colocar a funcionar como pertendo. Clicando a nova picturebox. também não funciona. Link to comment Share on other sites More sharing options...
Muryllo Posted December 6, 2015 at 10:40 PM Report Share #590432 Posted December 6, 2015 at 10:40 PM (edited) Boas, Agora já não entendo mais o teu problema, antes eu tinha entendido que precisavas criar um botão no topo direito da tela que por sinal a entrada é (RW - FW x 0). Isso é o ponto de entrada do topo direito da tela, beleza foi feito o form inicia lá, depois o trabalho foi iniciar o picturebox que por sinal é o BOTÃO no topo direito do form, foi feito também. E agora o que precisas ? Se o form precisa aparecer é só você marcar Create_Window(PARAM1, PARAM2, True) Isso deixará ele visível. Tens uma classe aí em cima onde é só fazer paste bin e modificar de acordo com as suas necessidades. Quanto a parte da picturebox, como não funciona ? Criaste o evento CLICK com a picturebox ? Tens certeza que adicionou o Nome correto ? A função falha ou retorna false ao Alocar a picturebox ? Declarou a Picturebox com WithEvents ? lembre-se que é assim : Dim WithEvents MEU_PICTUREBOX As New PictureBox Dá uma boa explicada aí no que pretendes realmente. Edited December 6, 2015 at 10:42 PM by Muryllo Link to comment Share on other sites More sharing options...
a3deluxe Posted December 7, 2015 at 10:03 PM Author Report Share #590458 Posted December 7, 2015 at 10:03 PM O que eu pretendia era a picturebox (funcionar como botão) no canto superior direito, não aparecendo o Form, só mesmo a picturebox. Link to comment Share on other sites More sharing options...
Muryllo Posted December 7, 2015 at 11:03 PM Report Share #590459 Posted December 7, 2015 at 11:03 PM (edited) E não é o que a classe faz ? Ok, esquece a classe. A fórmula para inicializar o formulário no canto superior direito é : LARGURA_DA_TELA - LARGURA_DA_JANELA x 0 Só inicializar o form nessa posição aí, depois basta alocar o Picturebox no canto superior direito do formulário, fórmula LARGURA_DO_FORM - LARGURA_DO_PICTUREBOX x 0 Só isso, não há mistério. Ainda criei uma classe que contem as 4 fórmulas para os 4 cantos da tela, mas tudo bem usa só essa. E para acederes ao evento click da picturebox, copia o evento substitui pelo nome do picturebox e pronto. O Form e o Picturebox são criados em run-time. OBS : Para esconder o form eu já expliquei como é ... Usa uma cor de fundo no formulário que não usas no form, depois iguala TransparencyKey com a cor que usaste em backgroundcolor. Olha bem pra imagem, vê o mouse clicando lá no canto superior direito e acionando o evento para surgir a mensagem na tela, funcionou perfeitamente. Olha também no desktop o arquivo Ajuda.png com os lados em Fuchsia (ROSA) fazendo com que fique somente o ícone do botão, o form nem aparece pois está em Fuchsia também então só ficou a picturebox. Edited December 7, 2015 at 11:11 PM by Muryllo Link to comment Share on other sites More sharing options...
a3deluxe Posted December 8, 2015 at 11:58 AM Author Report Share #590465 Posted December 8, 2015 at 11:58 AM Eu queria a picturebox visivel e o form oculto. Link to comment Share on other sites More sharing options...
Muryllo Posted December 8, 2015 at 01:50 PM Report Share #590472 Posted December 8, 2015 at 01:50 PM (edited) Public Function Ocultar_Form(ByVal mForm As Form) As Boolean Try If mForm Is Nothing Then Return False Else With mForm .FormBorderStyle = Windows.Forms.FormBorderStyle.None .MaximizeBox = False .MinimizeBox = False .ShowIcon = False .ShowInTaskbar = False .BackColor = Color.Fuchsia .TransparencyKey = Color.Fuchsia End With Return True End If Catch __ERR As Exception Return False End Try End Function Edited December 8, 2015 at 02:00 PM by Muryllo Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now