簡體   English   中英

如何使用相對位置設置textBox位置?

[英]How to set the textBox position Using Relative position?

在列表框中包含多個列表項,它將基於列表框高度顯示列表框中的前5條記錄。 如果我滾動列表框項目的第7條記錄或第一個位置。 如果用戶滾動listboxitem,我需要找出位置可見的listbox選定項(基於高度在listbox中顯示5條記錄)

編輯:

lstbxindex.ItemContainerGenerator.ContainerFromItem(lstbxindex.SelectedItem);

            System.Windows.Point relativePoint = lstbxindex.TransformToVisual(listBoxItem)
                               .Transform(new System.Windows.Point(0, 0));

使用此代碼,我得到了列表框selecteditem的相對位置。 如果用戶在滾動后滾動列表框項目,則需要將文本框覆蓋到列表框中特定的選定項目位置。 所以我檢查情況,

Listbox firstItem x=-2,y-2
Listbox secondItem x=-2,y=-56
Listbox thirdItem x=-2,y=-110
etc
relative position y increasing 54.

所以我檢查

if(relativePoint.Y==56)
{
**//how to set the textbox to that relative position in listbox**
}

在winforms中,您可以使用Listbox.TopIndex屬性訪問頂部可見的項目,請檢查它是否在WPF中實現! 下面是WINFORM App中的示例代碼。

lstbxindex.Items[lstbxindex.TopIndex].ToString()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM