c# - wpf 中 OnPaintBackground 的替代方案。

标签 c# wpf winforms

有一个 Windows 窗体应用程序,我正在尝试将其转换为 wpf ,但是当我使用

覆盖主窗口上的 onPaintBackground 时
protected override void OnPaintBackground(PaintEventArgs pevent)

有错误

no suitable method found to override

那么 wpf 中 onPaintBackground 的替代方案是什么?

最佳答案

一般来说,您不应该在 WPF 中“绘画”。因为连续重新创建对象(钢笔、画笔、形状)可能会非常慢。

您可以覆盖 OnRender方法,此页面的示例:

protected override void OnRender(DrawingContext dc)
{
    SolidColorBrush mySolidColorBrush  = new SolidColorBrush();
    mySolidColorBrush.Color = Colors.LimeGreen;
    Pen myPen = new Pen(Brushes.Blue, 10);
    Rect myRect = new Rect(0, 0, 500, 500);
    dc.DrawRectangle(mySolidColorBrush, myPen, myRect);
}

关于c# - wpf 中 OnPaintBackground 的替代方案。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10686813/

相关文章:

c# - System.InvalidCastException 解析 FluentCommandLineParser 参数

c# - 如何取消绑定(bind)ObjectDataSource?

c# - 如何使用 HtmlAgility Pack 解析 WPF 中 div id 标记之间的值?

WPF 用户控件数据绑定(bind)不起作用

c# - Windows 条形码阅读器服务

winforms - GMap.NET Windows Forms 用鼠标移动 map

c# - 在 Visual Studio 2019 中键入时,如何获取第 3 方类的 IntelliSense 提示?

c# - 使用 DispatcherObject 的 VerifyAccess 和 CheckAccess 方法

c# - .NET 属性网格 : Varying Read/Write rights for a complex object using ExpandableObjectConverter

c# - 用于唯一字符的 HashSet