This question has already been answered:

Good day.

I had a problem, I want to drag a form not for a border or as I have done - a black strip on top, but just a gray block on the page.

But as I did not try to implement it, I did not succeed.

Please tell me - how can this be implemented? enter image description here

Reported as a duplicate by PashaPash member c # 28 Dec '16 at 21:53 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • WinForms or WPF? - VladD
  • WinForms at the moment, I can and WPF me personally without a difference. :) - user199587

1 answer 1

The easiest way to do this without using WinApi is something like this (drag over Label):

int? x, y; private void label1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (x == null || y == null) { x = eX; y = eY; } else { Left += eX - (int)x; Top += eY - (int)y; } } else { x = null; y = null; } } 
  • 2
    The label can be made much easier, but I don’t need a label, but a gray block per page (And the page is in HTML) - This is CefSharp - You probably didn’t understand the question. ) - user199587
  • Did not work with this framework, therefore did not recognize, events of the form are caught there? - Andrey NOP
  • No, there is some kind of IDragHandler - But it works through the ass, or rather it does not work at all. PS There the panel and on this panel there is a render page. - user199587
  • @ user199587 put a transparent element on top of the panel and process click on it - PashaPash