I have a single line text box, that is wide enough to hold 20 characters and I was wondering how do I make it so that you can keep typing even though it's got 20 characters in it without making it longer and without a vertical scrollbar? I'm sure it's not that hard, but I've been trying for a while and I still can't get it.

Dani AI

Generated

was right to point at the edit-control style that enables horizontal scrolling. For a single-line EDIT control the usual approach is to give it the auto-hscroll behavior and make sure it is not a multi-line control — that lets the caret move and the text slide left as more characters are entered, with no vertical scrollbar shown.

If the control still stops accepting characters after 20, the cause is usually a character-limit, not the visible width. Dialog resource editors often expose a "Limit text" value, and code can set the limit at runtime. Two practical options:

HWND hEdit = CreateWindowEx(0, "EDIT", NULL,
    WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOHSCROLL,
    x, y, width, height, hWndParent, (HMENU)IDC_MYEDIT, hInstance, NULL);
SendMessage(hEdit, EM_SETLIMITTEXT, (WPARAM)1024, 0); // raise limit

If using MFC, call CEdit::SetLimitText. If the resource editor is used, enable "Auto HScroll" and remove or increase the limit there.

Notes and gotchas: ES_AUTOHSCROLL scrolls automatically and does not add a visible horizontal scrollbar; add WS_HSCROLL if a visible scrollbar is desired. Do not combine ES_AUTOHSCROLL with ES_MULTILINE unless a different behavior is intended. This addresses ’s original goal of allowing continued typing beyond the 20-character visible width without resizing or showing vertical scrollbars.

Recommended Answers

All 2 Replies

When creating an "EDIT" window there are several flags associated all begining with ES_. The one you want to use is ES_AUTOHSCROLL in dwStyle.

Thanks

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.