GTK# Eventbox MotionNotify not working

本文关键字:working not MotionNotify Eventbox GTK# | 更新日期: 2023-09-27 18:15:40

我有一个EventBox在我的应用程序中处理通知事件(enternotify, motionNotify和LeaveNotify是我感兴趣的事件)。在这个EventBox内部是一个HScale,我根据鼠标位置显示音频搜索的工具提示。但是动作通知事件不会被触发。

一些代码:

protected void ebAudiofileSeekerEnterNotifyEvent (object o, EnterNotifyEventArgs args)
    {
        log.debug("ebAudiofileSeekerEnterNotifyEvent called");
        int x = -1;
        int y = -1;
        int intX = -1;
        int intY = -1;
        int originX;
        int originY;
        this.GetPosition(out originX, out originY);
        Gdk.ModifierType modifierType = Gdk.ModifierType.None;
        this.Screen.RootWindow.GetPointer(out x, out y, out modifierType);
        this.hsAudiofileSeeker.TranslateCoordinates(this,this.hsAudiofileSeeker.Allocation.X,this.hsAudiofileSeeker.Allocation.Y,out intX,out intY);
        double valueAtPos = ((x - (intX + originX)) / (this.hsAudiofileSeeker.Allocation.Width * 1.0)) * this.hsAudiofileSeeker.Adjustment.Upper * 1.0;
        long ticksAtPosition = (this.objProgram.getAudioManager().getDuration().Ticks * (long)valueAtPos) / 100;
        TimeSpan timeSpanAtPosition = TimeSpan.FromTicks(ticksAtPosition);
        this.lblTooltipAudiofileSeeker.Text = (timeSpanAtPosition.Hours > 9 ? timeSpanAtPosition.Hours.ToString() : "0" + timeSpanAtPosition.Hours.ToString()) + ":" + (timeSpanAtPosition.Minutes > 9 ? timeSpanAtPosition.Minutes.ToString() : "0" + timeSpanAtPosition.Minutes.ToString()) + ":" + (timeSpanAtPosition.Seconds > 9 ? timeSpanAtPosition.Seconds.ToString() : "0" + timeSpanAtPosition.Seconds.ToString());
        this.hsAudiofileSeeker.TooltipWindow.Move(x, intY + originY);
        this.hsAudiofileSeeker.TooltipWindow.ShowAll();
    }
    protected void ebAudiofileSeekerMotionNotifyEvent (object o, MotionNotifyEventArgs args)
    {
        log.debug("ebAudiofileSeekerMotionNotifyEvent called");
        int x = -1;
        int y = -1;
        int intX = -1;
        int intY = -1;
        int originX;
        int originY;
        this.GetPosition(out originX, out originY);
        Gdk.ModifierType modifierType = Gdk.ModifierType.None;
        this.Screen.RootWindow.GetPointer(out x, out y, out modifierType);
        this.hsAudiofileSeeker.TranslateCoordinates(this,this.hsAudiofileSeeker.Allocation.X,this.hsAudiofileSeeker.Allocation.Y,out intX,out intY);
        double valueAtPos = ((x - (intX + originX)) / (this.hsAudiofileSeeker.Allocation.Width * 1.0)) * this.hsAudiofileSeeker.Adjustment.Upper * 1.0;
        long ticksAtPosition = (this.objProgram.getAudioManager().getDuration().Ticks * (long)valueAtPos) / 100;
        TimeSpan timeSpanAtPosition = TimeSpan.FromTicks(ticksAtPosition);
        this.lblTooltipAudiofileSeeker.Text = (timeSpanAtPosition.Hours > 9 ? timeSpanAtPosition.Hours.ToString() : "0" + timeSpanAtPosition.Hours.ToString()) + ":" + (timeSpanAtPosition.Minutes > 9 ? timeSpanAtPosition.Minutes.ToString() : "0" + timeSpanAtPosition.Minutes.ToString()) + ":" + (timeSpanAtPosition.Seconds > 9 ? timeSpanAtPosition.Seconds.ToString() : "0" + timeSpanAtPosition.Seconds.ToString());
        this.hsAudiofileSeeker.TooltipWindow.Move(x, intY + originY);
    }
    protected void ebAudiofileSeekerLeaveNotifyEvent (object o, LeaveNotifyEventArgs args)
    {
        log.debug("ebAudiofileSeekerLeaveNotifyEvent called");
        this.hsAudiofileSeeker.TooltipWindow.HideAll();
    }

eaudiofileseekermotionnotifyevent和eaudiofileseekerleavenotifyevent工作,但不是运动事件,有什么想法吗?我有点糊涂了。谢谢你的帮助。

GTK# Eventbox MotionNotify not working

