Formularios de Windows: ¿Cómo ocultar el botón Cerrar (x)?
Tengo un diálogo modal, y necesito ocultar el botón Cerrar (X), pero no puedo usar
ControlBox = false
, porque necesito mantener los botones Minimizar y Maximizar.
Necesito ocultar solo Cerrar botón, ¿hay alguna manera de hacer eso?
Muchas Gracias!
Actualización: Tenía permiso para desactivarlo, que es más simple:) Gracias a todos!
8 answers
No puede ocultarlo, pero puede deshabilitarlo anulando la propiedad CreateParams del formulario.
private const int CP_NOCLOSE_BUTTON = 0x200;
protected override CreateParams CreateParams
{
get
{
CreateParams myCp = base.CreateParams;
myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON ;
return myCp;
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-04-27 06:45:19
Podemos ocultar el botón cerrar en el formulario configurando this.ControlBox=false;
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-11-09 20:42:38
Bueno, puede ocultarlo, eliminando todo el menú del sistema:
private const int WS_SYSMENU = 0x80000;
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Style &= ~WS_SYSMENU;
return cp;
}
}
Por supuesto, al hacerlo se eliminan los botones minimizar y maximizar.
Si mantiene el menú del sistema pero elimina el elemento cerrar, el botón cerrar permanece pero está desactivado.
La alternativa final es pintar el área que no es cliente usted mismo. Eso es bastante difícil de hacer bien.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-09-04 20:36:11
Si realmente desea ocultarlo, como en "no visible", entonces probablemente tendrá que crear un formulario sin bordes y dibujar los componentes de subtítulos usted mismo. La biblioteca de VisualStyles tiene los elementos de Windows disponibles. También tendría que volver a agregar la funcionalidad de volver a dimensionar el formulario o mover el formulario agarrando la barra de subtítulos. Sin mencionar el menú del sistema en la esquina.
En la mayoría de los casos, es difícil justificar que el botón "cerrar" no esté disponible, especialmente cuando se desea una forma modal con capacidades de minimización. Minimizar una forma modal realmente no tiene sentido.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-09-04 20:34:09
Puede ocultar cerrar la caja usando
this.ControlBox = false;
Y no olvides agregar espacio en blanco a this.Text = " "
para hacerlo así
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-05-31 07:31:10
En las propiedades de su formulario establezca 'Control Box' = False pero también se ocultará Minimizado y Maximizado.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-27 01:23:45
Bueno, puede ocultar el botón cerrar cambiando el FormBorderStyle de la sección de propiedades o programáticamente en el constructor usando:
public Form1()
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None;
}
Luego se crea un elemento de menú para salir de la aplicación.
Salud
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-27 12:49:29
Si esta es una opción puede configurar
this.FormBorderStyle = FormBorderStyle.None;
Luego vuelva a crear los botones minimizar y maximizar
private void button1_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
}
private void button2_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-22 01:15:57