I have 18 text boxes named 'txtmybox' with indexes set as 0 to 17.

To change the back color I currently use a for..next loop ie:

for x = 0 to 17
txtmybox(x).backcolor=red
next x


The question is - is there a quicker way to perform this task, ie change all boxes in one go?


thanks

Dani AI

Generated

As asked, changing BackColor for many textboxes can be done several ways. and are right that a programmatic pass is common, but there are faster options depending on whether the change is at design time or runtime.

Selecting multiple controls in the form designer is the quickest one‑time fix: open the form in the designer, multi‑select the textboxes (Ctrl/Shift click or drag a selection rectangle) and change the BackColor in the Properties window. That edits all selected controls at once but will overwrite any individual color customizations already set on those controls. For changes that must happen while the app runs, centralizing the appearance is cleaner than repeating per‑control edits: a custom TextBox subclass that sets a default BackColor, or a single helper routine (called on form load) that applies a theme to that form/container, keeps behavior consistent across forms.

Two practical notes not mentioned above: setting a parent container’s BackColor does not change the BackColor of TextBox controls (they draw their own background), so changing the container color won’t achieve this. Also, for bulk runtime updates on many controls, suspending layout/redraw during the change reduces flicker (use the container/form’s SuspendLayout/ResumeLayout or an equivalent). For 18 controls, performance is trivial; choice should be based on maintainability (designer selection for one‑offs, subclassing or a small centralized routine for repeated or themed changes).

Recommended Answers

All 3 Replies

that is the simplest way

As ChrisPadgham said..that is a simplest way.
This following is other way (But Still needed to use Looping):

For Each controlx In Form1.Controls
    If TypeOf controlx Is TextBox Then controlx.BackColor = vbRed
Next controlx

Thanks for the replies

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.