//private void TimerTick(object sender, System.EventArgs e) //{ // Point pt = this.PointToClient(MousePosition); // Rectangle rect = new Rectangle(pt,new Size(1,1)); // bool MouseOver = (ClientRectangle.IntersectsWith(rect)&& !panel.ClientRectangle.IntersectsWith(rect)); // if (MouseOver) ExpandCommand = true; //if(arrMoveList.Count>0) // { // DoneMove = false; // } // else // { // DoneMove = true; // } // for (int i=0;i<arrMoveList.Count;i++) // { // MoveObject mo =((MoveObject)arrMoveList[i]); // mo.Increment_State(); // if(mo.faze==mo.endfaze) // { // arrMoveList.RemoveAt(i); // i--; // } // } // for (int i=0;i<arrSizeList.Count;i++) // { // SizeObject so =((SizeObject)arrSizeList[i]); // so.Increment_State(); // if(so.faze==so.endfaze) // { // arrSizeList.RemoveAt(i); // i--; // } // } // ScrollButton1.BringToFront(); // ScrollButton2.BringToFront(); // if((RetreatCommand)||(!MouseOver&& (delay+=(timer1.Interval)<20?20:timer1.Interval)>Delay&&Retreat)) // { // ExpandCommand = false; // Size sz = this.Size; // if (((sz.Width > XOffset))) // { // sz.Width -= 10; // this.Size = sz; // ChangeState((int)States.Compressing); // } // else // { // sz.Width = XOffset; // this.splitter1.Hide(); // Size = sz; // delay = 0; // ChangeState((int)States.Compressed); // RetreatCommand = false; // } // } // if((ExpandCommand)||(MouseOver&& (delay+=20)>10)) // { // Size sz = this.Size; // if (sz.Width < ButtonWidth+XOffset+RightMargin) // { // sz.Width += 20; // this.Size = sz; // ChangeState((int)States.Extending); // } // else // { // sz.Width = XOffset + ButtonWidth+2+RightMargin; // this.splitter1.Show(); // this.splitter1.Hide(); // Size = sz; // delay = 0; // ChangeState((int)States.Extended); // ExpandCommand = false; // } // } // if(SB1Down && (sbdelay+=(timer1.Interval<20)?20:timer1.Interval)>300) // { // ScrollUp(); // sbdelay-=20; // } // if(SB2Down && (sbdelay+=(timer1.Interval<20)?20:timer1.Interval)>300) // { // ScrollDown(); // sbdelay-=20; // } //} private void Mouse_Down(object sender, System.Windows.Forms.MouseEventArgs e) { base.OnMouseDown(e); ImageListView lv = ((ImageListView)sender); //ListView lv =((ListView)sender); //ListViewItem itm = lv.GetItemAt(e.X,e.Y); ImageListViewItem itm = (ImageListViewItem)lv.Items.FocusedItem; if (itm == null) { return; } List_Click(sender, e); lv.DoDragDrop(lv.Columns[0].Text + Separator + lv.SelectedItems[0].Text, DragDropEffects.Copy); }
/// <summary> /// Handles control's MouseMove event. /// </summary> public void MouseMove(MouseEventArgs e) { ImageListItem oldHoveredItem = HoveredItem; // ImageListView.ImageListViewColumnHeader oldHoveredColumn = HoveredColumn; // ImageListView.ImageListViewColumnHeader oldHoveredSeparator = HoveredSeparator; DoHitTest(e.Location); mImageListView.mRenderer.SuspendPaint(); // Do we need to scroll the view? if (MouseSelecting && mImageListView.ScrollOrientation == ScrollOrientation.VerticalScroll && !scrollTimer.Enabled) { if (e.Y > mImageListView.ClientRectangle.Bottom) { scrollTimer.Tag = -120; scrollTimer.Enabled = true; } else if (e.Y < mImageListView.ClientRectangle.Top) { scrollTimer.Tag = 120; scrollTimer.Enabled = true; } } else if (MouseSelecting && mImageListView.ScrollOrientation == ScrollOrientation.HorizontalScroll && !scrollTimer.Enabled) { if (e.X > mImageListView.ClientRectangle.Right) { scrollTimer.Tag = -120; scrollTimer.Enabled = true; } else if (e.X < mImageListView.ClientRectangle.Left) { scrollTimer.Tag = 120; scrollTimer.Enabled = true; } } else if (scrollTimer.Enabled && mImageListView.ClientRectangle.Contains(e.Location)) { scrollTimer.Enabled = false; } if (DraggingSeperator) { //int delta = e.Location.X - lastSeparatorDragLocation.X; //int colwidth = SelectedSeperator.Width + delta; //if (colwidth > 16) // lastSeparatorDragLocation = e.Location; //else //{ // lastSeparatorDragLocation = new Point(e.Location.X - colwidth + 16, e.Location.Y); // colwidth = 16; //} //SelectedSeperator.Width = colwidth; //HoveredItem = null; //HoveredColumn = SelectedSeperator; //HoveredSeparator = SelectedSeperator; mImageListView.Refresh(); } else if (ResizingPane) { int delta = e.Location.X - lastPaneResizeLocation.X; int width = mImageListView.mPaneWidth + delta; if (width > 2) { lastPaneResizeLocation = e.Location; } else { lastPaneResizeLocation = new Point(e.Location.X - width + 2, e.Location.Y); width = 2; } mImageListView.mPaneWidth = width; HoveredItem = null; //HoveredColumn = null; //HoveredSeparator = null; mImageListView.Refresh(); } else if (MouseSelecting) { //if (!ShiftKey && !ControlKey) // mImageListView.SelectedItems.Clear(false); // Create the selection rectangle Point viewOffset = mImageListView.ViewOffset; Point pt1 = new Point(lastMouseDownLocation.X - (viewOffset.X - lastViewOffset.X), lastMouseDownLocation.Y - (viewOffset.Y - lastViewOffset.Y)); Point pt2 = new Point(e.Location.X, e.Location.Y); SelectionRectangle = new Rectangle(Math.Min(pt1.X, pt2.X), Math.Min(pt1.Y, pt2.Y), Math.Abs(pt1.X - pt2.X), Math.Abs(pt1.Y - pt2.Y)); // Normalize to item area coordinates pt1 = new Point(SelectionRectangle.Left, SelectionRectangle.Top); pt2 = new Point(SelectionRectangle.Right, SelectionRectangle.Bottom); Point itemAreaOffset = new Point(-mImageListView.layoutManager.ItemAreaBounds.Left, -mImageListView.layoutManager.ItemAreaBounds.Top); pt1.Offset(itemAreaOffset); pt2.Offset(itemAreaOffset); // Determine which items are highlighted highlightedItems.Clear(); int startRow = (int)Math.Floor((float)(Math.Min(pt1.Y, pt2.Y) + viewOffset.Y) / (float)mImageListView.layoutManager.ItemSizeWithMargin.Height); int endRow = (int)Math.Floor((float)(Math.Max(pt1.Y, pt2.Y) + viewOffset.Y) / (float)mImageListView.layoutManager.ItemSizeWithMargin.Height); int startCol = (int)Math.Floor((float)(Math.Min(pt1.X, pt2.X) + viewOffset.X) / (float)mImageListView.layoutManager.ItemSizeWithMargin.Width); int endCol = (int)Math.Floor((float)(Math.Max(pt1.X, pt2.X) + viewOffset.X) / (float)mImageListView.layoutManager.ItemSizeWithMargin.Width); if (mImageListView.ScrollOrientation == ScrollOrientation.HorizontalScroll && (startRow >= 0 || endRow >= 0)) { for (int i = startCol; i <= endCol; i++) { for (int col = startCol; col <= endCol; col++) { if (i >= 0 && i <= mImageListView.Items.Count - 1 && !highlightedItems.ContainsKey(mImageListView.Items[i])) { highlightedItems.Add(mImageListView.Items[i], (ControlKey ? !mImageListView.Items[i].Selected : true)); } } } } else if (mImageListView.ScrollOrientation == ScrollOrientation.VerticalScroll && (startCol >= 0 || endCol >= 0) && (startRow >= 0 || endRow >= 0) && (startCol <= mImageListView.layoutManager.Cols - 1 || endCol <= mImageListView.layoutManager.Cols - 1)) { startCol = Math.Min(mImageListView.layoutManager.Cols - 1, Math.Max(0, startCol)); endCol = Math.Min(mImageListView.layoutManager.Cols - 1, Math.Max(0, endCol)); for (int row = startRow; row <= endRow; row++) { for (int col = startCol; col <= endCol; col++) { int i = row * mImageListView.layoutManager.Cols + col; if (i >= 0 && i <= mImageListView.Items.Count - 1 && !highlightedItems.ContainsKey(mImageListView.Items[i])) { highlightedItems.Add(mImageListView.Items[i], (ControlKey ? !mImageListView.Items[i].Selected : true)); } } } } //HoveredColumn = null; //HoveredSeparator = null; //SelectedSeperator = null; mImageListView.Refresh(); } else if (!MouseSelecting && !DraggingSeperator && !ResizingPane && inItemArea && lastMouseDownInItemArea && (LeftButton || RightButton) && ((Math.Abs(e.Location.X - lastMouseDownLocation.X) > SelectionTolerance || Math.Abs(e.Location.Y - lastMouseDownLocation.Y) > SelectionTolerance))) { if (!lastMouseDownOverItem && HoveredItem == null) { // Start mouse selection MouseSelecting = true; SelectionRectangle = new Rectangle(lastMouseDownLocation, new Size(0, 0)); mImageListView.Refresh(); } else if (lastMouseDownOverItem && HoveredItem != null && mImageListView.AllowDrag) { // Start drag&drop if (!HoveredItem.Selected) { HoveredItem.mSelected = true; mImageListView.OnSelectionChangedInternal(); DropTarget = null; mImageListView.Refresh(true); } // Set drag data List <string> filenames = new List <string>(); DataObject data = new DataObject(DataFormats.FileDrop, filenames.ToArray()); DropTarget = null; selfDragging = true; mImageListView.DoDragDrop(data, DragDropEffects.Copy); selfDragging = false; // Since the MouseUp event will be eaten by DoDragDrop we will not receive // the MouseUp event. We need to manually update mouse button flags after // the drop. if ((Control.MouseButtons & MouseButtons.Left) == MouseButtons.None) { LeftButton = false; } if ((Control.MouseButtons & MouseButtons.Right) == MouseButtons.None) { RightButton = false; } } } else if (!MouseSelecting && !DraggingSeperator && !ResizingPane && inHeaderArea && lastMouseDownInColumnHeaderArea && lastMouseDownOverSeparator && LeftButton)// && // mImageListView.AllowColumnResize && HoveredSeparator != null) { // Start dragging a separator DraggingSeperator = true; // SelectedSeperator = HoveredSeparator; lastSeparatorDragLocation = e.Location; } else if (!MouseSelecting && !DraggingSeperator && !ResizingPane && inPaneArea && lastMouseDownInPaneArea && lastMouseDownOverPaneBorder && LeftButton && mImageListView.AllowPaneResize && HoveredPaneBorder != false) { // Start dragging the pane ResizingPane = true; lastPaneResizeLocation = e.Location; } else if (!ReferenceEquals(HoveredItem, oldHoveredItem))// || //!ReferenceEquals(HoveredColumn, oldHoveredColumn) || //!ReferenceEquals(HoveredSeparator, oldHoveredSeparator)) { // Hovered item changed if (!ReferenceEquals(HoveredItem, oldHoveredItem)) { mImageListView.OnItemHover(new ItemHoverEventArgs(HoveredItem, oldHoveredItem)); } //if (!ReferenceEquals(HoveredColumn, oldHoveredColumn)) // mImageListView.OnColumnHover(new ColumnHoverEventArgs(HoveredColumn, oldHoveredColumn)); mImageListView.Refresh(); } mImageListView.mRenderer.ResumePaint(); // Change to size cursor if mouse is over a column separator or pane border if (mImageListView.Cursor != Cursors.VSplit && mImageListView.Focused && !MouseSelecting) { //if ((mImageListView.AllowColumnResize && HoveredSeparator != null) || // (mImageListView.AllowPaneResize && HoveredPaneBorder != false)) // mImageListView.Cursor = Cursors.VSplit; } else if (mImageListView.Cursor == Cursors.VSplit) { //if (!((inHeaderArea && (DraggingSeperator || HoveredSeparator != null)) || // (inPaneArea && (ResizingPane || HoveredPaneBorder != false)))) // mImageListView.Cursor = Cursors.Default; } lastMouseMoveLocation = e.Location; }