- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在我的应用程序中同时使用 Rectangle 和 graphicspath 绘制线条,当使用 GraphicsPath 而不是使用 Rectangle 时,我面临着绘图中宽度和高度的丢失。
下面是重现我的问题的示例代码,
protected override void OnPaint(PaintEventArgs e)
{
int left = ClientRectangle.X + 40, right = ClientRectangle.Width -80;
int bottom = ClientRectangle.Height - 80, top = ClientRectangle.Y + 40;
int borderWidth = 10;
Rectangle borderrectangle = new Rectangle(left, top, right, bottom);
Pen pen = new Pen(Color.Black, borderWidth);
//Draws lines using Rectangle.
e.Graphics.DrawRectangle(pen, borderrectangle);
Point[] points = new Point[]
{
new Point(left, top),
new Point(right, top),
new Point(right, bottom),
new Point(left, bottom),
};
GraphicsPath path = new GraphicsPath();
path.AddLines(points);
path.CloseFigure();
//Draws lines using Path.
e.Graphics.DrawPath(pen, path);
}
内部矩形使用 DrawPath 绘制,外部矩形使用 DrawRectangle 绘制。
谁能告诉我 GraphicsPath 绘图时宽度和高度丢失的原因,因为我已经给出了像矩形一样的适当点?
我们将不胜感激。
最佳答案
当您创建 Rectangle 时,您传递的是右侧和底部坐标作为宽度和高度。检查Rectangle构造函数参数:
public Rectangle(
int x,
int y,
int width,
int height
)
当你使用 Path 时,你是通过坐标绘制它,一切都很好。你应该这样创建矩形:
Rectangle borderrectangle = new Rectangle(left, top, right-left, bottom-top);
但要保证ClientRectangle的宽高都大于120
关于c# - DrawPath 和 DrawRectangle 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43936364/
我有一个 wxFrame 和几个 wxTextCtrl 以及派生自 wxWindow 的自定义 Image Class 的其他成员> 并且有一个 wxImage 成员。 在 wxFrame 的 OnP
好吧,我正在为我自己的控件编写 OnPaint 事件,我非常需要使其像素精确。 我在矩形边框方面遇到了一点问题。 看图: 删除了无效的 ImageShack 链接 这两个矩形是使用相同的位置和大小参数
我正在尝试在表单上绘制可变颜色/宽度的边框(用于“整个房间”状态报告),它绘制得很好,除非在非主要显示器上最大化... 在第二个显示器上最大化时,我没有绘制最左边的边缘,如图所示 here (为调试添
我有一个全屏表单,在 Paint 事件的处理程序中,我在整个表单周围绘制了一个 2px 的边框。我为连接到计算机的每个屏幕创建了这些表格之一。出于某种原因,顶部和左侧边框未绘制在任何非主显示器上。窗体
几乎每次我使用 Graphics.DrawRectangle或 Graphics.FillRectangle (int 版本)我似乎错过了要绘制的矩形的右侧和底部边框上的像素。 哪些像素被填充的确切定
我正在绘制一个矩形,休眠了几毫秒——然后我想清除该矩形,但我不知道如何清除。 (该矩形位于图形上方,因此我不能简单地用另一个矩形覆盖它) graphics.DrawRe
当我在图像中绘制红色正方形时,我希望该正方形中的像素为“红色”。然而,它们却是黑色的...... >>> from SimpleCV import Image,Color >>> Color.RED
下面的 WPF 程序会显示一个如下所示的窗口: 黑色方 block 外的鼠标移动会导致窗口标题随鼠标位置更新。当鼠标进入正方形时停止更新。 我希望 MouseMove 继续触发,即使鼠标在正方形上也是
private void Form1_Paint(object sender, PaintEventArgs e) { Pen p = new Pen(Brushes.Black, 1);
我在我的应用程序中同时使用 Rectangle 和 graphicspath 绘制线条,当使用 GraphicsPath 而不是使用 Rectangle 时,我面临着绘图中宽度和高度的丢失。 下面是重
使用 DrawingContext 时. DrawRectangle与 TileBrush ,我注意到矩形的左上角不是底层图像的左上角。这发生在两个 DrawingBrush和 ImageBrush来
我的 highcharts-more.js 文件有问题。它开始在下面给我错误; CRIPT5007: Unable to get property 'drawRectangle' of undefin
这里的代码非常简单...只是在 OnPaint 例程中为 Form 绘制应该是 64x64 的矩形: protected override void OnPaint(PaintEventArgs e)
正如标题所说,我想用异或模式画一些东西,因为我想在一段时间后清理它。 我在 Visual Studio 2010 中使用 C#(窗口窗体)。 谁能帮我解决这个问题? 最佳答案 我为 .net 做了一个
我有以下代码: public void DrawLetter(int Cell, string Letter, int X, int Y) { System.Drawing.Font fBody
我是一名优秀的程序员,十分优秀!