松鼠的博客

导航

ListBox坐标

 

private void CreateEditBox(object sender)
{
listBox1
= (ListBox)sender ; 
itemSelected 
= listBox1.SelectedIndex ;
Rectangle r 
= listBox1.GetItemRectangle(itemSelected);
string itemText = (string)listBox1.Items[itemSelected];
editBox.Location 
= new System.Drawing.Point(r.X + delta , r.Y + delta ) ;
editBox.Size 
= new System.Drawing.Size(r.Width -10 , r.Height- delta);
editBox.Show();
listBox1.Controls.AddRange(
new System.Windows.Forms.Control[] {this.editBox}); 
editBox.Text 
= itemText ;
editBox.Focus();
editBox.SelectAll(); 
editBox.KeyPress 
+= new System.Windows.Forms.KeyPressEventHandler(this.EditOver);
editBox.LostFocus 
+= new System.EventHandler(this.FocusOver);
}

使用 GetItemRectangle 和 Rectangle
MSDN2:http://msdn2.microsoft.com/zh-cn/library/system.drawing.rectangle.location.aspx

posted on 2008-01-08 10:30  Xproer-松鼠  阅读(209)  评论(0)    收藏  举报