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);
}
}
}
这篇关于这可能有三角形的图片框而不是矩形的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:这可能有三角形的图片框而不是矩形的吗?


基础教程推荐
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01