簡體   English   中英

如何確定哪個UI元素在GTK#中具有焦點?

[英]How do I determine which UI element has focus in GTK#?

在C#中,很容易找到哪個元素具有焦點。 您只需執行以下操作:

using System.Windows;
using System.Windows.Input;

namespace Whatever
{
    public partial class MainWindow : Window
    {
        public IInputElement GetFocusedElement()
        {
            return FocusManager.GetFocusedElement(this);
        }
    }
}

我想在Mono / GTK#中做大致的等效。 我該怎么做?

在GTK窗口(Mainwindow / this)上是一個Focus道具,它返回Widget 您可以獲取並設置它,它應該在所有“關注的”容器子對象中波動,直到到達最后一個關注的節點。

因此,更新代碼示例:

public partial class MainWindow : Window
{
    public Widget GetFocusedElement()
    {
        Console.WriteLine (((Widget)this.Focus).Name);
        return this.Focus;
    }
}

暫無
暫無

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

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