<tfoot id='zHEuJ'></tfoot>
    1. <small id='zHEuJ'></small><noframes id='zHEuJ'>

      <legend id='zHEuJ'><style id='zHEuJ'><dir id='zHEuJ'><q id='zHEuJ'></q></dir></style></legend>
        <bdo id='zHEuJ'></bdo><ul id='zHEuJ'></ul>

    2. <i id='zHEuJ'><tr id='zHEuJ'><dt id='zHEuJ'><q id='zHEuJ'><span id='zHEuJ'><b id='zHEuJ'><form id='zHEuJ'><ins id='zHEuJ'></ins><ul id='zHEuJ'></ul><sub id='zHEuJ'></sub></form><legend id='zHEuJ'></legend><bdo id='zHEuJ'><pre id='zHEuJ'><center id='zHEuJ'></center></pre></bdo></b><th id='zHEuJ'></th></span></q></dt></tr></i><div id='zHEuJ'><tfoot id='zHEuJ'></tfoot><dl id='zHEuJ'><fieldset id='zHEuJ'></fieldset></dl></div>
      1. 根据旋转的文本框旋转光标

        Rotating Cursor According to Rotated TextBox(根据旋转的文本框旋转光标)

            • <bdo id='s70sd'></bdo><ul id='s70sd'></ul>

            • <legend id='s70sd'><style id='s70sd'><dir id='s70sd'><q id='s70sd'></q></dir></style></legend>

                  <tbody id='s70sd'></tbody>

                1. <small id='s70sd'></small><noframes id='s70sd'>

                2. <i id='s70sd'><tr id='s70sd'><dt id='s70sd'><q id='s70sd'><span id='s70sd'><b id='s70sd'><form id='s70sd'><ins id='s70sd'></ins><ul id='s70sd'></ul><sub id='s70sd'></sub></form><legend id='s70sd'></legend><bdo id='s70sd'><pre id='s70sd'><center id='s70sd'></center></pre></bdo></b><th id='s70sd'></th></span></q></dt></tr></i><div id='s70sd'><tfoot id='s70sd'></tfoot><dl id='s70sd'><fieldset id='s70sd'></fieldset></dl></div>
                  <tfoot id='s70sd'></tfoot>
                  本文介绍了根据旋转的文本框旋转光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 TextBox 允许我的用户旋转.但我希望我的用户能够让他们的 Cursor 旋转到与 TextBox 旋转相同的角度.例如,如果他们将 TextBox 旋转到 28°,那么当 Cursor 进入该 TextBox 时,Cursor 应该也将自身旋转到 28°.

                  I have a TextBox that I allow my users to rotate. But what I would LOVE for my users is to have their Cursor rotate to the same angle that the TextBox was rotated at. For example, if they rotated the TextBox to 28°, then when the Cursor enters that TextBox the Cursor should also rotate itself to 28°.

                  推荐答案

                  您可以使用 WinForms 中的 System.Drawing.Icon 类结合 WPF 的位图旋转功能来旋转光标.

                  You can rotate your cursor using the System.Drawing.Icon class from WinForms in combination with WPF's bitmap rotation ability.

                  这样做的方法是加载图标,将其转换为 BitmapSource,使用 Image 和 RenderTargetBitmap 对其进行旋转,将其转换回 Icon,保存,最后更新字节 2、10 和 11它是 .cur 而不是 .ico.

                  The way to do this is to load the icon, convert it to a BitmapSource, use Image and RenderTargetBitmap to rotate it, convert it back to an Icon, save it, and finally update bytes 2, 10, and 11 that make it a .cur instead of a .ico.

                  代码如下:

                  public Cursor GetRotatedCursor(byte[] curFileBytes, double rotationAngle)
                  {
                    // Load as Bitmap, convert to BitmapSource
                    var origStream = new MemoryStream(curFileBytes);
                    var origBitmap = new System.Drawing.Icon(origStream).ToBitmap();
                    var origSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(origBitmap.GetHBitmap());
                  
                    // Construct rotated image
                    var image = new Image
                    {
                      BitmapSource = origSource,
                      RenderTransform = new RotateTransform(rotationAngle)
                    };
                  
                    // Render rotated image to RenderTargetBitmap
                    var width = origBitmap.Width;
                    var height = origBitmap.Height;
                    var resultSource = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
                    resultSource.Render(image);
                  
                    // Convert to System.Drawing.Bitmap
                    var pixels = new int[width*height];
                    resultSource.CopyPixels(pixels, width, 0);
                    var resultBitmap = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppPargb);
                    for(int y=0; y<height; y++)
                      for(int x=0; x<width; x++)
                        resultBitmap.SetPixel(x, y, Color.FromArgb(pixels[y*width+x]));
                  
                    // Save to .ico format
                    var resultStream = new MemoryStream();
                    new System.Drawing.Icon(resultBitmap.GetHIcon()).Save(resultStream);
                  
                    // Convert saved file into .cur format
                    resultStream.Seek(2); resultStream.WriteByte(curFileBytes, 2, 1);
                    resultStream.Seek(10); resultStream.WriteByte(curFileBytes, 10, 2);
                    resultStream.Seek(0);
                  
                    // Construct Cursor
                    return new Cursor(resultStream);
                  }
                  

                  如果你想避免循环,你可以用一小段usafe代码替换它来调用接受初始化数据的System.Drawing.Bitmap构造函数:

                  If you want to avoid the loop, you can replace it with a small bit of usafe code to call the System.Drawing.Bitmap constructor that takes initialization data:

                    fixed(int* bits = pixels)
                    {
                      resultBitmap = new System.Drawing.Bitmap(width, height, width, System.Drawing.Imaging.PixelFormat.Format32bppPargb, new IntPtr(bits));
                    }
                  

                  每次您的 TextBox 旋转发生变化时,您都需要调用它.这可以通过旋转 TextBox 的代码来完成,也可以通过绑定到 TextBox 旋转的值上的 PropertyChangedCallback 来完成.

                  You'll need to call this every time your TextBox rotation changes. This can be done either from the code that rotates your TextBox, or from a PropertyChangedCallback on a value that is bound to the TextBox's rotation.

                  这篇关于根据旋转的文本框旋转光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)
                    <tfoot id='VbnNf'></tfoot>
                      <bdo id='VbnNf'></bdo><ul id='VbnNf'></ul>

                        <small id='VbnNf'></small><noframes id='VbnNf'>

                        <i id='VbnNf'><tr id='VbnNf'><dt id='VbnNf'><q id='VbnNf'><span id='VbnNf'><b id='VbnNf'><form id='VbnNf'><ins id='VbnNf'></ins><ul id='VbnNf'></ul><sub id='VbnNf'></sub></form><legend id='VbnNf'></legend><bdo id='VbnNf'><pre id='VbnNf'><center id='VbnNf'></center></pre></bdo></b><th id='VbnNf'></th></span></q></dt></tr></i><div id='VbnNf'><tfoot id='VbnNf'></tfoot><dl id='VbnNf'><fieldset id='VbnNf'></fieldset></dl></div>
                            <tbody id='VbnNf'></tbody>

                          • <legend id='VbnNf'><style id='VbnNf'><dir id='VbnNf'><q id='VbnNf'></q></dir></style></legend>