ScottPlot5默认的右键菜单是英文的,如果需要改成中文,可以有两种方式。
一种是在ScottPlot5源文件包里修改,当插件更新后需要重新编译。
另一种是通过函数自定义右键菜单,避免对源包的修改。
下面的函数提供了图像另存为,复制和重置缩放三个功能,使用时调用即可。

private void SetMyRightMenu(ScottPlot.WinForms.FormsPlot formsPlot)
{
	//设置右键菜单
	formsPlot.Menu?.Clear();
	formsPlot.Menu?.Add("保存", (plot) =>
	{
	    SaveFileDialog saveImageDialog = new SaveFileDialog();	
	    saveImageDialog.Title = "图像另存为";
	    saveImageDialog.Filter = "svg矢量图|*.svg|jpg图片|*.jpg,*.jpeg|bmp图片|*.bmp|png图片|*.png|webp图片|*.webp";
	    saveImageDialog.FilterIndex = 1;
	    saveImageDialog.RestoreDirectory = true;
	    if (saveImageDialog.ShowDialog() == DialogResult.OK)
	    {
	        string pictureName = saveImageDialog.FileName;
	        plot.Save(pictureName, formsPlot.Width, formsPlot.Height);
	    }
	});
	
	formsPlot.Menu?.Add("复制", (plot) =>
	{
	    byte[] bytes = plot.GetImage(formsPlot.Width, formsPlot.Height).GetImageBytes();
	    Bitmap bitmap = null;
	    using (MemoryStream stream = new MemoryStream(bytes))
	    {
	        bitmap = new Bitmap(stream);
	    }
	    Clipboard.SetImage(bitmap);	
	});
	
	formsPlot.Menu?.Add("重置缩放", (plot) =>
	{
	    plot.Axes.AutoScale();
	    plot.PlotControl?.Refresh();
	});
}
Logo

中国智能体开发者社区,聚焦智能体与大模型开发,提供前沿资讯、实用工具链、开源项目及行业案例。通过技术沙龙、开发者大赛等活动,促进经验交流与协作,助力开发者快速构建创新智能应用。

更多推荐