首页 新闻 会员 周边 捐助

C#不规则窗体之空心圈圈窗体

0
悬赏园豆:20 [已解决问题] 解决于 2024-05-08 21:55

上次开发了一个鼠圈圈的应用程序,就是屏幕跟随鼠标的圈圈。不过目前没实现圈圈窗体代码,想实现与博客网页里的鼠标圈圈效果,所以来这请园友们请教。

这个是博文:https://www.cnblogs.com/lzhdim/p/18010388 

具体圈圈效果请见我的博客效果。

请热心的园友给出无规则圈圈窗体创建的代码,先谢谢啦。

lzhdim的主页 lzhdim | 小虾三级 | 园豆:650
提问于:2024-02-18 21:41
< >
分享
最佳答案
0

1、弄一个背景透明的圈圈图片;

2、设置窗体的BackgroundImage为图片;设置TransprantKey为背景色,设置BackColor为背景色;

 

因为图片为透明的背景,所以窗体只显示的圈圈,也是透明空心的圈圈了。。。

lzhdim | 小虾三级 |园豆:650 | 2024-05-08 21:38
其他回答(1)
0

要实现一个不规则的空心圈圈窗体,你可以使用 C# 的 WinForms 应用程序来实现。以下是一个简单的示例代码:

csharp
Copy code
using System;
using System.Drawing;
using System.Windows.Forms;

public class IrregularForm : Form
{
private Point center;
private int radius = 50;

public IrregularForm()
{
    this.FormBorderStyle = FormBorderStyle.None;
    this.BackColor = Color.Transparent;
    this.TransparencyKey = Color.Transparent;
    this.TopMost = true;
    this.StartPosition = FormStartPosition.Manual;
    this.Bounds = Screen.PrimaryScreen.Bounds;

    this.MouseMove += IrregularForm_MouseMove;
}

protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);
    
    using (Pen pen = new Pen(Color.Red, 2))
    {
        e.Graphics.DrawEllipse(pen, center.X - radius, center.Y - radius, 2 * radius, 2 * radius);
    }
}

private void IrregularForm_MouseMove(object sender, MouseEventArgs e)
{
    center = e.Location;
    Invalidate();
}

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new IrregularForm());
}

}
这个示例代码创建了一个继承自 Form 的 IrregularForm 类,它是一个无边框、透明背景的窗体。在窗体的 OnPaint 方法中绘制了一个空心圆,而鼠标移动事件则用来更新圆心的位置。通过这种方式,你可以在屏幕上随着鼠标的移动绘制出一个不规则的空心圆。

收获园豆:20
Technologyforgood | 园豆:7514 (大侠五级) | 2024-02-29 17:10

这个只是在窗体上绘制的圈圈吧,不是空心圈圈窗体。

支持(0) 反对(0) lzhdim | 园豆:650 (小虾三级) | 2024-03-01 19:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册