forms - Best way to create a floating object in c# -


i want make system tray app used "mask off" areas of screen (this use hide portions of dj software such bpm counters, user can hide bpm when practising, press key reveal.) it's equivalent of sticking piece of gaffer tape monitor, without nasty residue!

the requirements are:

  1. the user should able draw number of rectangles on screen want mask off. (maybe using setup / edit mode)
  2. the rectangles need on top (kind of modal, but...)
  3. the user must able interact application below - i.e. mouse clicks , key presses should work on dj software
  4. the user should able toggle between displaying , hiding rectangles (without having redraw each time

not sure of best way approach - thought making rectangles number of forms no content or controls on. there better (graphical way) acheive this? panels or rectangles or something?

ideally have liked use layered form using standard form easier write , present here @ stackoverflow.

the ux far great doesn't matter, it's give general idea. should feel free adopt own interface.

enter image description here

public sealed partial class gaffertape : form {     private point _startlocation = point.empty;     private point _cursorlocation = point.empty;     private bool _drawing;     private rectangle _regionrectangle;     private readonly list<rectangle> _rectangles = new list<rectangle>();      public bool allowdrawing { get; set; }      public gaffertape()     {         initializecomponent();          //todo: consider letting designer handle this.         formborderstyle = formborderstyle.none;         windowstate = formwindowstate.maximized;         topmost = true;         doublebuffered = true;         showintaskbar = false;         cursor = cursors.cross;         backcolor = color.white;         opacity = 0.4;         transparencykey = color.black;          //todo: consider letting designer handle this.         mousedown += onmousedown;         mouseup += onmouseup;         mousemove += onmousemove;         paint += onpaint;          allowdrawing = true;      }      private void onmousedown(object sender, mouseeventargs mouseeventargs)     {         //i don't allow user draw after rectangles have been drawn. see: buttoninvert_clic         if (allowdrawing)         {             _startlocation = mouseeventargs.location;             _drawing = true;         }     }      private void onmouseup(object sender, mouseeventargs mouseeventargs)     {         _drawing = false;         dialogresult = dialogresult.ok;         _rectangles.add(_regionrectangle);     }      private void onmousemove(object sender, mouseeventargs mouseeventargs)     {         if (_drawing == false)             return;          _cursorlocation = mouseeventargs.location;          _regionrectangle = new rectangle(math.min(_startlocation.x, _cursorlocation.x),                                          math.min(_startlocation.y, _cursorlocation.y),                                          math.abs(_startlocation.x - _cursorlocation.x),                                          math.abs(_startlocation.y - _cursorlocation.y));          invalidate();     }      private void onpaint(object sender, painteventargs painteventargs)     {         foreach (rectangle rectangle in _rectangles)             painteventargs.graphics.fillrectangle(brushes.black, rectangle);          painteventargs.graphics.fillrectangle(brushes.black, _regionrectangle);     }      private void buttoninvert_click(object sender, eventargs e)     {         opacity = 100;         transparencykey = color.white;         allowdrawing = false;         cursor = cursors.default;     } } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -