Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

972
Views
Formulario sin bordes y redimensionable (C#)

Encontré un código en línea y lo copié, hasta ahora he podido hacerlo todo bien, excepto por una cosa: quiero que el formulario (ventana) no tenga ningún borde.

Estoy usando Visual Studio 2013 y esta pregunta es simplemente sobre el código que se necesita para hacer que el formulario (ventana) no tenga bordes. El problema es que cuando lo haces sin bordes, ya no se puede cambiar el tamaño, pero cuando tiene un borde, se puede cambiar el tamaño.

Sé que usando algún código es posible anular y lograr ambos. Esto es lo que tengo hasta ahora (copiado de otro sitio web). Esto elimina la barra superior que tiene el nombre del programa, hace que el formulario se pueda mover haciendo clic y arrastrando el formulario, y se puede cambiar de tamaño.

El único problema es que la frontera sigue ahí. ¿Qué código puedo agregar a esto para que el borde desaparezca? Quiero mantener este código actual porque ya ofrece un par de funciones que necesito.

Por cierto, miré algunas preguntas anteriores con temas similares pero no encontré el código correcto que necesito.

Para el mod que me dirigió a otro hilo: probé el código allí y no es exactamente lo que estoy tratando de lograr, aunque es un problema similar. Cuando probé ese código, no pude hacer clic en ninguna parte del formulario (ventana) para moverlo. Además, tenía una esquina redimensionable en la parte inferior derecha que no es lo que estoy buscando. Necesito la función de cambio de tamaño en todas las esquinas y lados como una ventana normal.

 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 BoxHider { public partial class Form1 : Form { public Form1() { InitializeComponent(); //Next line doesn't seem to be working this.FormBorderStyle = FormBorderStyle.None; } const int WM_NCHITTEST = 0x0084; const int HTCLIENT = 1; const int HTCAPTION = 2; protected override void WndProc(ref Message m) { base.WndProc(ref m); switch (m.Msg) { case WM_NCHITTEST: if (m.Result == (IntPtr)HTCLIENT) { m.Result = (IntPtr)HTCAPTION; } break; } } protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.Style |= 0x40000; return cp; } } } }

Lo que necesito

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Prueba esto:

 public Form1() { InitializeComponent(); this.FormBorderStyle = FormBorderStyle.None; } protected override void WndProc(ref Message m) { const int RESIZE_HANDLE_SIZE = 10; switch (m.Msg) { case 0x0084/*NCHITTEST*/ : base.WndProc(ref m); if ((int)m.Result == 0x01/*HTCLIENT*/) { Point screenPoint = new Point(m.LParam.ToInt32()); Point clientPoint = this.PointToClient(screenPoint); if (clientPoint.Y <= RESIZE_HANDLE_SIZE) { if (clientPoint.X <= RESIZE_HANDLE_SIZE) m.Result = (IntPtr) 13/*HTTOPLEFT*/ ; else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE)) m.Result = (IntPtr) 12/*HTTOP*/ ; else m.Result = (IntPtr) 14/*HTTOPRIGHT*/ ; } else if (clientPoint.Y <= (Size.Height - RESIZE_HANDLE_SIZE)) { if (clientPoint.X <= RESIZE_HANDLE_SIZE) m.Result = (IntPtr) 10/*HTLEFT*/ ; else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE)) m.Result = (IntPtr) 2/*HTCAPTION*/ ; else m.Result = (IntPtr) 11/*HTRIGHT*/ ; } else { if (clientPoint.X <= RESIZE_HANDLE_SIZE) m.Result = (IntPtr) 16/*HTBOTTOMLEFT*/ ; else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE)) m.Result = (IntPtr) 15/*HTBOTTOM*/ ; else m.Result = (IntPtr)17/*HTBOTTOMRIGHT*/ ; } } return; } base.WndProc(ref m); } protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.Style |= 0x20000; // <--- use 0x20000 return cp; } }

fuentes de información:

  • https://stackoverflow.com/a/19670447/2352507
  • Controlador de cambio de tamaño personalizado en forma sin bordes C#
  • http://www.csharp411.com/add-drop-shadow-to-borderless-form/
over 4 years ago · Santiago Trujillo Report

0

Debe establecer el estilo del borde después de cargar el formulario:

 protected override void OnLoad(EventArgs e) { base.OnLoad(e); this.FormBorderStyle = FormBorderStyle.None; }
over 4 years ago · Santiago Trujillo Report

0

Recientemente necesitaba una respuesta similar a la misma pregunta que tenía. Anulé la función WndProc y el código funciona. Nota: en la parte superior de la barra de título no debería haber ningún control; de lo contrario, ¡no funcionará!

 protected override void WndProc(ref Message m) { switch (m.Msg) { case 0x84: base.WndProc(ref m); if ((int)m.Result == 0x1) { if (Cursor.Position.Y <= (this.Location.Y + HeightOfTitleBar) && Cursor.Position.Y >= this.Location.Y + 4) m.Result = (IntPtr)0x2; if (Cursor.Position.Y <= this.Location.Y + this.Height && Cursor.Position.Y >= this.Location.Y + this.Height - 4) m.Result = (IntPtr)15; if (Cursor.Position.Y <= this.Location.Y + 4 && Cursor.Position.Y >= this.Location.Y) m.Result = (IntPtr)12; if (Cursor.Position.X <= this.Location.X + this.Width && Cursor.Position.X >= this.Location.X + this.Width - 4) m.Result = (IntPtr)11; if (Cursor.Position.X <= this.Location.X + 4 && Cursor.Position.X >= this.Location.X) m.Result = (IntPtr)10; if (Cursor.Position.Y <= this.Location.Y + 8 && Cursor.Position.Y >= this.Location.Y && Cursor.Position.X <= this.Location.X + 8 && Cursor.Position.X >= this.Location.X) m.Result = (IntPtr)13; if (Cursor.Position.Y <= this.Location.Y + this.Height && Cursor.Position.Y >= this.Location.Y + this.Height - 8 && Cursor.Position.X <= this.Location.X + this.Width && Cursor.Position.X >= this.Location.X + this.Width - 8) m.Result = (IntPtr)17; if (Cursor.Position.Y <= this.Location.Y + this.Height && Cursor.Position.Y >= this.Location.Y + this.Height - 8 && Cursor.Position.X <= this.Location.X + 8 && Cursor.Position.X >= this.Location.X) m.Result = (IntPtr)16; if (Cursor.Position.Y <= this.Location.Y + 8 && Cursor.Position.Y >= this.Location.Y && Cursor.Position.X <= this.Location.X + this.Width && Cursor.Position.X >= this.Location.X + this.Width - 8) m.Result = (IntPtr)14; } return; } base.WndProc(ref m); }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!