相关疑难解决方法(0)

如何在c#中绘制圆角矩形

我正在使用此代码来制作圆角矩形.但它只绘制了rectanlge的左上角和右上角,更不能完成下部的矩形.如何使其完整和充实.我应该做些什么改变?

public static Bitmap DrawRoundedRectangle(Bitmap Image, Color BoxColor, int XPosition, int YPosition,
        int Height, int Width, int CornerRadius)
    {
     Bitmap NewBitmap = new Bitmap(Image, Image.Width, Image.Height);
     using (Graphics NewGraphics = Graphics.FromImage(NewBitmap))
    {
        using (Pen BoxPen = new Pen(BoxColor))
        {
            using (GraphicsPath Path = new GraphicsPath())
            {
                   Path.AddLine(XPosition + CornerRadius, YPosition, XPosition + Width - (CornerRadius * 2), YPosition);
                    Path.AddArc(XPosition + Width - (CornerRadius * 2), YPosition, CornerRadius * 2, CornerRadius * 2, 270, 90);
                  Path.AddLine(XPosition + Width, YPosition + CornerRadius, …
Run Code Online (Sandbox Code Playgroud)

c# graphics drawing rectangles winforms

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

如何在WS_EX_LAYERED表单上绘制控件?

我正在使用这个代码做一个透明的纯色形式.

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  BlendFunction: TBlendFunction;
  BitmapPos: TPoint;
  BitmapSize: TSize;
  exStyle: DWORD;
  Bitmap: TBitmap;
begin
  exStyle := GetWindowLongA(Handle, GWL_EXSTYLE);
  if (exStyle and WS_EX_LAYERED = 0) then
    SetWindowLong(Handle, GWL_EXSTYLE, exStyle or WS_EX_LAYERED);

  Bitmap := TBitmap.Create;
  try
    Bitmap.PixelFormat …
Run Code Online (Sandbox Code Playgroud)

delphi winapi

6
推荐指数
1
解决办法
4170
查看次数

半透明的圆圈与文本

我正在开展一个项目,我需要在中间添加一个带文字的圆圈.我正在使用下面的代码.但我的问题是圆圈太小,当我调整它的大小时,它会重叠其他控件.我想绘制与正方形相同宽度的圆圈,或者如何使背景透明?

在此输入图像描述

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

    using (Bitmap bitmap = new Bitmap(this.Width, this.Height))
    {
        using (Graphics graphics = Graphics.FromImage(bitmap))
        {
            graphics.SmoothingMode = SmoothingMode.HighQuality;
            graphics.Clear(this.BackColor);

            using (SolidBrush brush = new SolidBrush(this._FillColor))
            {                      
                graphics.FillEllipse(brush, 0x18 - 6, 0x18 - 6, (this.Width - 0x30) + 12, (this.Height - 0x30) + 12);
            }

            Brush FontColor = new SolidBrush(this.ForeColor);
            SizeF MS = graphics.MeasureString(Convert.ToString(Convert.ToInt32((100 / _Maximum) * _Value)), Font);
            graphics.DrawString(Convert.ToString(Convert.ToInt32((100 / _Maximum) * _Value)), Font, FontColor, Convert.ToInt32((Width / 2 - MS.Width / 2) + …
Run Code Online (Sandbox Code Playgroud)

c# transparency winforms

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

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

我有一个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
查看次数