C# Can';t使用自定义用户控件保存表单
在我创建一个userControl并在Windows窗体中建立它之后,这个窗体就不能再保存了。当我按下Ctrl+S或“保存”按钮时,什么也没有发生,表单文件名上的小*表示它没有保存。另外,我的表单包含颜色的属性。当我更改此选项时,颜色不会更改,属性窗口似乎不再响应 自定义用户控件的代码C# Can';t使用自定义用户控件保存表单,c#,windows,forms,save,element,C#,Windows,Forms,Save,Element,在我创建一个userControl并在Windows窗体中建立它之后,这个窗体就不能再保存了。当我按下Ctrl+S或“保存”按钮时,什么也没有发生,表单文件名上的小*表示它没有保存。另外,我的表单包含颜色的属性。当我更改此选项时,颜色不会更改,属性窗口似乎不再响应 自定义用户控件的代码 namespace FlowGui { public partial class FlowProgressBar: UserControl { // Public Variab
namespace FlowGui
{
public partial class FlowProgressBar: UserControl
{
// Public Variables with Setters
private int maxValue;
[Bindable(true), Category("Behavior")]
public int Maximum
{
get
{
return maxValue;
}
set
{
maxValue = value;
DrawBar();
}
}
private int minValue;
[Bindable(true), Category("Behavior")]
public int Minimum
{
get
{
return minValue;
}
set
{
minValue = value;
DrawBar();
}
}
private int currentValue;
[Bindable(true), Category("Behavior")]
public int Value
{
get
{
return currentValue;
}
set
{
currentValue = value;
DrawBar();
}
}
private Color barColor;
[Bindable(true), Category("Appearance")]
public Color BarColor
{
get
{
return barColor;
}
set
{
barColor = value;
CreateBarImage();
DrawBar();
}
}
// private Values for Drawing
private Image canvas;
private Graphics gfx;
private Bitmap barImage;
public FlowProgressBar()
{
InitializeComponent();
}
// Load
private void FlowProgressBar_Load(object sender, EventArgs e)
{
maxValue = 100;
minValue = 0;
currentValue = 0;
barColor = Color.LightBlue;
// Init Graphic
InitGraphics();
CreateBarImage();
DrawBar();
}
private void CreateBarImage()
{
barImage = new Bitmap(10, 50);
Bitmap currentBarImage = Properties.Resources.BarImage_Basic;
for(int x=0; x<10; x++)
{
for (int y = 0; y < 50; y++)
{
Color barPreColor = currentBarImage.GetPixel(x, y);
int r = barPreColor.R * barColor.R / 255;
int g = barPreColor.G * barColor.G / 255;
int b = barPreColor.B * barColor.B / 255;
Color pixelColor = Color.FromArgb(r,g,b);
currentBarImage.SetPixel(x, y, pixelColor);
}
}
}
private void InitGraphics()
{
canvas = new Bitmap(pictureBoxBar.Width, pictureBoxBar.Height);
gfx = Graphics.FromImage(canvas);
}
private void DrawBar()
{
int barWidth = pictureBoxBar.Width;
int barHeight = pictureBoxBar.Height;
Image bgImage = Properties.Resources.BarBG_Raised_Grey;
gfx.DrawImage(bgImage,-200,0,barWidth+400,barHeight);
gfx.DrawImage(barImage, 0, 0, 100, barHeight);
pictureBoxBar.Image = canvas;
}
// Behaviour
private void FlowProgressBar_SizeChanged(object sender, EventArgs e)
{
InitGraphics();
DrawBar();
}
private void pictureBoxBar_Paint(object sender, PaintEventArgs e)
{
InitGraphics();
DrawBar();
}
}
}
名称空间流GUI
{
公共部分类FlowProgressBar:UserControl
{
//带有setter的公共变量
私有整数最大值;
[可绑定(真实)、类别(“行为”)]
公共整数最大值
{
得到
{
返回最大值;
}
设置
{
最大值=最大值;
牵引杆();
}
}
私人价值;
[可绑定(真实)、类别(“行为”)]
公共整数最小值
{
得到
{
返回最小值;
}
设置
{
最小值=最小值;
牵引杆();
}
}
私有值;
[可绑定(真实)、类别(“行为”)]
公共整数值
{
得到
{
返回当前值;
}
设置
{
当前值=当前值;
牵引杆();
}
}
私人色彩;
[可绑定(真实)、类别(“外观”)]
公共颜色
{
得到
{
返回原色;
}
设置
{
barColor=值;
CreateBarImage();
牵引杆();
}
}
//绘图的私有值
私有图像画布;
专用图形gfx;
私人位图图像;
公共FlowProgressBar()
{
初始化组件();
}
//装载
私有void FlowProgressBar_加载(对象发送方,事件参数e)
{
最大值=100;
最小值=0;
currentValue=0;
barColor=Color.LightBlue;
//初始图形
InitGraphics();
CreateBarImage();
牵引杆();
}
私有void CreateBarImage()
{
barImage=新位图(10,50);
位图currentBarImage=Properties.Resources.BarImage_Basic;
对于(int x=0;x
问题是pictureBoxBar_Paint()事件。我将其从用户控件中删除后,所有内容都会运行。解决了
问题是pictureBoxBar_Paint()事件。在我将其从userControl中删除后,一切都会运行