Advertisement
Fhernd

Principal.cs

Mar 4th, 2018
1,278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4.  
  5. namespace R715MoverFormularioSinBordes
  6. {
  7.     public partial class Principal : Form
  8.     {
  9.         private bool moviendoFormulario;
  10.         private Point posicionActualPuntero;
  11.  
  12.         public Principal()
  13.         {
  14.             InitializeComponent();
  15.         }
  16.  
  17.         private void btnMoverFormulario_Click(object sender, EventArgs e)
  18.         {
  19.             Close();
  20.         }
  21.  
  22.         private void lblMoverFormulario_MouseDown(object sender, MouseEventArgs e)
  23.         {
  24.             if (e.Button == MouseButtons.Left)
  25.             {
  26.                 moviendoFormulario = true;
  27.                 posicionActualPuntero = new Point(e.X, e.Y);
  28.             }
  29.             else
  30.             {
  31.                 moviendoFormulario = false;
  32.             }
  33.         }
  34.  
  35.         private void lblMoverFormulario_MouseMove(object sender, MouseEventArgs e)
  36.         {
  37.             if (moviendoFormulario)
  38.             {
  39.                 Point nuevoPunto;
  40.  
  41.                 nuevoPunto = PointToScreen(new Point(e.X, e.Y));
  42.                 nuevoPunto.Offset(-posicionActualPuntero.X, -posicionActualPuntero.Y);
  43.  
  44.                 Location = nuevoPunto;
  45.             }
  46.         }
  47.  
  48.         private void lblMoverFormulario_MouseUp(object sender, MouseEventArgs e)
  49.         {
  50.             moviendoFormulario = false;
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement