Как сделать текстовое поле с закругленным углом в C #? - PullRequest
0 голосов
/ 29 октября 2019

Мне было интересно, как сделать класс для текстовых полей с закругленными углами в c # (visual studio). Может ли кто-нибудь, пожалуйста, помогите мне. Я нашел код в Интернете, чтобы создать его, но не смог увеличить (растянуть) его

using System.Windows.Forms;
using System.Drawing;
using System;

class round : TextBox
{
    [System.Runtime.InteropServices.DllImport("gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
    private static extern IntPtr CreateRoundRectRgn
    (
        int nLeftRect, // X-coordinate of upper-left corner or padding at start
        int nTopRect,// Y-coordinate of upper-left corner or padding at the top of the textbox
        int nRightRect, // X-coordinate of lower-right corner or Width of the object
        int nBottomRect,// Y-coordinate of lower-right corner or Height of the object
                        //RADIUS, how round do you want it to be?
        int nheightRect, //height of ellipse 
        int nweightRect //width of ellipse
    );
    protected override void OnCreateControl()
    {
        base.OnCreateControl();
        this.Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(2, 3, this.Width, this.Height, 15, 15)); //play with these values till you are happy
    }
}

1 Ответ

0 голосов
/ 29 октября 2019

В сети я нашел код для его создания, но не смог его увеличить (растянуть).

При использовании этого кода размер элемента управления будет изменен (растянут) при перестройке проекта.

Чтобы применить это в конструкторе без перекомпоновки проекта, переопределите событие OnResize вместо события OnCreateControl .

Замените это:

protected override void OnCreateControl()
{
    base.OnCreateControl();
    this.Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(2, 3, this.Width, this.Height, 15, 15)); //play with these values till you are happy
}

с этим:

protected override void OnResize(EventArgs e)
{
    base.OnResize(e);
    this.Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(2, 3, this.Width, this.Height, 15, 15)); //play with these values till you are happy
}

Удачи.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...