实现类似Win10系统新建文件夹的功能代码:

文章对你有用的话免费点个赞哈,废话不多说,直接上代码:

public static void main(String[] args) {
        String directorPath = "C:\\Users\\pc\\Desktop\\代码新建的文件夹哦";//拿我的代码去用觉得修改一下这一行哈,"代码新建的文件夹哦"改为“新建文件夹”
        //创建文件夹
        File directory = new File(directorPath);
        if (!directory.exists()){
            boolean created = directory.mkdir();
            if (created){
                System.out.println("文件夹已创建:"+directorPath);
            }else {
                System.out.println("无法创建文件夹:"+directorPath);
            }
        }else {
            System.out.println("文件夹已经存在"+directorPath);
            //尝试创建带编号的文件夹
            int count = 1;
            while (true){
                String  newDirectoryPath = directorPath + "("+count +")";
                File newDirectory = new File(newDirectoryPath);
                if (!newDirectory.exists()){
                    boolean created = newDirectory.mkdir();
                    if (created){
                        System.out.println("文件已创建"+newDirectoryPath);
                        break;
                    }else {
                        System.out.println("无法创建文件夹"+newDirectoryPath);
                    }
                }
                count++;
            }
        }
    }

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现类似Win10的区域裁剪功能,你可以使用C#的Graphics类来进行绘图操作。下面是一个简单的示例代码: ```csharp using System; using System.Drawing; using System.Windows.Forms; namespace RegionClipExample { public partial class MainForm : Form { private Rectangle clipRect; // 裁剪区域的矩形 public MainForm() { InitializeComponent(); clipRect = new Rectangle(50, 50, 200, 200); // 初始化裁剪区域矩形 } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); // 创建一个Graphics对象 Graphics g = e.Graphics; // 设置裁剪区域 Region clipRegion = new Region(clipRect); g.Clip = clipRegion; // 绘制背景 g.FillRectangle(Brushes.LightGray, ClientRectangle); // 绘制文本 string text = "Hello, World!"; Font font = new Font("Arial", 16, FontStyle.Bold); SizeF textSize = g.MeasureString(text, font); PointF textLocation = new PointF((ClientSize.Width - textSize.Width) / 2, (ClientSize.Height - textSize.Height) / 2); g.DrawString(text, font, Brushes.Black, textLocation); } protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); // 更新裁剪区域的位置为鼠标点击位置 clipRect.Location = e.Location; // 刷新窗口,触发重绘 Invalidate(); } } } ``` 以上代码创建了一个Windows窗体应用程序,当鼠标在窗口上点击时,裁剪区域的位置会跟随鼠标点击位置移动,并重新绘制窗口。裁剪区域的矩形初始位置为(50, 50),大小为200x200。 在窗体的`OnPaint`方法中,我们创建一个`Graphics`对象,并设置其裁剪区域为`clipRect`。然后使用`FillRectangle`方法绘制背景,使用`DrawString`方法绘制文本。 在窗体的`OnMouseDown`方法中,我们更新裁剪区域的位置为鼠标点击位置,并调用`Invalidate`方法刷新窗口,触发重绘操作。 你可以根据自己的需要调整裁剪区域的初始位置和大小,以及绘制的内容。希望对你有帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值