我正在為我的應用程式尋找一個圓形圖片框,我偶然發現了這段代碼(它不是我的),我已經嘗試了很多次,但我找不到任何錯誤。我已經按照教程中為這個圓形圖片框所做的每一步,所以它不會是錯誤的,因為它在教程中作業得很好。
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
namespace New_Radio_Barcelona.Controls
{
class RashiCircularPictureBox : PictureBox
{
private int border = 2;
private Color colorBorder = Color.RoyalBlue;
private Color colorBorder2 = Color.HotPink;
private DashStyle borderstyle = DashStyle.Solid;
private DashCap borderCap = DashCap.Flat;
private float gradiant = 50f;
public RashiCircularPictureBox()
{
this.Size = new Size(95, 95);
this.SizeMode = PictureBoxSizeMode.StretchImage;
}
public int Border
{
get
{
return border;
}
set
{
border = value;
this.Invalidate();
}
}
public Color ColorBorder
{
get
{
return colorBorder;
}
set
{
colorBorder = value;
this.Invalidate();
}
}
public Color ColorBorder2
{
get
{
return colorBorder2;
}
set
{
colorBorder2 = value;
this.Invalidate();
}
}
public DashStyle Borderstyle
{
get
{
return borderstyle;
}
set
{
borderstyle = value;
this.Invalidate();
}
}
public DashCap BorderCap
{
get
{
return borderCap;
}
set
{
borderCap = value;
this.Invalidate();
}
}
public float Gradiant
{
get
{
return gradiant;
}
set
{
gradiant = value;
this.Invalidate();
}
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
this.Size = new Size(this.Width, this.Width);
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
var graphic = pe.Graphics;
var rect = Rectangle.Inflate(this.ClientRectangle, -1, -1);
var rectborder = Rectangle.Inflate(rect, -border, -border);
var size = border > 0 ? border * 3 : 1;
using (var bordercolorG = new LinearGradientBrush(rectborder, colorBorder, colorBorder2, gradiant))
using (var path = new GraphicsPath())
using (var pen = new Pen(this.Parent.BackColor, border))
using (var penborder = new Pen(bordercolorG, size))
{
graphic.SmoothingMode = SmoothingMode.AntiAlias;
penborder.DashStyle = borderstyle;
penborder.DashCap = borderCap;
path.AddEllipse(rect);
this.Region = new Region(path);
graphic.DrawEllipse(pen, rect);
if (border > 0)
{
graphic.DrawEllipse(penborder, rectborder);
}
}
}
}
}
我編譯該專案,然后嘗試將其添加到“設計”選項卡中,如教程中所示。它說它無法加載。我試圖了解什么作業不正常,但我仍然沒有發現錯誤。一些幫助PLS?要考慮的另一個方面是這樣一個事實,即在 class RashiCircularPictureBox : PictureBox代碼上方放置 1 個參考,并在public RashiCircularPictureBox()其中表示 0 個參考。可能是為了這個,但我不是班級專家,我陷入了這種愚蠢的境地。如果有人能清除我對這個問題的看法,我將不勝感激
uj5u.com熱心網友回復:
直到最近,大多數版本的 Visual Studio 中的設計器都是 32 位行程。因此,如果控制元件構建為 64 位,則無法在設計時加載它,但 VS 仍然可以創建可以在運行時使用 64 位控制元件的 64 位應用程式。
這意味著如果您將控制元件構建為 32 位或 AnyCPU,它應該可以解決設計時加載問題。
Visual Studio 2022 版本 17.0.0的發行說明指出“devenv.exe 現在僅為 64 位”。我自己沒有嘗試過,但這可能意味著您現在可以在設計時使用 64 位控制元件與較新版本的 VS。
在所有情況下,AnyCPU 都應該可以作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/379704.html
上一篇:如何從未指定的物件中獲取屬性?
