本文整理汇总了C#中System.Windows.Forms.Cursor.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Cursor.Dispose方法的具体用法?C# Cursor.Dispose怎么用?C# Cursor.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Cursor
的用法示例。
在下文中一共展示了Cursor.Dispose方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: treeView_ItemDrag
//-------------------------------------------------------------------------------------
#region << Drag&Drop Methods >>
void treeView_ItemDrag(object sender, ItemDragEventArgs e)
{
try
{
if(allowInternalDragDrop == false)
return;
if((e.Button & MouseButtons.Left) != MouseButtons.Left)
return;
StringFormat sf = new StringFormat();
sf.Trimming = StringTrimming.EllipsisCharacter;
ITreeItem item = (ITreeItem)((SimTreeNode)e.Item).TreeItem;
if(item != SelectedNodeItem)
SelectNodeWithItem(item);
Bitmap bmp = null;
Brush back = null;
Pen border = null;
try
{
back = new SolidBrush(SystemColors.Info);
border = new Pen(SystemColors.InfoText);
SizeF ms = this.CreateGraphics().MeasureString(item.ItemText, treeView.Font);
if(ms.Width > this.Width - 50)
ms.Width = this.Width - 50;
Rectangle r = new Rectangle(0,0, (int)ms.Width + 5, (int)ms.Height + 2);
bmp = new Bitmap(r.Width, r.Height, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(back, r);
g.DrawRectangle(border, new Rectangle(0,0,r.Width-1, r.Height-1)); //
using(SolidBrush text = new SolidBrush(SystemColors.InfoText))
g.DrawString(item.ItemText, treeView.Font, text, new RectangleF(2, 1, r.Width, r.Height), sf);
//cursorCan = new Cursor(bmp.GetHicon());
cursorCan = WinAPI.IconInfo.CreateCursorFromBitmap(bmp, 0,0);
bmp = new Bitmap(r.Width + 7, r.Height + 7, PixelFormat.Format32bppArgb);
g = Graphics.FromImage(bmp);
g.FillRectangle(back, r);
g.DrawRectangle(border, r);
using(SolidBrush text = new SolidBrush(SystemColors.InfoText))
g.DrawString(item.ItemText, treeView.Font, text, new RectangleF(2, 1, r.Width, r.Height), sf);
g.DrawIcon(Properties.Resources.StopIcon, new Rectangle(r.Width - 9, r.Height - 9, 16, 16));
//cursorCanNot = new Cursor(bmp.GetHicon());
cursorCanNot = WinAPI.IconInfo.CreateCursorFromBitmap(bmp, 0, 0);
this.DoDragDrop(item, DragDropEffects.Move);
treeView.Cursor = Cursors.Default;
if(treeView.prevDropNode != null)
{
treeView.BeginUpdate();
treeView.prevDropNode.NodeFont = null;
treeView.prevDropNode.ForeColor = Color.Empty;
treeView.prevDropNode = null;
treeView.EndUpdate();
}
}
finally
{
if(back != null)
back.Dispose();
back = null;
if(border != null)
border.Dispose();
border = null;
if(cursorCan != null)
cursorCan.Dispose();
cursorCan = null;
if(cursorCanNot != null)
cursorCanNot.Dispose();
cursorCanNot = null;
if(bmp != null)
bmp.Dispose();
bmp = null;
}
}
catch(Exception Err)
{
Sim.Controls.ErrorBox.Show(Err);
}
}
示例2: ListDragSource_MouseMove
private void ListDragSource_MouseMove(object sender, MouseEventArgs e)
{
//注意这里的严密性, 最好不使用e.Button == MouseButtons.Left, 因为e.Button还可能具有其他的属性
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
{
// If the mouse moves outside the rectangle, start the drag.
//这里做得太好了,防止意外的拖拽,不是说鼠标动了一下就要拖拽!
if (dragBoxFromMouseDown != Rectangle.Empty &&
!dragBoxFromMouseDown.Contains(e.X, e.Y))
{
// Create custom cursors for the drag-and-drop operation.
try
{
MyNormalCursor = new Cursor("3dwarro.cur");
MyNoDropCursor = new Cursor("3dwno.cur");
}
catch
{
// An error occurred while attempting to load the cursors, so use
// standard cursors.
UseCustomCursorsCheck.Checked = false;
}
finally
{
// The screenOffset is used to account for any desktop bands
// that may be at the top or left side of the screen when
// determining when to cancel the drag drop operation.
screenOffset = SystemInformation.WorkingArea.Location;
// Proceed with the drag-and-drop, passing in the list item.
DragDropEffects dropEffect = ListDragSource.DoDragDrop(ListDragSource.Items[indexOfItemUnderMouseToDrag], DragDropEffects.All | DragDropEffects.Link);
//拖拽结束后继续执行!
// If the drag operation was a move then remove the item.
if (dropEffect == DragDropEffects.Move)
{
ListDragSource.Items.RemoveAt(indexOfItemUnderMouseToDrag);
// Selects the previous item in the list as long as the list has an item.
if (indexOfItemUnderMouseToDrag > 0)
ListDragSource.SelectedIndex = indexOfItemUnderMouseToDrag - 1;
else if (ListDragSource.Items.Count > 0)
// Selects the first item.
ListDragSource.SelectedIndex = 0;
}
// Dispose of the cursors since they are no longer needed.
if (MyNormalCursor != null)
MyNormalCursor.Dispose();
if (MyNoDropCursor != null)
MyNoDropCursor.Dispose();
}
}
}
}
示例3: ListDragSource_MouseMove
private void ListDragSource_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
{
// If the mouse moves outside the rectangle, start the drag.
if (dragBoxFromMouseDown != Rectangle.Empty &&
!dragBoxFromMouseDown.Contains(e.X, e.Y))
{
// Create custom cursors for the drag-and-drop operation.
try
{
MyNormalCursor = new Cursor(@"C:\Windows\Cursors\lnodrop.cur");
MyNoDropCursor = new Cursor(@"C:\Windows\Cursors\larrow.cur");
DropLocationLabel.Text = "!!!";
}
catch (Exception ex)
{
// An error occurred while attempting to load the cursors, so use
// standard cursors.
DropLocationLabel.Text = ex.Message;
UseCustomCursorsCheck.Checked = false;
}
finally
{
// The screenOffset is used to account for any desktop bands
// that may be at the top or left side of the screen when
// determining when to cancel the drag drop operation.
screenOffset = SystemInformation.WorkingArea.Location;
// Proceed with the drag-and-drop, passing in the list item.
DragDropEffects dropEffect = ListDragSource.DoDragDrop(ListDragSource.Items[indexOfItemUnderMouseToDrag], DragDropEffects.All | DragDropEffects.Link);
// If the drag operation was a move then remove the item.
if (dropEffect == DragDropEffects.Move)
{
ListDragSource.Items.RemoveAt(indexOfItemUnderMouseToDrag);
// Selects the previous item in the list as long as the list has an item.
if (indexOfItemUnderMouseToDrag > 0)
ListDragSource.SelectedIndex = indexOfItemUnderMouseToDrag - 1;
else if (ListDragSource.Items.Count > 0)
// Selects the first item.
ListDragSource.SelectedIndex = 0;
}
// Dispose of the cursors since they are no longer needed.
if (MyNormalCursor != null)
MyNormalCursor.Dispose();
if (MyNoDropCursor != null)
MyNoDropCursor.Dispose();
}
}
}
}
示例4: ListDragSource_MouseMove
private void ListDragSource_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
{
if (!ListDragTarget.Lock)
{
bool draggable = true;
if (sender == ListDragTarget)
{
draggable = ListDragTarget.RemovableForTaskFlow(IndexOfItemUnderMouseToDrag);
}
if (!draggable)
Cursor.Current = Cursors.No;
// If the mouse moves outside the rectangle, start the drag.
if (draggable && dragBoxFromMouseDown != Rectangle.Empty &&
!dragBoxFromMouseDown.Contains(e.X, e.Y))
{
// Create custom cursors for the drag-and-drop operation.
try
{
TaskListBox ctrl = (TaskListBox)sender;
MyNormalCursor = ctrl.CreateCursor(IndexOfItemUnderMouseToDrag, true);
MyNodropCursor = ctrl.CreateCursor(IndexOfItemUnderMouseToDrag, false);
}
catch
{
}
finally
{
// The screenOffset is used to account for any desktop bands
// that may be at the top or left side of the screen when
// determining when to cancel the drag drop operation.
screenOffset = SystemInformation.WorkingArea.Location;
object data = ((TaskListBox)sender).GetDragData(IndexOfItemUnderMouseToDrag);
if (sender == ListDragTarget)
{
((TaskListBox)sender).RemoveAt(IndexOfItemUnderMouseToDrag);
AlignHelpMessage();
}
// Proceed with the drag-and-drop, passing in the list item.
DragDropEffects dropEffect = ((TaskListBox)sender).DoDragDrop(data, DragDropEffects.All | DragDropEffects.Copy);
// Dispose of the cursors since they are no longer needed.
if (MyNormalCursor != null)
MyNormalCursor.Dispose();
if (MyNodropCursor != null)
MyNodropCursor.Dispose();
}
}
}
}
else
{
if (sender is TaskListBox)
{
TaskListBox listbox = (TaskListBox)sender;
int newHoveredIndex = listbox.IndexFromPoint(e.Location);
if(newHoveredIndex==-1)
this.ToolTip.ShowAlways = false;
if (hoveredIndex != newHoveredIndex)
{
hoveredIndex = newHoveredIndex;
if (hoveredIndex > -1)
{
AbstractProcessingTask task = listbox.Get(hoveredIndex);
if (task != null)
{
this.ToolTip.Active = false;
this.ToolTip.SetToolTip(listbox, task.ToolTip);
this.ToolTip.Active = true;
this.ToolTip.ShowAlways = true;
}
}
}
}
}
}