本文整理汇总了C#中System.Windows.Forms.ListView.GetItemRect方法的典型用法代码示例。如果您正苦于以下问题:C# ListView.GetItemRect方法的具体用法?C# ListView.GetItemRect怎么用?C# ListView.GetItemRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ListView
的用法示例。
在下文中一共展示了ListView.GetItemRect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetItemRectTest
public void GetItemRectTest ()
{
ListView mylistview = new ListView ();
mylistview.Items.Add ("Item 1");
mylistview.Items.Add ("Item 2");
Rectangle r = mylistview.GetItemRect (1);
Assert.AreEqual (0, r.Top, "#35a");
Assert.IsTrue (r.Bottom > 0, "#35b");
Assert.IsTrue (r.Right > 0, "#35c");
Assert.IsTrue (r.Left > 0, "#35d");
Assert.IsTrue (r.Height > 0, "#35e");
Assert.IsTrue (r.Width > 0, "#35f");
}
示例2: BeginDrag
public void BeginDrag( ListView curListView, Point curPos, ListView targetListView )
{
if( Region != null )
Region.Dispose( );
if( BackgroundImage != null )
BackgroundImage.Dispose( );
DragListViewRect = CalculateApproximateRect( curListView );
DragListView = curListView;
DropListView = targetListView;
Size = new Size( DragListViewRect.Width, DragListViewRect.Height );
Opacity = 0.5;
DragOffset = DragListView.PointToClient( curPos );
DragOffset.X *= -1;
DragOffset.Y *= -1;
DragOffset.Offset( DragListViewRect.X, DragListViewRect.Y ); // リストビューの隠れている箇所のぶんのオフセット
Location = new Point(
curPos.X + DragOffset.X,
curPos.Y + DragOffset.Y
);
IntPtr coord = Api.SendMessage( DragListView.Handle, (uint)LVM.GETITEMSPACING, 0, 0 );
int horizontal = (int)Api.LOWORD( coord );
int vertical = (int)Api.HIWORD( coord );
Rectangle padding = new Rectangle(
( horizontal - DragListView.LargeImageList.ImageSize.Width ) / 2,
0, //( vertical - DragListView.LargeImageList.ImageSize.Height ) / 2,
( horizontal - DragListView.LargeImageList.ImageSize.Width ),
0 //( vertical - DragListView.LargeImageList.ImageSize.Height )
);
// 上に切れたアイテムをドラッグすると透明が描画されない
BackgroundImage = new Bitmap( Size.Width, Size.Height );
GraphicsPath path = new GraphicsPath( );
using( Graphics gfx = Graphics.FromImage( BackgroundImage ) )
{
var brush = new SolidBrush(DragListView.ForeColor);
foreach( int index in DragListView.SelectedIndices )
{
var rcIcon = DragListView.GetItemRect( index, ItemBoundsPortion.Entire );
rcIcon.Offset( -DragListViewRect.X, -DragListViewRect.Y );
rcIcon.Offset( padding.X, padding.Y );
rcIcon.Width -= padding.Width;
rcIcon.Height -= padding.Height;
gfx.DrawImage( DragListView.LargeImageList.Images[ index ], rcIcon.Left, rcIcon.Top );
var rcText = DragListView.GetItemRect( index, ItemBoundsPortion.Label );
rcText.Offset( -DragListViewRect.X, -DragListViewRect.Y );
rcText.Offset( 0 /*padding.X*/, padding.Y );
rcText.Width -= padding.Width;
rcText.Height -= padding.Height;
gfx.DrawString(
DragListView.Items[ index ].Text,
DragListView.Font, brush,
rcText.Left, rcText.Top
);
path.AddRectangle( rcIcon );
//path.AddRectangle( rcText );
}
}
Region = new Region( path );
Show( );
}