是否关闭了事件压缩?工具提示打开POINTER_MOTION_HINT_MASK,这会干扰事件压缩。

我遇到了这个问题,将eaudiofileseeker AboveChild属性设置为true,并为侦听器添加了以下代码:

protected void ebAudiofileSeekerEnterNotifyEvent (object o, EnterNotifyEventArgs args)
    {
        log.debug("ebAudiofileSeekerEnterNotifyEvent called");
        if (Program.getInstance().getAudioManager().Duration > TimeSpan.Zero)
        {
            int x = -1;
            int y = -1;
            int intX = -1;
            int intY = -1;
            int originX;
            int originY;
            this.GetPosition(out originX, out originY);
            Gdk.ModifierType modifierType = Gdk.ModifierType.None;
            this.Screen.RootWindow.GetPointer(out x, out y, out modifierType);
            this.hsAudiofileSeeker.TranslateCoordinates(this, this.hsAudiofileSeeker.Allocation.X, this.hsAudiofileSeeker.Allocation.Y, out intX, out intY);
            double valueAtPos = ((x - (intX + originX)) / (this.hsAudiofileSeeker.Allocation.Width * 1.0)) * this.hsAudiofileSeeker.Adjustment.Upper * 1.0;
            long ticksAtPosition = (Program.getInstance().getAudioManager().Duration.Ticks * (long)valueAtPos) / 100;
            TimeSpan timeSpanAtPosition = TimeSpan.FromTicks(ticksAtPosition);
            this.lblTooltipAudiofileSeeker.Text = (timeSpanAtPosition.Hours > 9 ? timeSpanAtPosition.Hours.ToString() : "0" + timeSpanAtPosition.Hours.ToString()) + ":" + (timeSpanAtPosition.Minutes > 9 ? timeSpanAtPosition.Minutes.ToString() : "0" + timeSpanAtPosition.Minutes.ToString()) + ":" + (timeSpanAtPosition.Seconds > 9 ? timeSpanAtPosition.Seconds.ToString() : "0" + timeSpanAtPosition.Seconds.ToString());
            this.hsAudiofileSeeker.TooltipWindow.Move(x, intY + originY);
            this.hsAudiofileSeeker.TooltipWindow.ShowAll();
        }
    }
protected void ebAudiofileSeekerMotionNotifyEvent (object o, MotionNotifyEventArgs args)
{
    log.debug("ebAudiofileSeekerMotionNotifyEvent called");
    if (Program.getInstance().getAudioManager().Duration > TimeSpan.Zero)
    {
        int x = -1;
        int y = -1;
        int intX = -1;
        int intY = -1;
        int originX;
        int originY;
        this.GetPosition(out originX, out originY);
        Gdk.ModifierType modifierType = Gdk.ModifierType.None;
        this.Screen.RootWindow.GetPointer(out x, out y, out modifierType);
        this.hsAudiofileSeeker.TranslateCoordinates(this, this.hsAudiofileSeeker.Allocation.X, this.hsAudiofileSeeker.Allocation.Y, out intX, out intY);
        double valueAtPos = ((x - (intX + originX)) / (this.hsAudiofileSeeker.Allocation.Width * 1.0)) * this.hsAudiofileSeeker.Adjustment.Upper * 1.0;
        log.debug("modifier = " + modifierType);
        if (modifierType.HasFlag(Gdk.ModifierType.Button1Mask))
        {
            log.debug("modifier is button 1, so change value");
            this.hsAudiofileSeeker.Value = valueAtPos;
        }
        long ticksAtPosition = (Program.getInstance().getAudioManager().Duration.Ticks * (long)valueAtPos) / 100;
        TimeSpan timeSpanAtPosition = TimeSpan.FromTicks(ticksAtPosition);
        this.lblTooltipAudiofileSeeker.Text = (timeSpanAtPosition.Hours > 9 ? timeSpanAtPosition.Hours.ToString() : "0" + timeSpanAtPosition.Hours.ToString()) + ":" + (timeSpanAtPosition.Minutes > 9 ? timeSpanAtPosition.Minutes.ToString() : "0" + timeSpanAtPosition.Minutes.ToString()) + ":" + (timeSpanAtPosition.Seconds > 9 ? timeSpanAtPosition.Seconds.ToString() : "0" + timeSpanAtPosition.Seconds.ToString());
        this.hsAudiofileSeeker.TooltipWindow.Move(x, intY + originY);
    }
}
protected void ebAudiofileSeekerLeaveNotifyEvent (object o, LeaveNotifyEventArgs args)
{
    log.debug("ebAudiofileSeekerLeaveNotifyEvent called");
    this.hsAudiofileSeeker.TooltipWindow.HideAll();
}

代码可以在这里找到:http://sourceforge.net/p/audiocuesheet/code/HEAD/tree/