none
quiero desactivar la opción tamaño de esta ventana. ¿saben como? RRS feed

Respuestas

  • Sí.

    Obtienes el handle del menú con GetSystemMenu().
    Inhabilitas el item, llamando a ModifyMenu() MF_BYCOMMAND/SC_SIZE/MF_GRAYED


    using System;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            private UInt32 MF_BYCOMMAND = 0;
            private UInt32 MF_GRAYED = 1;
            private UInt32 SC_SIZE = 0xF000;
    
            [DllImport("user32.dll")]
            private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
    
            [DllImport("user32.dll")]
            private static extern bool ModifyMenu(IntPtr hMnu, UInt32 uPosition, UInt32 uFlags, IntPtr uIDNewItem, string lpNewItem);
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                IntPtr sysMenu = GetSystemMenu(this.Handle, false);
    
                ModifyMenu(sysMenu, SC_SIZE, MF_BYCOMMAND | MF_GRAYED, IntPtr.Zero, "Tamaño");
            }
        }
    }
    

    Imports System.Runtime.InteropServices
    
    Partial Public Class Form1
        Inherits Form
        Private MF_BYCOMMAND As UInt32 = 0
        Private MF_GRAYED As UInt32 = 1
        Private SC_SIZE As UInt32 = &HF000
    
        <DllImport("user32.dll")> _
        Private Shared Function GetSystemMenu(hWnd As IntPtr, bRevert As Boolean) As IntPtr
        End Function
    
        <DllImport("user32.dll")> _
        Private Shared Function ModifyMenu(hMnu As IntPtr, uPosition As UInt32, uFlags As UInt32, uIDNewItem As IntPtr, lpNewItem As String) As Boolean
        End Function
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim sysMenu As IntPtr = GetSystemMenu(Me.Handle, False)
    
            ModifyMenu(sysMenu, SC_SIZE, MF_BYCOMMAND Or MF_GRAYED, IntPtr.Zero, "Tamaño")
        End Sub
    End Class
    

    • Editado Pizpireta lunes, 9 de septiembre de 2013 22:07
    • Marcado como respuesta mojicahaner lunes, 9 de septiembre de 2013 23:14
    lunes, 9 de septiembre de 2013 21:29

Todas las respuestas

  • aldar click en la barra de titulo aparece la opción "tamaño" y la quiero deshabilitar, ¿saben como?



    lunes, 9 de septiembre de 2013 21:16
  • Sí.

    Obtienes el handle del menú con GetSystemMenu().
    Inhabilitas el item, llamando a ModifyMenu() MF_BYCOMMAND/SC_SIZE/MF_GRAYED


    using System;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            private UInt32 MF_BYCOMMAND = 0;
            private UInt32 MF_GRAYED = 1;
            private UInt32 SC_SIZE = 0xF000;
    
            [DllImport("user32.dll")]
            private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
    
            [DllImport("user32.dll")]
            private static extern bool ModifyMenu(IntPtr hMnu, UInt32 uPosition, UInt32 uFlags, IntPtr uIDNewItem, string lpNewItem);
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                IntPtr sysMenu = GetSystemMenu(this.Handle, false);
    
                ModifyMenu(sysMenu, SC_SIZE, MF_BYCOMMAND | MF_GRAYED, IntPtr.Zero, "Tamaño");
            }
        }
    }
    

    Imports System.Runtime.InteropServices
    
    Partial Public Class Form1
        Inherits Form
        Private MF_BYCOMMAND As UInt32 = 0
        Private MF_GRAYED As UInt32 = 1
        Private SC_SIZE As UInt32 = &HF000
    
        <DllImport("user32.dll")> _
        Private Shared Function GetSystemMenu(hWnd As IntPtr, bRevert As Boolean) As IntPtr
        End Function
    
        <DllImport("user32.dll")> _
        Private Shared Function ModifyMenu(hMnu As IntPtr, uPosition As UInt32, uFlags As UInt32, uIDNewItem As IntPtr, lpNewItem As String) As Boolean
        End Function
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim sysMenu As IntPtr = GetSystemMenu(Me.Handle, False)
    
            ModifyMenu(sysMenu, SC_SIZE, MF_BYCOMMAND Or MF_GRAYED, IntPtr.Zero, "Tamaño")
        End Sub
    End Class
    

    • Editado Pizpireta lunes, 9 de septiembre de 2013 22:07
    • Marcado como respuesta mojicahaner lunes, 9 de septiembre de 2013 23:14
    lunes, 9 de septiembre de 2013 21:29
  • no funciona, dehecho no se si es lo que quiero.

    al darle click a la barra de titulo. ella muestra las opciones.

    maximizar, minimizar, mover, tamaño y cerrar.

    quiero deshabilitar la de "tamaño"

    lunes, 9 de septiembre de 2013 23:03
  • listo amigo muchs gracias! ya funciono

    lunes, 9 de septiembre de 2013 23:14
  • Funcionan perfectamente. Ambos dos: vb y c#.

    Es posible, si copiaste y pegaste el ejemplo en c#, que no hayas asignado el evento Load del formulario. 

    lunes, 9 de septiembre de 2013 23:16