【发布时间】:2011-11-09 17:51:36
【问题描述】:
我正在使用 Visual Studio 2010 Ultimate,我尝试使用进度条和两个标签转换一些图像,但两个标签的文本都没有显示,程序只显示白色背景的标签。
附言标签背景颜色为“Control”(不透明)
我有两种形式,一种是“主”形式,一种是“ProgressDialog”形式
当我点击“保存”按钮时在主窗体中
//copy the filenames to a new array to sort them
string[] FileNames = openDialog.FileNames;
Array.Sort(FileNames);
//create an instance of my progress dialog
ProgressDialog progress = new ProgressDialog(this, 100/FileNames.Length);
progress.ShowProgress();
//save all the files in the array
for (int i = 0; i < FileNames.Length; i++)
{
//call the SaveImage method
SaveImage(FileNames[i], 597, 412, Fill);
//increase the progresbar and set the label text of the progress dialog to the filename
progress.Increase(FileNames[i]);
}
progress.Close();//close progress dialog and re-enable the main form
...这里是我的“ProgressDialog”表单的代码:
Bar:进度条的名称
注释:图片路径为文本的标签名称
private Form SenderForm;// the "Main" form
private int Step; //value to increase in the progress bar
public ProgressDialog(Form sender, int step)//constructor
{
InitializeComponent();
SenderForm = sender;
Step = step;
}
//disable cose button
private const int CP_NOCLOSE_BUTTON = 0x200;
protected override CreateParams CreateParams
{
get
{
CreateParams myCp = base.CreateParams;
myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
return myCp;
}
}
//re-enable the "Main" form
private void ProgressDialog_FormClosed(object sender, FormClosedEventArgs e)
{
SenderForm.Enabled = true;
SenderForm.Activate();//activate form
}
//increase the value of the progressbar
public void Increase( string comment=null, int step=0)
{
//if step is 0 -> use the Step of the constructor
if (step==0) step = Step;
//if the comment (the current file name) is != of null
if (comment!=null)
Comment.Text = comment;//use the comment of the parameter
//increase progressbar
Bar.Value += step;
}
//show "ProgrssDialog" form
public void ShowProgress()
{
this.Show();
SenderForm.Enabled = false;//disable the main form
}
【问题讨论】:
-
我可以自信地说,标签在 Visual Studio 2010 中工作得很好。因此,问题一定出在您的程序上。代码是什么样的?