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


C# Stroke.GetPacketData方法代码示例

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


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

示例1: StrokeToInputs

        /// <summary>
        ///  Converts Stroke PacketData to an Input array
        /// </summary>
        /// <param name="Stroke">
        /// The Stroke to convert from</param>           
        /// <param name="destinationRenderer">
        /// The renderer to use when converting from hi-metric to pixel coordinates</param>        
        /// <param name="horizontalScaleFactor">
        /// The horizontal scaling factor</param>
        /// <param name="verticalScaleFactor">
        /// The vertical scaling factor</param>       
        /// <param name="destinationControl">
        /// The control that ink data is played back to</param>
        /// <param name="inkOffset">
        /// The offset to the upper left of the ink data</param>
        internal static INPUT[] StrokeToInputs(
            Stroke sourceStroke, 
            Renderer destinationRenderer, 
            Graphics g, 
            float horizontalScaleFactor, 
            float verticalScaleFactor,
            Control destinationControl,
            Point inkOffset 
            )
        {
            int [] sourceStrokePacketData = sourceStroke.GetPacketData();
            INPUT[] mouseEvents = new INPUT[sourceStrokePacketData.Length/sourceStroke.PacketDescription.Length + 1];
            UInt32 tickCount = GetTickCount();
            GetBoundsCallback b = new GetBoundsCallback( delegate { return Screen.GetBounds(destinationControl).Size; } );
            Size screenSize = (Size)destinationControl.Invoke( b );

            // Iterate through each packet set and create a corresponding Mouse based Input structure
            for (int strokePacketIndex = 0, i = 0; strokePacketIndex < sourceStrokePacketData.Length; strokePacketIndex += sourceStroke.PacketDescription.Length, i++) {
                // Obtain the packet as a Point from the stroke
                Point packetPoint = new Point(sourceStrokePacketData[strokePacketIndex] - inkOffset.X, sourceStrokePacketData[strokePacketIndex+1] - inkOffset.Y);

                // Convert the inkspace coordinate of the packet to a display coordinate
                destinationRenderer.InkSpaceToPixel(g,ref packetPoint);

                // Scale the location to the current window
                packetPoint.X = (int) (packetPoint.X * horizontalScaleFactor);
                packetPoint.Y = (int) (packetPoint.Y * verticalScaleFactor);

                // Avoid mouse' enabling and moving the border of the panel)
                if ( 0 == packetPoint.X) {
                    packetPoint.X = 1;
                }
                if ( 0 == packetPoint.Y) {
                    packetPoint.Y = 1;
                }

                // Convert the window coordinates to screen coordinates
                if( destinationControl.InvokeRequired ) {
                    PointScreenCallback z = new PointScreenCallback( delegate { return destinationControl.PointToScreen( packetPoint ); } );
                    packetPoint = (Point)destinationControl.Invoke( z );
                }
                else
                    packetPoint = destinationControl.PointToScreen( packetPoint );

                #region Create the Input structure for the Mouse Event

                mouseEvents[i].type = INPUT_MOUSE;
                mouseEvents[i].mi.dx = (packetPoint.X * 65535) / screenSize.Width;
                mouseEvents[i].mi.dy = (packetPoint.Y * 65535) / screenSize.Height;
                mouseEvents[i].mi.mouseData = 0;

                if(0 == strokePacketIndex) {
                    // Move to the start of the stroke
                    mouseEvents[i].mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
                    mouseEvents[i].mi.time = tickCount++;
                    mouseEvents[i].mi.dwExtraInfo = (UIntPtr)0;

                    // Start of the 'stroke'
                    mouseEvents[++i].type = INPUT_MOUSE;
                    mouseEvents[i].mi.dx = (packetPoint.X * 65535) / screenSize.Width;
                    mouseEvents[i].mi.dy = (packetPoint.Y * 65535) / screenSize.Height;
                    mouseEvents[i].mi.mouseData = 0;
                    mouseEvents[i].mi.dwFlags = MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE;
                } else if(sourceStrokePacketData.Length - sourceStroke.PacketDescription.Length <= strokePacketIndex) {
                    // End of the 'stroke'
                    mouseEvents[i].mi.dwFlags = MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE;
                } else {
                    // Body of the 'stroke'
                    mouseEvents[i].mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
                }

                mouseEvents[i].mi.time = tickCount++;
                mouseEvents[i].mi.dwExtraInfo = (UIntPtr)0;

                #endregion
            }
            return mouseEvents;
        }
开发者ID:kevinbrink,项目名称:CP3_Enhancement,代码行数:93,代码来源:SendInputInterop.cs


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