gpt4 book ai didi

c# - 在 C# 中重写绘制控件

转载 作者:行者123 更新时间:2023-11-30 22:24:21 25 4
gpt4 key购买 nike

任何人都可以提供有关如何在 C# 中覆盖绘制事件的基本教程吗?我在 C# 方面没有太多经验,这是我不容易掌握的部分,因为我无法遵循一些教程和技巧,因为我不了解 C# 中重写的概念。

最佳答案

这是一个非常基本的示例,它将(应该!)绘制一个红色的“X”:

public class FacadeControl : Control
{
private Pen invalidPen;


public FacadeControl()
{
invalidPen = new Pen(Color.Red, 2);
SetStyle(ControlStyles.ResizeRedraw, true); // make sure the control is redrawn every time it is resized
}



protected override void OnPaint(PaintEventArgs pe)
{
// get the graphics object to use to draw
Graphics g = pe.Graphics;

g.DrawLine(invalidPen, 0, 0, Width, Height);
g.DrawLine(invalidPen, 0, Height, Width, 0);
}
}

关于c# - 在 C# 中重写绘制控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12816752/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com