怎样显示带进度条的模式对话框

lengq 2010-09-13 04:31:00
我想做一个带进度条的模式对话框,
就是对话框里面含有个进度条,进度条的蓝色小方块从左至右填充,满格以后清空进度条,再填充,如此反复。

这种对话框应该没有直接可以用的,类似FileDialog。
哪位可以帮忙做一个啊,谢谢啦。
...全文
256 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lengq 2010-09-15
  • 打赏
  • 举报
回复
我现在的情况时需要在母体窗口上表示一个类似DialogBox的窗体,里面加载一个进度条,用来忙指示。
母体窗口的后台程序继续运行,运行完了后,再关闭DialogBox窗体。

是不是需要在打开DialogBox窗体前新建一个线程啊?

另外DialogBox窗体怎么做啊?(关键是不要放大,缩小,关闭这三个按钮)
xzjxylophone 2010-09-14
  • 打赏
  • 举报
回复
在 sunpire 大神, jv9大神 等SL板块的其他大神的帮助下目前我用的 带进度条的模式对话框,
希望对你有帮助:

调用模式进度条对话框:

W_PBarSuper win = new W_PBarSuper(string.Format("正在读取文件:{0}……", tempATCFile.FileName), ProcessBarCategory.OpenPhoneFile, _param);
try
{

win.Owner = this._parentWindow;
win.WindowStartupLocation = WindowStartupLocation.CenterOwner;
win.ShowDialog();

}


模式进度条对话框:

private ProcessBarCategory _currentProcessBarCategory = ProcessBarCategory.OpenPhoneFile;

private object[] _param = null;
public W_PBarSuper(string des, ProcessBarCategory enumOP, object[] param)
{
InitializeComponent();
this.lbl_Des.Content = des;
this._currentProcessBarCategory = enumOP;
this._param = param;
this.OperateResult = false;
}


private void Window_Loaded(object sender, RoutedEventArgs e)
{

try
{
this.start();
}
catch(Exception ex)
{
Log.LogRecord(ex.ToString());
}

}




#region 进度条相关,主要是实现接口:INotifyPropertyChanged
/// <summary>
/// 记录百分比
/// </summary>
public double percent = 0;
private double finished;
/// <summary>
/// 记录获取信息时候完成度
/// </summary>
public double Finished
{
get
{
return this.finished;
}
set
{
this.finished = value;
NotifyPropertyChanged("Finished");

}
}

private string _detailDescription;
/// <summary>
/// 记录获取信息时候需要提示的文字
/// </summary>
public string DetailDescription
{
get
{
return this._detailDescription;
}
set
{
this._detailDescription = value;
NotifyPropertyChanged("DetailDescription");
}
}

public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}

#endregion

private void RegisterEventThis()
{
this.PropertyChanged -= new PropertyChangedEventHandler(this.This_PropertyChanged);
this.PropertyChanged += new PropertyChangedEventHandler(this.This_PropertyChanged);
}
void This_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{

if (e.PropertyName == "Finished")
{
//this.pb_Main.Value = this._currentMTKPhone.Finished;
this.pb_Main.Dispatcher.Invoke(new Action<DependencyProperty, object>(this.pb_Main.SetValue), DispatcherPriority.Background, ProgressBar.ValueProperty, this.Finished);

//Thread initThread = new Thread(new ParameterizedThreadStart(this.InitInformation2));

//initThread.Start(this._currentMTKPhone.Finished);

}
else if (e.PropertyName == "DetailDescription")
{
//this.lbl_DesDetail.Content = this._currentMTKPhone.DetailDescription;
this.lbl_DesDetail.Dispatcher.Invoke(new Action<DependencyProperty, object>(this.lbl_DesDetail.SetValue), DispatcherPriority.Background, Label.ContentProperty, this.DetailDescription);

}
//this.Dispatcher.Invoke(new UpdateUIDelegate(this.UpdateUI), new object[] { this._currentMTKPhone.Finished, this._currentMTKPhone.DetailDescription });
}


private System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();

//轮循执行要执行的业务逻辑
void Refersh(object sender, EventArgs e)
{
try
{

this.StartThread();

}
catch(Exception ex)
{
//throw ex;
}
finally
{
this.stop();
this.Close();
}
}


private void StartThread()
{
switch (this._currentProcessBarCategory)
{
case ProcessBarCategory.OpenPhoneFile:
this.OpenPhoneFile(this._param[0] as ATCFile);
break;
case ProcessBarCategory.WritePhoneFile:
this.WritePhoneFile(this._param[0] as string, this._param[1] as string);
break;
default:
break;
}
}

public void start()
{
timer.Tick += Refersh;
timer.Interval = new TimeSpan(0, 0, 1);
timer.Start();
}
public void stop()
{
timer.Stop();
timer.Tick -= Refersh;
}


public bool OpenPhoneFile(ATCFile atc)
{

this.RegisterEventThis();

try
{

string phoneFullFileName = atc.FullFileName;
if (!Directory.Exists(ConstString.ATCFileTemp))
{
Directory.CreateDirectory(ConstString.ATCFileTemp);
}
string pcFullFileName = System.IO.Path.Combine(ConstString.ATCFileTemp, atc.FileName);
//fileName
if (System.IO.File.Exists(pcFullFileName))
{
System.IO.File.Delete(pcFullFileName);
}



//逻辑函数中更新你的Finished和DetailDescription

byte[] array = DataConvert.HexToByte(result);
System.IO.FileStream fs = new System.IO.FileStream(pcFullFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
fs.Write(array, 0, array.Length);
fs.Close();
this.OperateResult = true;
}
catch (Exception ex)
{
this.OperateResult = false;
throw ex;
}
finally
{

}
return true;


}


不足之处 请指正。。。。
jv9 2010-09-14
  • 打赏
  • 举报
回复
楼主的意思是想使用实现载入提示busy的效果么?可以使用BusyIndicator。

而,如果想实现,步骤化进度条,可以使用ProgressBar控件。可以将ChildWindow制作为DialogBox效果承载该控件。
Sunpire 2010-09-14
  • 打赏
  • 举报
回复
在WPF中就只能使用 ProgressBar 了,没有现成的 BusyIndicator 控件。

以前有帮助 4楼的朋友解决过在 WPF 中使用进度条的问题,一个完整的尝试及摸索的过程:
http://topic.csdn.net/u/20100725/16/d202194c-60d3-4f6f-bbff-2519df081844.html

有二种方法可以总结一下:
方法一、 按照使用WinForm实现进度条的方法,通过事件来驱动进度条的进度变化,
并且在事件处理方法中要注意跨线程访问控件的问题。

不过方法一在 Silverlight 和 WPF 中并不是最好的方法,最好的方法是
方法二、 将进度条的 Value 属性绑定至 后台Model的一个用于表示进度的依赖项属性,
很自然的就能把 Model的进度显示在前台的ProgressBar 上了。
lengq 2010-09-14
  • 打赏
  • 举报
回复
呵呵,怎么插入本地图片阿
lengq 2010-09-14
  • 打赏
  • 举报
回复
这种效果
lengq 2010-09-14
  • 打赏
  • 举报
回复
我是想实现载入提示busy的效果么,能说说BusyIndicator具体怎么用么?
我是用VS2008开发的WPF项目。

谢谢了
lengq 2010-09-13
  • 打赏
  • 举报
回复
ProgressBar是个控件啊,怎么才能在DialogBox里表示出来呢?
还是必须自己画form
Sunpire 2010-09-13
  • 打赏
  • 举报
回复
有这样的控件,
System.Windows.Controls.ProgressBar
在程序集 System.Windows.dll

8,735

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