'form initialization subroutine StatusStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {toolStripStatusLabel1}) StatusStrip1.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.HorizontalStackWithOverflow StatusStrip1.Location = New System.Drawing.Point(0, 0) StatusStrip1.Name = "statusStrip1" StatusStrip1.ShowItemToolTips = True StatusStrip1.Size = New System.Drawing.Size(292, 22) StatusStrip1.Text = "statusStrip1" toolStripStatusLabel1.Name = "toolStripStatusLabel1" toolStripStatusLabel1.Size = New System.Drawing.Size(109, 17) toolStripStatusLabel1.Text = "toolStripStatusLabel1" StatusStrip1.Visible = False 'processing code Try StatusStrip1.Visible = True toolStripStatusLabel1.Text = "Starting" StatusStrip1.Refresh() 'more code toolStripStatusLabel1.Text = "Processing layer " & pLayer.Name StatusStrip1.Refresh() 'more code Catch ex As Exception System.Windows.Forms.MessageBox.Show(ex.ToString, "Run") Finally StatusStrip1.Visible = False 'Make it invisible when finished or in case the process crashes early End Try
Windows.Forms.Cursor.Current = Windows.Forms.Cursors.WaitCursor
I have found the IMouseCursor to behave strangely so tend to avoid it. I think each time your code calls external methods then you need to call .SetCursor() again.Have you looked into using IProgressDialog? You can use it with a step progressor bar if you know how many iterations the process will take. If you don't know then hide the step progressor as shown below: //CREATE OBJECT TO ALLOW USER TO CANCEL ITrackCancel trackCancel = new CancelTrackerClass(); trackCancel.CancelOnClick = true; trackCancel.CancelOnKeyPress = true; //CREATE A PROGRESS DIALOG IProgressDialogFactory progDialogFact = new ProgressDialogFactoryClass(); IStepProgressor stepProg = progDialogFact.Create(trackCancel, Handle.ToInt32()); IProgressDialog2 progDialog = (IProgressDialog2)stepProg; progDialog.CancelEnabled = true; progDialog.Description = "Querying database..."; progDialog.Title = "Progress Dialog Title Here"; progDialog.Animation = esriProgressAnimationTypes.esriProgressGlobe; stepProg.Message = "Click below to Cancel..."; stepProg.Hide();Don't forget to close the dialog in your Finally block:progDialog.HideDialog();This progess dialog will not be embeded in your form but pop up in front. However, I have found it to be the most reliable way to show the user that lengthy background processes are occuring. For shorter processes where a WinForm remains open you may just want to set the Windows cursor to a wait one.
//CREATE OBJECT TO ALLOW USER TO CANCEL ITrackCancel trackCancel = new CancelTrackerClass(); trackCancel.CancelOnClick = true; trackCancel.CancelOnKeyPress = true; //CREATE A PROGRESS DIALOG IProgressDialogFactory progDialogFact = new ProgressDialogFactoryClass(); IStepProgressor stepProg = progDialogFact.Create(trackCancel, Handle.ToInt32()); IProgressDialog2 progDialog = (IProgressDialog2)stepProg; progDialog.CancelEnabled = true; progDialog.Description = "Querying database..."; progDialog.Title = "Progress Dialog Title Here"; progDialog.Animation = esriProgressAnimationTypes.esriProgressGlobe; stepProg.Message = "Click below to Cancel..."; stepProg.Hide();
progDialog.HideDialog();
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.