Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#圆角矩形MVS 2012_C# - Fatal编程技术网

c#圆角矩形MVS 2012

c#圆角矩形MVS 2012,c#,C#,我是c#编程的初学者,想在windowsformapplication中绘制一个矩形。 我使用Microsoft Visual Studio 2012并获得以下示例代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using Sy

我是c#编程的初学者,想在windowsformapplication中绘制一个矩形。 我使用Microsoft Visual Studio 2012并获得以下示例代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

    }
    private void FillRectangleRectangle(PaintEventArgs e)
    {

        // Create solid brush.
        SolidBrush blueBrush = new SolidBrush(Color.Blue);

        // Create rectangle.
        Rectangle rect = new Rectangle(0, 0, 200, 200);

        // Fill rectangle to screen.
        e.Graphics.FillRectangle(blueBrush, rect);
    }




    }
  }

但是它不是word,有人能帮我吗?

在表单上添加绘画事件,并插入函数的代码(这是正确的)。 应该是这样的:

private void Form1_Paint(object sender, PaintEventArgs e)
{
   SolidBrush blueBrush = new SolidBrush(Color.Blue);
   Rectangle rect = new Rectangle(0, 0, 200, 200);
   e.Graphics.FillRectangle(blueBrush, rect);
}
无论何时您想要重新绘制表单,请使用

Invalidate();

我认为您需要刷新您试图绘制的对象。试试这些

form.Invalidate();
form.Refresh();  

应该绘制的代码没有在任何地方被调用。这就是表单的
Paint
事件的用途。您应该分配该事件,然后在代码中执行以下操作:

private void Form1_Paint(object sender, PaintEventArgs e)
{
    FillRectangleRectangle(e);
}

那么,您想在哪里调用
FillRectangleRectangle
?你说的“它不起作用”到底是什么意思?发生了什么?尝试在窗体的Paint事件中调用函数。仅此-.-thx此。Paint+=新的PaintEventHandler(FillRectangleRectangle);在设计师那里做——这就是它的目的。通常您不需要在代码中分配事件。@ThorstenDittmar啊,没有看到。很抱歉