c# - 如何绘制运动中的椭圆?

标签 c# .net graphics

我通过外部 Controller 自己的 SDK 从外部 Controller 获取 X 和 Y 坐标。

所以,我想将这个坐标转换为半透明的圆圈并模拟鼠标光标。

我有以下代码,但我只能绘制半透明圆圈,并且无法“删除”以前的圆圈。

我想绘制半透明的圆圈,并在绘制下一个圆圈时删除它们。我应该在一个坐标和以下坐标之间绘制某种过渡来模拟“运动”。 我发现的另一个问题是,我无法在按钮、文本框等标准组件上绘制圆圈......

//...
System.Drawing.Graphics g = this.CreateGraphics();
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

System.Drawing.Color translucentYellow = System.Drawing.Color.FromArgb(128, Color.Yellow);
System.Drawing.SolidBrush aBrush = new System.Drawing.SolidBrush(translucenYellow);

g.CompositingQuality = system.Drawing.Drawing2D.CompositingQuality.GammaCorrected;

g.FillEllipse(aBrush, X, Y, width, height);
//.….

最佳答案

当系统为您做得更好时,不要绘制光标。

理想情况下,您需要做的是:

Cursor = new Cursor("D:\\circle1.cur");

不幸的是,这不适用于许多版本的 cur 文件。准确地说,任何超过 32x32 像素且带有颜色的东西。

所以你会想要使用更灵活的例程,我发现了on this post ,见下文..!

像这样使用

Cursor = CreateCursorNoResize(bmp, 16, 16);

并像这样设置光标位置:

Cursor.Position = new Point(yourX, yourY);

每当 Controller 进行更改时..

这是经过稍微修改的例程:

using System.Runtime.InteropServices;
// ..

public struct IconInfo
{
    public bool fIcon;
    public int xHotspot;
    public int yHotspot;
    public IntPtr hbmMask;
    public IntPtr hbmColor;
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetIconInfo(IntPtr hIcon, ref IconInfo pIconInfo);
[DllImport("user32.dll")]
public static extern IntPtr CreateIconIndirect(ref IconInfo icon);

public static Cursor CreateCursorNoResize(Bitmap bmp, int xHotSpot, int yHotSpot)
{
    IntPtr ptr = bmp.GetHicon();
    IconInfo tmp = new IconInfo();
    GetIconInfo(ptr, ref tmp);
    tmp.xHotspot = xHotSpot;
    tmp.yHotspot = yHotSpot;
    tmp.fIcon = false;
    ptr = CreateIconIndirect(ref tmp);
    return new Cursor(ptr);
}

注释:

  • full code有更多选择
  • 光标将转向具有自己的光标的控件(例如文本框)的不同控件。

光标位于 rw-designer :

A_Circle

关于c# - 如何绘制运动中的椭圆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26254244/

相关文章:

c# - 加入问题

c# - params 是否可用于通过使用 yield 的函数通过 ref 传递变量

c# - 使用 MSTSCLib 进行远程桌面连接

c++ - Vulkan - 在第二个渲染 channel 中加载深度附件不起作用

java - 尝试使用 KeyListeners 和 ImageIcons 时出现错误?

Java Graphics.fillPolygon : How to also render right and bottom edges?

javascript - 根据 ui 文化更改 CSS 中使用的图像。网站

javascript - 如何在 ASP.net 中从 Javascript 调用 C# 服务器端函数

c# - 将 IFoo<T> 转换为 IFoo<object> 的一般方法

c# - Bin - 在 WPF 中部署基于 MySQL Entity Framework Provider 的应用程序?