Hi--
I appreciate your interest.
I have put this code in the form's constructor to "Double Buffer" the form.
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint,true);
this.UpdateStyles();
I expected that this would paint the entire form to an off-screen image and
then push the complete image back to the screen. It had no noticeable
effect.
It appears that the different control types are being painted
sequentially -- first the form background, then the panels, then the
textboxes, labels, buttons, etc. It is this sequential painting that is
ugly-- the panel is repainted leaving the other controls on-screen filled
with the image of the covering form. I would rather live with a delay in
painting the entire image than watching the controls be sequentially
updated.
The answers to the specific questions posed are below along with an
annotated code snipet for the dialog call.
In my experience , a form with 20 textboxes only, should not have
repainting performace issue. Could you let me know if there is anything
special with your form and TextBoxes?
The Form has three main panels --
Left docked with buttons
Top Docked with labels and textboxes bound master table
Bottom panel with data grid bound to child table in same dataset.
To help narrow down this problem, I'd also like to know if the slow
repainting of the mainform only occurres on the pop-up form closing? will
the repainting become slow if you drag the pop-up form over and off the
mainform, instead of closing the pop-up?
If I drag the dialog off the screen, I see the same blink that I see if
Iclose it.
If the slow painting is only occurred in closing the popup form, I'd like
to take a look at the code snippet related to the pop-up form handling.
private void btnOpen_Click(object sender, System.EventArgs e)
{
try
{
// Show dialog to give user a chance to save changes
if (ds.HasChanges())
{
DialogResult rslt = MessageBox.Show("The current data has unsaved
changes.\n" +
"Do you want to continue?", "New Order",
MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if (rslt==DialogResult.No) return; // If No -- dialog clears and repaint is
acceptable.
}
// If Yes -- remnants of the dialog are displayed noticeably in the
textboxes and labels
// that it covers. The dialog is small & only covers 5 controls in its
default location.
// Without the following call to DoEvendt, even this small dialog gives ugly
results.
// The call to DoEvents takes care of it though.
Application.DoEvents();
// The following dialog is preloaded. Class1 holds a static reference
// so it does not have to instantiate each time it is called.
// (The dialog is 738 x 412 pixels in size; the main form is 800 x 600)
DlgSelectPurchaseOrders dlg = Class1.dlgPurchaseOrders;
DialogResult result = dlg.ShowDialog();
// Without the following call to DoEvents the screen appears to freeze
// for a (mental) count of 1-1/2 during which the textboxes & labels,
buttons etc.
// retain the image of the dialog.
// The call to DoEvents reduces the time the image is retained to a short,
// but still noticeable "blink'.
Application.DoEvents();
if(result == DialogResult.OK)
{
OpenOrder(int.Parse(dlg.SelectedPO));
}
}
catch (Exception ex)
{
MessageBox.Show("Failed to open order.\n" +
ex.Message , "Open Order" , MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnEditDetail_Click(object sender, System.EventArgs e)
{
try
{
DialogResult result = dlgDetail.ShowDialog();
}
catch(Exception ex)
{
MessageBox.Show("Failed to open detail editor.\n" +
ex.Message , "Edit Detail" , MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Thanks!
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.