- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
两个标签都有 AutoSize
true 和 TextAlign
MiddleCenter。
label2 怎么也能显示平滑的边框?
这是处理程序 Form.Load(...)
& Form.Paint(...)
的测试代码:
int _cornerRadius = 10;
Point _locationLabel2;
// Form.Load(...)
private void Form3_Load(object sender, EventArgs e)
{
// Step 1: Cut the label regions (seems to be ok, result is the same for both labels)
GraphicsPath graphicsPath = _getRoundPath(label1.ClientRectangle, _cornerRadius);
label1.Region = new Region(graphicsPath);
graphicsPath = _getRoundPath(label2.ClientRectangle, _cornerRadius);
label2.Region = new Region(graphicsPath);
_locationLabel2 = this.PointToClient(label2.Parent.PointToScreen(label2.Location));
}
// Form.Paint(...)
private void Form3_Paint(object sender, PaintEventArgs e)
{
using (Pen pen = new Pen(label1.BackColor, 3.0f))
{
// Step 2: Smooth the label borders (ok only for label1)
_drawRoundedRectangle(e.Graphics, pen, label1.Location.X, label1.Location.Y,
label1.ClientRectangle.Width, label1.ClientRectangle.Height, _cornerRadius);
_drawRoundedRectangle(e.Graphics, pen, _locationLabel2.X, _locationLabel2.Y,
label2.ClientRectangle.Width, label2.ClientRectangle.Height, _cornerRadius);
}
}
// Helper 1/3
private static GraphicsPath _getRoundPath(Rectangle rectangle, int radius)
{
int x = rectangle.X;
int y = rectangle.Y;
int width = rectangle.Width;
int height = rectangle.Height;
radius = radius << 1;
GraphicsPath path = new GraphicsPath();
if (radius > 0)
{
if (radius > height) radius = height;
if (radius > width) radius = width;
path.AddArc(x, y, radius, radius, 180, 90);
path.AddArc(x + width - radius, y, radius, radius, 270, 90);
path.AddArc(x + width - radius, y + height - radius, radius, radius, 0, 90);
path.AddArc(x, y + height - radius, radius, radius, 90, 90);
path.CloseFigure();
}
else
{
path.AddRectangle(rectangle);
}
return path;
}
// Helper 2/3
private void _drawRoundedRectangle(Graphics graphics, Pen pen, int x, int y, int width, int height, int radius)
{
RectangleF rectangle = new RectangleF(x, y, width, height);
GraphicsPath path = _generateRoundedRectangle(graphics, rectangle, radius);
SmoothingMode old = graphics.SmoothingMode;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.DrawPath(pen, path);
graphics.SmoothingMode = old;
}
// Helper 3/3
private static GraphicsPath _generateRoundedRectangle(Graphics graphics, RectangleF rectangle, int radius)
{
GraphicsPath path = new GraphicsPath();
float diameter = radius * 2.0F;
SizeF sizeF = new SizeF(diameter, diameter);
RectangleF arc = new RectangleF(rectangle.Location, sizeF);
path.AddArc(arc, 180, 90);
arc.X = rectangle.Right - diameter;
path.AddArc(arc, 270, 90);
arc.Y = rectangle.Bottom - diameter;
path.AddArc(arc, 0, 90);
arc.X = rectangle.Left;
path.AddArc(arc, 90, 90);
path.CloseFigure();
return path;
}
主要代码部分来自Arun Reginald Zaheeruddin
最佳答案
按照这个answer解决了作者:@Reza Aghaei。
解决方案
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
public class RoundLabel : Label
{
[Browsable(true)]
public Color _BackColor { get; set; }
public RoundLabel()
{
this.DoubleBuffered = true;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
using (var graphicsPath = _getRoundRectangle(this.ClientRectangle))
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (var brush = new SolidBrush(_BackColor))
e.Graphics.FillPath(brush, graphicsPath);
using (var pen = new Pen(_BackColor, 1.0f))
e.Graphics.DrawPath(pen, graphicsPath);
TextRenderer.DrawText(e.Graphics, Text, this.Font, this.ClientRectangle, this.ForeColor);
}
}
private GraphicsPath _getRoundRectangle(Rectangle rectangle)
{
int cornerRadius = 15; // change this value according to your needs
int diminisher = 1;
GraphicsPath path = new GraphicsPath();
path.AddArc(rectangle.X, rectangle.Y, cornerRadius, cornerRadius, 180, 90);
path.AddArc(rectangle.X + rectangle.Width - cornerRadius - diminisher, rectangle.Y, cornerRadius, cornerRadius, 270, 90);
path.AddArc(rectangle.X + rectangle.Width - cornerRadius - diminisher, rectangle.Y + rectangle.Height - cornerRadius - diminisher, cornerRadius, cornerRadius, 0, 90);
path.AddArc(rectangle.X, rectangle.Y + rectangle.Height - cornerRadius - diminisher, cornerRadius, cornerRadius, 90, 90);
path.CloseAllFigures();
return path;
}
}
关于c# - 带有光滑圆角的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42627293/
光滑,如何将查询映射到继承表模型? IE, 我有表A,B,C A是“父”表,B&C是“子”表 我想知道的是我该如何使用平滑模型,以便A将成为抽象的B&C具体类型,而查询A中的一行将导致B或C对象 类似
如果数据库尚不存在,有没有办法轻松创建数据库? Database.forURL("jdbc:mysql://127.0.0.1/database", driver = "com.mysql.jdbc.
我是 Java slick 的新手,我对“相机”的翻译有一个小问题。我有这个代码: package chapterOne; import org.newdawn.slick.Animation; im
我正在尝试使用 Slick 渲染健康栏。我想要一个红色矩形,前面有一个绿色矩形来显示剩余的生命值。这是我到目前为止所拥有的: Rectangle healthBG = new Rect
有一个225px的方 block 。在里面插入一张大尺寸的图片(850 像素)。她走到外面。 看起来像这样: .content {display: inline-block;} .column {fl
我正在用 Java slick 编写游戏,我想添加消息管理。应该有一个 ArrayList,其中包含所有尚未发送的消息。每 2 秒应显示列表中的下一项。 我的逻辑: 在更新方法中,应显示第一条消息。
case class Account(var email:String, var pass:String, var familyId: Int, var accessId: Int, id: Opti
Content should wrap Content should wrap Content should wrap C
我正在使用 JQuery Slick Slider http://kenwheeler.github.io/slick/效果非常好。 我还运行了一个单独的脚本,用于检查页面 url,如果光滑 slid
我知道如何使用 click, scroll 的事件处理函数和其他默认事件。 目前我正在使用一个名为 slick slider 的 slider 插件。并且它工作正常,我想用定义的函数而不是匿名函数替换
我有 slider ,每个 slider 都包含视频作为背景和播放/暂停按钮。尝试通过单击正确的按钮来播放视频,但出现以下行为:我单击第二张幻灯片中的播放按钮,视频从第一张幻灯片中播放。暂停按钮也是如
我正在尝试在我的页面上实现一个光滑的 slider 。在浏览精美的文档时,他们提到要以响应方式使用 slider ,请遵循代码(我在下面发布)。我无法理解断点的用途。谁能给我解释一下代码。我尝试谷歌搜
我遇到了光滑 slider 的问题,我想创建一个应该在光滑 slider 上打开的灯箱,我想在灯箱中添加一些内容,主要问题是我不知道如何我可以将内容添加到灯箱部分吗? $('.works-slides
我正在尝试使用一个 slider ,它附带一个搜索框。此搜索框搜索 slider 中的用户名称。 目前,当用户开始在输入框中键入内容时,搜索框会自动完成全名。 例如,他们输入“Joh”,建议输入“Jo
我一直在尝试创建类似 this 的东西使用 slick.js,我真的无法理解它。 我已经准备好了当前的代码。如何使中心幻灯片图像的宽度和高度为 100% 并为幻灯片添加填充?好像不行。 我真的很感激任
我使用光滑 slider 创建了 slider 。我遇到的问题是在线断点工作正常的宽度。 但是,当我以正常方式写入 html file 时,相同的代码不起作用。谁能帮我这个。从检查中检查并查看正常代码
我正在尝试在输入字段中删除可拖动选项(以便我可以选择文本并使用箭头在字段内导航)。 var slider = $('.slider').slick({ infinite: false,
当它到达 breakpoint 时,如 990px,我在 slick slider 中遇到了问题。它删除了背景并且没有显示任何类型的错误。 iconic 我正在使用这个 javascript 来提
我想将光滑 slider 的点定位在上一个和下一个按钮之间。Slick 提供设置让您定位点/按钮。但它们会互相显示。 这是我的代码: $('.slider').slick({ arrows:
我在网站上创建了一个光滑的 slider 。我可以看到它进入“光滑模式”,但也没有显示我告诉它的幻灯片数量。它们都在那里,我可以通过更改它们的“左”和“不透明度”CSS 值来显示它们。 我将无法复制这
我是一名优秀的程序员,十分优秀!