Подтвердить что ты не робот

Форма с закругленными границами в С#?

Я использую этот код, чтобы форма не имела стиля рамки:

this.FormBorderStyle = FormBorderStyle.None;

Мне нужно сделать закругленные края на форме.

Есть ли простой способ? Как это сделать?

4b9b3361

Ответ 1

Взгляните на это: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.region.aspx

Класс Form наследуется от класса Control, поэтому попробуйте сделать тот же образец, который у вас есть на ссылке, на свойство Form Region (и, конечно же, сделать это в событии формы):

    // This method will change the square button to a circular button by 
// creating a new circle-shaped GraphicsPath object and setting it 
// to the RoundButton objects region.
private void roundButton_Paint(object sender, 
    System.Windows.Forms.PaintEventArgs e)
{

    System.Drawing.Drawing2D.GraphicsPath buttonPath = 
        new System.Drawing.Drawing2D.GraphicsPath();

    // Set a new rectangle to the same size as the button 
    // ClientRectangle property.
    System.Drawing.Rectangle newRectangle = roundButton.ClientRectangle;

    // Decrease the size of the rectangle.
    newRectangle.Inflate(-10, -10);

    // Draw the button border.
    e.Graphics.DrawEllipse(System.Drawing.Pens.Black, newRectangle);

    // Increase the size of the rectangle to include the border.
    newRectangle.Inflate( 1,  1);

    // Create a circle within the new rectangle.
    buttonPath.AddEllipse(newRectangle);

    // Set the button Region property to the newly created 
    // circle region.
    roundButton.Region = new System.Drawing.Region(buttonPath);

}

Ответ 2

Я знаю, что вопрос уже был дан, я хотел бы добавить альтернативу и глупую НО, но не рекомендуется, так как ваш вопрос не ограничивает ответ в виде кодов...

  • Создайте пустое квадратное изображение с цветом фона в качестве заливки, затем сотрите верхние левые закругленные углы, чтобы они были прозрачными, повторите это ко всем углам.
  • Установите очень маловероятный цвет в качестве цвета фона формы
  • Установите этот цвет как TransparencyKey в вашей форме
  • Добавьте изображения как PictureBox и поместите их в соответствующие углы

Viola!

Ответ 3

    public static void RoundBorderForm(Form frm)
    {

        Rectangle Bounds = new Rectangle(0, 0, frm.Width, frm.Height);
        int CornerRadius = 20;
        System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
        path.AddArc(Bounds.X, Bounds.Y, CornerRadius, CornerRadius, 180, 90);
        path.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y, CornerRadius, CornerRadius, 270, 90);
        path.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90);
        path.AddArc(Bounds.X, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90);
        path.CloseAllFigures();

        frm.Region = new Region(path);
        frm.Show();
    }