0

I am implementing a QWERTY-style keyboard on a cheap touchscreen PC running (similar to a bank ATM). The Panel container has several dozen buttons and when the user presses "Shift", I swap all the text on the buttons. For example, btnPos12.Text = (m_bShiftOn) ? "Q" : "q"; in a big loop for all buttons on the Panel.

This works fine, but because the processor is not very powerful, there is significant flicker as all the button text changes. I'd like to suspend all text updates till they've all been done and then...bang!...change them all (aka double-buffering). I tried using this thread: How do I suspend painting for a control and its children?

This works very well for single controls, such as a multi-line TextBox, but does not prevent each button's text from updating.

I then tried changing the text on a single button. First I suspended drawing on that button, and then changed the text in a big loop...but again the text changes each time btnPosXX.Text = ... is called. Is there any way to prevent changes to the "Text" property of a control?

int nShiftIndex = (m_bShiftOn) ? UPPER : LOWER;
for (int nButton = 0; nButton < pnlButtons.Controls.Count; nButton++)
{
    pnlButtons.Controls[nButton].Text = m_aszKeys[nShiftIndex];
} 
Community
  • 1
  • 1
AlainD
  • 5,413
  • 6
  • 45
  • 99
  • 1
    Adding your actual code will help in getting an answer. – Steve Mitcham Feb 20 '15 at 16:54
  • 1
    Have a look at this question / answer. http://stackoverflow.com/questions/615781/can-i-suspend-redrawing-of-a-form-until-i-have-performed-all-updates – jac Feb 20 '15 at 16:59
  • @AlainD, see jac's edit to your question, you can just keep editing your question to add code details. Also, look at his suggested link and also if you could add where you are attempting to suspend/resume the updates. – Steve Mitcham Feb 20 '15 at 17:09
  • @SteveMitcham: Thanks. Actually, the question has all the details, but I think you're hinting that coders (like myself) prefer to see a succinct code sample rather than something more wordy (and potentially ambiguous)! Point taken, I'll work on that... – AlainD Feb 20 '15 at 17:12
  • If you look here: http://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/Control.cs,f12a8fdec6c1bb36 the button text is set via the low-level SetWindowText function in the win32 api. I'll have to wait for a bit until I can get to a machine I can develop winforms on to try and work something out. – Steve Mitcham Feb 20 '15 at 17:17
  • Yes, code examples of a specific reproducible problem are preferred for SO. – Steve Mitcham Feb 20 '15 at 17:18
  • thinking outside the box...can you have a separate set of buttons in the same location, and just change visibility en mass? pausing the layout when changing visibility may look better visually. – Jeremy Feb 20 '15 at 18:37

1 Answers1

0
this.SuspendLayout();

  ...

this.ResumeLayout();
Steve Mitcham
  • 5,268
  • 1
  • 28
  • 56
Jeremy
  • 4,808
  • 2
  • 21
  • 24
  • 1
    That doesn't work. SuspendLayout just stops the layout logic for the control, but doesn't appear to affect the Text property for the control. – AlainD Feb 20 '15 at 17:04
  • Did you try it at the form level before setting any properties? It should stop updating all controls that belong to the form if I'm not mistaken. – Jeremy Feb 20 '15 at 17:53
  • Just tried it, but it doesn't help. SuspendLayout doesn't appear to affect the Text property of a control, only layout logic. – AlainD Feb 20 '15 at 18:02
  • How about BeginUpdate and EndUpdate? – Jeremy Feb 20 '15 at 18:03
  • BeginUpdate / EndUpdate are supported on some classes (eg. ComboBox) but not on the Panel or Form classes. – AlainD Feb 20 '15 at 18:12
  • one more thing. I noticed the autogenerated designer code does this.ResumeLayout(False) this.PerformLayout() – Jeremy Feb 20 '15 at 18:25