Is this possible to have triangular PictureBox instead of the rectangular one?(这可能有三角形的图片框而不是矩形的吗?)
问题描述
这是否可以在 Windows 窗体中使用三角形 PictureBox
控件而不是矩形控件?
Is this possible to have triangular PictureBox
control in windows forms instead of the rectangular one?
推荐答案
你有一些选择,例如:
- 您可以将控制区域设置为三角形.
- 您只能在控件的三角形区域内绘制.
示例 1
在本例中,控制区域仅限于三角形.
In this example, the region of control limited to a triangular shape.
public class TriangularPictureBox:PictureBox
{
protected override void OnPaint(PaintEventArgs pe)
{
using (var p = new GraphicsPath())
{
p.AddPolygon(new Point[] {
new Point(this.Width / 2, 0),
new Point(0, Height),
new Point(Width, Height) });
this.Region = new Region(p);
base.OnPaint(pe);
}
}
}
示例 2
在此示例中,仅在控件的三角形区域上进行绘制.
In this example, the painting will be done only on a triangular area of the control.
public class TriangularPictureBox:PictureBox
{
protected override void OnPaint(PaintEventArgs pe)
{
using (var p = new GraphicsPath())
{
p.AddPolygon(new Point[] {
new Point(this.Width / 2, 0),
new Point(0, Height),
new Point(Width, Height) });
pe.Graphics.SetClip(p);
base.OnPaint(pe);
}
}
}
这篇关于这可能有三角形的图片框而不是矩形的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:这可能有三角形的图片框而不是矩形的吗?


基础教程推荐
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 将 XML 转换为通用列表 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 如何激活MC67中的红灯 2022-01-01