c# - 如何使用 PaintEventArgs 参数调用函数?

标签 c# .net

给定以下来自 MSDN 的代码示例:

private void GetPixel_Example(PaintEventArgs e)
    {

        // Create a Bitmap object from an image file.
        Bitmap myBitmap = new Bitmap(@"C:\Users\tanyalebershtein\Desktop\Sample Pictures\Tulips.jpg");

        // Get the color of a pixel within myBitmap.
        Color pixelColor = myBitmap.GetPixel(50, 50);

        // Fill a rectangle with pixelColor.
        SolidBrush pixelBrush = new SolidBrush(pixelColor);
        e.Graphics.FillRectangle(pixelBrush, 0, 0, 100, 100);
    }

如何调用Paint函数?

最佳答案

在绘画事件中是这样的

private PictureBox pictureBox1 = new PictureBox();

pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);

private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
   GetPixel_Example(e) ;
}

关于c# - 如何使用 PaintEventArgs 参数调用函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11753345/

相关文章:

c# - 如何以编程方式将注册表项的所有权授予管理员?

c# 并从内存中删除敏感数据和所有垃圾收集副本

c# - 如何比较两个列表,其中一个列表与另一个列表开头,并且仅返回 "overhang"元素?

.NET WSDL 生成 xs :choice name the Choice Binding Enums

c# - 如何在 .NET Core 3.1.0 中使用 ACL 在 Mac OS 上管理文件夹权限

c# - CodeDom 生成的代码中的额外括号

c# - 输入字符串的格式不正确,无法解析为 DateTime

c# - .net core 是否支持代码契约?

c# - 无法构建带有 project.json 的 .NET 项目

C# :Unity container and ILogger