Visual Basic.NET - Mostrar un formulario estático en una aplicación vacía.

 
Vista:
sin imagen de perfil

Mostrar un formulario estático en una aplicación vacía.

Publicado por Rodrigo (13 intervenciones) el 25/12/2021 22:25:24
Estoy haciendo pruebas para hacer una aplicación basic y creo el formulario pero inmediatamente desaparece. ¿C ¿cómo puedo hacer para que se quede estático? gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Mostrar un formulario estático en una aplicación vacía.

Publicado por Lizy (18 intervenciones) el 26/12/2021 03:09:57
' A ver si te sirve esto:

' Solo hay que copiar este código y tendrás un bonito formulario de lujo

Option Strict On

Public Class Form1

WithEvents TMR_CLOSE As New Timer
WithEvents PIC1 As New PictureBox, ROJ As New Label, BCO As New Label

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = ""
Me.ControlBox = False
Me.FormBorderStyle = FormBorderStyle.FixedToolWindow
Me.BackColor = Color.Black

ROJ.Text = "X"
ROJ.Font = New Font("Arial", 10, FontStyle.Bold)
ROJ.TextAlign = ContentAlignment.MiddleCenter
ROJ.BackColor = Color.Red
ROJ.ForeColor = Color.White
ROJ.Size = New Size(25, 23)
ROJ.Location = New Point(Me.Width - ROJ.Width, 0)
ROJ.Anchor = CType(AnchorStyles.Top + AnchorStyles.Right, AnchorStyles)
ROJ.Visible = True
Me.Controls.Add(ROJ)

BCO.Text = "X"
BCO.Font = New Font("Arial", 10, FontStyle.Bold)
BCO.TextAlign = ContentAlignment.MiddleCenter
BCO.BackColor = Color.Snow
BCO.ForeColor = Color.Gray
BCO.Size = New Size(25, 23)
BCO.Location = New Point(Me.Width - BCO.Width, 0)
BCO.Anchor = CType(AnchorStyles.Top + AnchorStyles.Right, AnchorStyles)
BCO.Visible = True
Me.Controls.Add(BCO)
BCO.BringToFront()

TMR_CLOSE.Interval = 100 : TMR_CLOSE.Enabled = False

PIC1.BorderStyle = BorderStyle.FixedSingle
PIC1.Size = New Size(25, 25)
PIC1.Location = New Point(Me.Width - PIC1.Width, Me.Height - PIC1.Height)
PIC1.Cursor = Cursors.SizeNWSE
Me.Controls.Add(PIC1) ' Opcionalmente puedes ponerle imagen adecuada a tu PictureBox

' Nota: Si quieres que un objeto se mueva en el Form a modo de drag drop, por ejemlo un Panel1
' Solo agregalo al form y quita el comentario que puse en los Handles de Movimiento del Form

End Sub

' Movimiento del Form

Dim MVE As Boolean = False
Dim Xobj As Single, Yobj As Single
Dim Xfrm As Single, Yfrm As Single
Dim MIN_W As Integer = 100, MIN_H As Integer = 50
Dim CTRL As Control

Private Sub Mueve_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown, PIC1.MouseDown ', Panel1.MouseDown
CTRL = CType(sender, Control)

If e.Button = MouseButtons.Left Then
CTRL.BringToFront()

Xobj = e.X
Yobj = e.Y

Form_Min_Sze() ' Cuando MVE = False

MVE = True

Application.DoEvents()
End If

End Sub

Private Sub Mueve_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove, PIC1.MouseMove ', Panel1.MouseMove
CTRL = CType(sender, Control)

If e.Button = MouseButtons.Left Then
If MVE = True Then

Xfrm = e.X + CTRL.Left
Yfrm = e.Y + CTRL.Top

CTRL.Left = CInt(Xfrm - Xobj)
CTRL.Top = CInt(Yfrm - Yobj)

Form_Min_Sze() ' Cuando MVE = True

CTRL.Refresh()
Application.DoEvents()
End If
End If
End Sub

Private Sub Mueve_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp, PIC1.MouseUp ', Panel1.MouseUp
CTRL = CType(sender, Control)

If e.Button = MouseButtons.Left Then
If MVE = True Then
MVE = False

Form_Min_Sze() ' Cuando MVE = False

Application.DoEvents()
End If
End If
End Sub

Private Sub Form_Min_Sze()
If CTRL.Name = PIC1.Name Then
If MVE = True Then

If Me.Width > MIN_W And Me.Height > MIN_H Then
Me.Width = PIC1.Left + PIC1.Width
Me.Height = PIC1.Top + PIC1.Height
Else
PIC1.Visible = False
Exit Sub
End If

Else

If Me.Width <= MIN_W Then
Me.Width = MIN_W + 1
End If

If Me.Height <= MIN_H Then
Me.Height = MIN_H + 1
End If

If PIC1.Left = Me.Width - PIC1.Width Then

Else
PIC1.Left = Me.Width - PIC1.Width
End If

If PIC1.Top = Me.Height - PIC1.Height Then

Else
PIC1.Top = Me.Height - PIC1.Height
End If

End If

PIC1.Visible = True

End If
End Sub

' Closing

Private Sub Blanco_MouseMove(sender As Object, e As MouseEventArgs) Handles BCO.MouseMove
BCO.Visible = False
ROJ.Visible = True

TMR_CLOSE.Start()
End Sub

Private Sub TMR_CLOSE_Tick(sender As Object, e As EventArgs) Handles TMR_CLOSE.Tick
ROJ.Visible = False
BCO.Visible = True

TMR_CLOSE.Stop()
End Sub

Private Sub Rojo_MouseClick(sender As Object, e As MouseEventArgs) Handles ROJ.MouseClick
If e.Button = MouseButtons.Left Then
End ' Me.Close() ' según convenga
End If
End Sub

Private Sub Rojo_MouseDown(sender As Object, e As MouseEventArgs) Handles ROJ.MouseDown
If e.Button = MouseButtons.Left Then
End ' Me.Close() ' según convenga
End If
End Sub

End Class
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
-1
Comentar
Imágen de perfil de Phil Rob
Val: 3.353
Oro
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

Mostrar un formulario estático en una aplicación vacía.

Publicado por Phil Rob (1554 intervenciones) el 26/12/2021 08:52:12
Hola,

Normalmente, cuando un Form es sobre la pantalla, no desaparece todo solo.

Envía el foto del explorador de solución de tu proyecto durante el desarrollo y el código del procedimiento Form_load. Intentaré de comprender el problema.

Buen domingo... :D)))
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar