VSCode使用技巧——Ctrl+鼠标滚轮键使字体进行缩放

点击VSCode左下角的齿轮,进入设置

进入Extensions——》JSON——》Edit in settings.json

在json当中添加如下:

"editor.mouseWheelZoom": true,

 

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
非常抱歉,我在之前的回答中遗漏了以鼠标为中心的部分。以下是更新后的代码: ```csharp using System; using System.Drawing; using System.Windows.Forms; namespace GraphicsPathExample { public partial class Form1 : Form { private GraphicsPath graphicsPath; private float scaleFactor = 1.0f; private Point scaleCenter; public Form1() { InitializeComponent(); // 创建一个GraphicsPath对象,并添加一些图形路径 graphicsPath = new GraphicsPath(); graphicsPath.AddEllipse(50, 50, 200, 100); graphicsPath.AddRectangle(new Rectangle(100, 150, 150, 100)); // 设置PictureBox的鼠标事件 pictureBox1.MouseWheel += PictureBox1_MouseWheel; pictureBox1.MouseMove += PictureBox1_MouseMove; } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); // 创建一个变换矩阵 Matrix matrix = new Matrix(); matrix.Scale(scaleFactor, scaleFactor); matrix.Translate(scaleCenter.X, scaleCenter.Y); // 在PictureBox上绘制图形路径 e.Graphics.Transform = matrix; e.Graphics.DrawPath(Pens.Black, graphicsPath); } private void PictureBox1_MouseWheel(object sender, MouseEventArgs e) { // 计算因子 float delta = e.Delta / 1200.0f; scaleFactor += delta; // 限制因子的范围 if (scaleFactor < 0.1f) scaleFactor = 0.1f; if (scaleFactor > 5.0f) scaleFactor = 5.0f; // 计算中心点位置 scaleCenter = e.Location; // 重新绘制PictureBox pictureBox1.Invalidate(); } private void PictureBox1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Middle) { // 更新中心点位置 scaleCenter = e.Location; // 重新绘制PictureBox pictureBox1.Invalidate(); } } } } ``` 在这个更新后的示例代码中,我们添加了一个新的变量`scaleCenter`来存储的中心点位置。在PictureBox的MouseWheel事件和MouseMove事件中,我们都更新了`scaleCenter`的值。 在MouseWheel事件中,我们根据鼠标滚轮的滚动值来计算因子,并根据鼠标的位置更新`scaleCenter`。在MouseMove事件中,如果鼠标按下并移动,我们也更新了`scaleCenter`的值。 然后,在OnPaint事件中,我们先使用Translate方法将画布平移至中心点位置,然后再进行操作。这样就可以实现以鼠标为中心进行显示了。 希望这次的回答能满足你的需求!如果还有其他问题,请随时提问。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值