相关疑难解决方法(0)

如何使用WinForms(.NET)绘制圆角矩形?

使用C#绘制矩形,我需要首先绘制每个边缘的弧我绘制矩形,然后我需要单击按钮它将在边缘绘制弧,我该怎么办?

.net c# winforms

17
推荐指数
2
解决办法
7万
查看次数

带有自定义边框和圆边的C#表单

我正在使用此代码来创建带有圆边的表单(FormBorderStyle = none):

[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
    int nLeftRect, // x-coordinate of upper-left corner
    int nTopRect, // y-coordinate of upper-left corner
    int nRightRect, // x-coordinate of lower-right corner
    int nBottomRect, // y-coordinate of lower-right corner
    int nWidthEllipse, // height of ellipse
    int nHeightEllipse // width of ellipse
 );

public Form1()
{
    InitializeComponent();
    Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));
}
Run Code Online (Sandbox Code Playgroud)

这是在Paint事件上设置自定义边框:

    ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, Color.Black, 5, ButtonBorderStyle.Solid, Color.Black, 5, ButtonBorderStyle.Solid, Color.Black, 5, ButtonBorderStyle.Solid, Color.Black, …
Run Code Online (Sandbox Code Playgroud)

c# rounded-corners winforms formborderstyle

12
推荐指数
1
解决办法
4万
查看次数

如何避免带有圆角的可缩放用户控件的彩色边框的视觉伪影?

我有一个Form其中包含:

  1. a TrackBar(最小值 = 1,最大值 = 200,表示缩放百分比);
  2. 与.UserControlBorderStyle = BorderStyle.None

相关代码

表格1

来自设计师代码

trackBar1.Value = 100;
BackColor = Color.Gray;
Run Code Online (Sandbox Code Playgroud)

从代码隐藏

private void trackBar1_Scroll(object sender, EventArgs e)
{
    userControl11.SetZoomFactor(trackBar1.Value / 100F);
}
Run Code Online (Sandbox Code Playgroud)

用户控制1

internal float MyBaseWidth;

public UserControl1()
{
    InitializeComponent();

    MyBaseWidth = Width;

    SetZoomFactor(1);
}

protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);

    e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
    e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
    e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

    Pen p = new Pen(Color.Yellow);
    e.Graphics.DrawPath(p, GraphicsPathWithBorder);
}

internal GraphicsPath GraphicsPathWithBorder;

internal void SetZoomFactor(float …
Run Code Online (Sandbox Code Playgroud)

c# user-controls rounded-corners visual-artifacts winforms

4
推荐指数
1
解决办法
1111
查看次数