drawing issue with modeless window

  • Thread starter Thread starter Nathan Smith
  • Start date Start date
N

Nathan Smith

I have a popup window created from a form that contains a progress bar and a
label field. The problem is while the progress bar updates fine, the label
field does not show up at all on the form.

I have tried a couple of different things, but nothing seems to make the
label field to show.

Any ideas?

Thanks.
 
No data binding. Here's what I'm doing...
[Sample start]
'create a progress window
Dim progDlg As New Banner
progDlg.TextBox1.Text = "Please Wait..."
'set the progress bar to start pos
progDlg.ProgBar.Increment(10)
progDlg.Show()
[Sample End]
 
Without actually seeing how you're communicating with the progress window
it's a bit difficult to make a reccomendation. To illustrate how I might
accomplish the same thing I have included a project in the text below my
signature.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

------------------------------------------------------
namespace Progresswindow

{

public class Form1 : Form

{

int progress = 0;

Timer t;

Progress dlg = new Progress();

public Form1()

{

InitializeComponent();

}

private void StartProgress()

{

progress=0;

t = new Timer();

t.Interval = 100;

t.Tick += new EventHandler(t_Tick);

t.Enabled = true;

dlg.ShowDialog();

}

void t_Tick(object sender, EventArgs e)

{

progress++;

if (progress < 101)

dlg.ProgressValue = progress;

else

{

t.Enabled = false;

t = null;

}

}

private void button1_Click(object sender, EventArgs e)

{

StartProgress();

}

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.IContainer components = null;

/// <summary>

/// Clean up any resources being used.

/// </summary>

/// <param name="disposing">true if managed resources should be disposed;
otherwise, false.</param>

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.button1 = new System.Windows.Forms.Button();

this.SuspendLayout();

//

// button1

//

this.button1.Location = new System.Drawing.Point(85, 111);

this.button1.Name = "button1";

this.button1.Size = new System.Drawing.Size(75, 23);

this.button1.TabIndex = 0;

this.button1.Text = "Start";

this.button1.UseVisualStyleBackColor = true;

this.button1.Click += new System.EventHandler(this.button1_Click);

//

// Form1

//

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize = new System.Drawing.Size(284, 264);

this.Controls.Add(this.button1);

this.Name = "Form1";

this.Text = "Form1";

this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.Button button1;

}

public class Progress : Form

{

int progress;


public int ProgressValue

{

get { return progress; }

set

{

if (value == 100)

{

this.Close();

}

else

{

progress = value;

this.progressBar1.Value = value;

this.label1.Text = value.ToString();

}

}

}


public Progress()

{

InitializeComponent();

}

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.IContainer components = null;

/// <summary>

/// Clean up any resources being used.

/// </summary>

/// <param name="disposing">true if managed resources should be disposed;
otherwise, false.</param>

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.progressBar1 = new System.Windows.Forms.ProgressBar();

this.label1 = new System.Windows.Forms.Label();

this.SuspendLayout();

//

// progressBar1

//

this.progressBar1.Location = new System.Drawing.Point(12, 50);

this.progressBar1.Name = "progressBar1";

this.progressBar1.Size = new System.Drawing.Size(260, 23);

this.progressBar1.TabIndex = 0;

//

// label1

//

this.label1.Location = new System.Drawing.Point(12, 24);

this.label1.Name = "label1";

this.label1.Size = new System.Drawing.Size(260, 23);

this.label1.TabIndex = 1;

this.label1.Text = "label1";

this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

//

// Progress

//

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize = new System.Drawing.Size(284, 90);

this.Controls.Add(this.label1);

this.Controls.Add(this.progressBar1);

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;

this.MaximizeBox = false;

this.MinimizeBox = false;

this.Name = "Progress";

this.Text = "Progress";

this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.ProgressBar progressBar1;

private System.Windows.Forms.Label label1;

}

}





-------------------------------------------------------


Nathan Smith said:
No data binding. Here's what I'm doing...
[Sample start]
'create a progress window
Dim progDlg As New Banner
progDlg.TextBox1.Text = "Please Wait..."
'set the progress bar to start pos
progDlg.ProgBar.Increment(10)
progDlg.Show()
[Sample End]

Bob Powell said:
Are you using databinding?

Can you post some code...

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
It looks like you're using ShowDialog instead of Show to open the window. I
was under the assumption that I needed to use Show when opening modeless
dialogs and ShowDialog when opening modal dialogs - is this not the case?

All this dialog is for is to popup and give the user a message along with
progress of the current operation - there is no user input. When the
operation is finished the window is close by the app.

I am updating the progress bar using the progress bar Increment method. The
bar shows and works fine - it's just the label field that I put in the window
that doesn't show at all - even if that's the only field on the dialog.

Thanks for the help!
 
Ah, it's funny you should say that but I did the demo with Show first of all
and then decided that wasn't what you were describing.

Personally I would say that any popup progresss should really be modal so
that the user can be informed of the action taking place without insisting
that they do something at the same time. If you want tasks to carry on
asyncrounously then a progress bar in a status bar control is a far better
UI option.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Back
Top