Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.Windows.Forms;
- namespace FirePlay.UI
- {
- /// <summary>
- /// Summary description for cInsideMover.
- /// </summary>
- public class InsideMover : Component
- {
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private Container components = null;
- public InsideMover(IContainer container)
- {
- ///
- /// Required for Windows.Forms Class Composition Designer support
- ///
- container.Add(this);
- InitializeComponent();
- //
- // TODO: Add any constructor code after InitializeComponent call
- //
- }
- public InsideMover()
- {
- ///
- /// Required for Windows.Forms Class Composition Designer support
- ///
- InitializeComponent();
- //
- // TODO: Add any constructor code after InitializeComponent call
- //
- }
- public Control ControlToMove
- {
- set
- {
- if (_parent != null)
- {
- // odkvaci prijasnje evente
- _parent.MouseDown -= new MouseEventHandler(_parent_MouseDown);
- _parent.MouseMove -= new MouseEventHandler(_parent_MouseMove);
- _parent.MouseUp -= new MouseEventHandler(_parent_MouseUp);
- _parent.DoubleClick -= new EventHandler(_parent_DoubleClick);
- }
- _parent=value;
- if (value!=null)
- {
- // zakači se na evente od containera koji ti trebaju
- _parent.MouseDown+=new MouseEventHandler(_parent_MouseDown);
- _parent.MouseMove+=new MouseEventHandler(_parent_MouseMove);
- _parent.MouseUp+=new MouseEventHandler(_parent_MouseUp);
- _parent.DoubleClick+=new EventHandler(_parent_DoubleClick);
- }
- }
- get
- {
- return _parent;
- }
- }
- Control _parent;
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Component Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- components = new System.ComponentModel.Container();
- }
- #endregion
- int _lastMouseX;
- int _lastMouseY;
- bool _moving;
- public void StartMouseDown(MouseEventArgs e)
- {
- _parent_MouseDown(null, e);
- }
- private void _parent_MouseDown(object sender, MouseEventArgs e)
- {
- _lastMouseX=e.X;
- _lastMouseY=e.Y;
- _moving=true;
- }
- private void _parent_MouseMove(object sender, MouseEventArgs e)
- {
- if (_moving)
- {
- Point newLocation=_parent.Location;
- newLocation.X+=e.X-_lastMouseX;
- newLocation.Y+=e.Y-_lastMouseY;
- _parent.Location=newLocation;
- }
- }
- private void _parent_MouseUp(object sender, MouseEventArgs e)
- {
- _moving=false;
- }
- private void _parent_DoubleClick(object sender, EventArgs e)
- {
- if (_parent is Form)
- {
- Form f=(Form)_parent;
- if (f.WindowState==FormWindowState.Normal)
- {
- f.WindowState=FormWindowState.Maximized;
- }
- else
- {
- f.WindowState=FormWindowState.Normal;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement