Why do child forms show the maximize and minimize buttons despite the fact that the FormBorderStyle property is equal to none?

689 views Asked by At

I'm working with visual C# and Windows Forms.

I have a parent form that calls its form children, the form children have the FormBorderStyle property in none, minimize box and maximizeBox in false and WindowsState in Maximized but when the program is run, the buttons maximize and minimize appear and they work despite being disabled.

Look at the attached image.

enter image description here

Code:

  this.WindowState = FormWindowState.Maximized;
  this.Dock = DockStyle.Fill;
  InicioSesion inicioSesionForm = new InicioSesion();
  inicioSesionForm.MdiParent = this;
  inicioSesionForm.Dock = DockStyle.Fill;
  inicioSesionForm.ShowInTaskbar = false;
  inicioSesionForm.MaximizeBox = false;
  inicioSesionForm.MinimizeBox = false;
  inicioSesionForm.Show();

Is there a way to solve that?

Any comments or suggestions are welcome.

UPDATE:

code from the IncioSesion form:

using allSale.Clases;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace allSale
{
    public partial class InicioSesion : Form
    {
        public InicioSesion()
        {
            InitializeComponent();
        }

        private void linkLabelRegistrarteLogin_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Registrarse registrarse = new Registrarse();
            registrarse.MdiParent = (FormularioPrincipal) this.ParentForm;
            registrarse.Dock = DockStyle.Fill;
            registrarse.WindowState = FormWindowState.Maximized;
            registrarse.Show();
            this.Close();
        }

        private void btnEntrarLogin_Click(object sender, EventArgs e)
        {
            if (textCorreoLogin.Text.Length == 0)
            {
                MessageBox.Show("¡Debe ingresar un correo electrónico!", "allSale", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            else if (textClaveLogin.Text.Length == 0)
            {
                MessageBox.Show("¡Debe ingresar su contraseña de usuario!", "allSale", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            else
            {
                Validador validador = new Validador();
                if (validador.correoElectronicoValido(textCorreoLogin.Text))
                {
                    BaseDeDatos baseDeDatos = new BaseDeDatos();
                    String correoUsuario = baseDeDatos.obtenerCorreoUsuario();
                    if (!String.IsNullOrEmpty(correoUsuario))
                    {
                        String claveUsuario = baseDeDatos.obtenerClaveUsuario();

                        if (correoUsuario.Equals(textCorreoLogin.Text) && claveUsuario.Equals(textClaveLogin.Text))
                        {

                            Globals.idEmpresa = baseDeDatos.obtenerIDEmpresaPorRUC(baseDeDatos.obtenerRUCUsuarioPorCorreo(correoUsuario));
                            Globals.idUsuario = baseDeDatos.obtenerIDUsuarioPorCorreo(correoUsuario);

                            Vender formularioVender = new Vender();
                            formularioVender.MdiParent = (FormularioPrincipal)this.ParentForm;
                            formularioVender.Dock = DockStyle.Fill;
                            formularioVender.WindowState = FormWindowState.Maximized;
                            formularioVender.Show();

                            FormularioPrincipal parent = (FormularioPrincipal)this.ParentForm;
                            parent.visibleMenuGeneral(true);

                            //FormularioPrincipal formularioPrincipal = new FormularioPrincipal();
                            //formularioPrincipal.visibleMenuGeneral(true);
                            this.Close();
                        }
                        else
                        {
                            if (correoUsuario.Equals(textCorreoLogin.Text))
                            {
                                MessageBox.Show("¡La clave ingresada es incorrecta!", "allSale", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                            }
                            else
                            {
                                MessageBox.Show("¡No existe un usuario con el correo ingresado!", "allSale", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                            }
                        }

                    }
                    else
                    {
                        MessageBox.Show("¡No existe aún usuarios almacenados!", "allSale", MessageBoxButtons.OK, MessageBoxIcon.Stop); 
                    }
                }
                else {MessageBox.Show("¡Debe ingresar un correo electrónio válido!", "allSale", MessageBoxButtons.OK, MessageBoxIcon.Stop);}


            }
        }
        public static class Globals
        {
            public static int idEmpresa = 0;
            public static int idUsuario = 0;
            public static List<ProductosVender> listaProductosParaVenderX = new List<ProductosVender>();
           
        }

        private void InicioSesion_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
        }
    }
}

And a video of what happens

Update 2 of the question: removing DockStyle.Fill;

enter image description here

Solution:

How can i Remove Maximize,Minimize and Close icon in MDI Menustrip

1

There are 1 answers

0
SlobodanT On

I think if you set child form's window state to maximize it will show those buttons regardless of window style.Its like some MDI parent-child behavior.

You can try setting child form window location and size manually.I assume you won't move child form since you set form border style to none.

Other thing you could try is add a Panel and fill the parent form with it.And then add your maximized child form inside that panel.