当前位置: 首页>>代码示例>>C#>>正文


C# Control.GetControlAncestors方法代码示例

本文整理汇总了C#中System.Windows.Forms.Control.GetControlAncestors方法的典型用法代码示例。如果您正苦于以下问题:C# Control.GetControlAncestors方法的具体用法?C# Control.GetControlAncestors怎么用?C# Control.GetControlAncestors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.Control的用法示例。


在下文中一共展示了Control.GetControlAncestors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateHelpStack

        private static void UpdateHelpStack()
        {
            needStackUpdate = false;

            // Retrieving all windows in a z-sorted way is a "time consuming" (~ 0.05ms) and API-heavy
            // query, and we don't need to be that accurate. Don't do it every time. Once a second is enough.
            bool updateGlobalWindows =
                globalWindows == null ||
                (DateTime.Now - lastGlobalWindowUpdate).TotalMilliseconds > 1000 ||
                globalWindows.Any(f => f.IsDisposed);
            if (updateGlobalWindows)
            {
                lastGlobalWindowUpdate = DateTime.Now;
                globalWindows = EditorHelper.GetZSortedAppWindows();
            }

            // Iterate through our list of windows to find the one we're hovering
            foreach (Form form in globalWindows)
            {
                if (!form.Visible) continue;
                if (!new Rectangle(form.Location, form.Size).Contains(Cursor.Position)) continue;

                Point localPos = form.PointToClient(Cursor.Position);
                hoveredControl = form.GetChildAtPointDeep(localPos, GetChildAtPointSkip.Invisible | GetChildAtPointSkip.Transparent);
                break;
            }

            Control c;
            HelpInfo help;

            // Get rid of disposed Controls
            c = hoveredHelpProvider as Control;
            if (c == null || c.IsDisposed)
            {
                hoveredHelpProvider = null;
                hoveredHelpCaptured = false;
            }

            // An IHelpProvider has captured the mouse: Ask what to do with it.
            if (hoveredHelpCaptured)
            {
                help = hoveredHelpProvider.ProvideHoverHelp(c.PointToClient(Cursor.Position), ref hoveredHelpCaptured);

                // Update provider's help info
                stack.UpdateFromProvider(hoveredHelpProvider, help);

                // If still in charge: Return early.
                if (hoveredHelpCaptured) return;
            }

            // No IHelpProvider in charge: Find one that provides help
            help = null;
            IHelpProvider lastHelpProvider = hoveredHelpProvider;
            foreach (IHelpProvider hp in hoveredControl.GetControlAncestors<IHelpProvider>())
            {
                c = hp as Control;
                help = hp.ProvideHoverHelp(c.PointToClient(Cursor.Position), ref hoveredHelpCaptured);
                hoveredHelpProvider = hp;
                if (help != null || hoveredHelpCaptured) break;
            }

            // Update help system based on the result.
            if (lastHelpProvider != hoveredHelpProvider)
                stack.UpdateFromProvider(lastHelpProvider, hoveredHelpProvider, help);
            else if (hoveredHelpProvider != null)
                stack.UpdateFromProvider(hoveredHelpProvider, help);
        }
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:67,代码来源:HelpSystem.cs

示例2: UpdateHelpStack

        private static void UpdateHelpStack()
        {
            needStackUpdate = false;

            foreach (Form f in EditorHelper.GetZSortedAppWindows())
            {
                if (!f.Visible) continue;
                if (!new Rectangle(f.Location, f.Size).Contains(Cursor.Position)) continue;

                Point localPos = f.PointToClient(Cursor.Position);
                hoveredControl = f.GetChildAtPointDeep(localPos, GetChildAtPointSkip.Invisible | GetChildAtPointSkip.Transparent);
                break;
            }

            Control c;
            HelpInfo help;

            // Get rid of disposed Controls
            c = hoveredHelpProvider as Control;
            if (c == null || c.IsDisposed)
            {
                hoveredHelpProvider = null;
                hoveredHelpCaptured = false;
            }

            // An IHelpProvider has captured the mouse: Ask what to do with it.
            if (hoveredHelpCaptured)
            {
                help = hoveredHelpProvider.ProvideHoverHelp(c.PointToClient(Cursor.Position), ref hoveredHelpCaptured);

                // Update provider's help info
                stack.UpdateFromProvider(hoveredHelpProvider, help);

                // If still in charge: Return early.
                if (hoveredHelpCaptured) return;
            }

            // No IHelpProvider in charge: Find one that provides help
            help = null;
            IHelpProvider lastHelpProvider = hoveredHelpProvider;
            foreach (IHelpProvider hp in hoveredControl.GetControlAncestors<IHelpProvider>())
            {
                c = hp as Control;
                help = hp.ProvideHoverHelp(c.PointToClient(Cursor.Position), ref hoveredHelpCaptured);
                hoveredHelpProvider = hp;
                if (help != null || hoveredHelpCaptured) break;
            }

            // Update help system based on the result.
            if (lastHelpProvider != hoveredHelpProvider)
                stack.UpdateFromProvider(lastHelpProvider, hoveredHelpProvider, help);
            else if (hoveredHelpProvider != null)
                stack.UpdateFromProvider(hoveredHelpProvider, help);
        }
开发者ID:sinithwar,项目名称:duality,代码行数:54,代码来源:HelpSystem.cs


注:本文中的System.Windows.Forms.Control.GetControlAncestors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。