[Q] How can you see if you can add text to a control?

P

Peter B

Hi!

Taking a randomly focused control on a form, how can you check to see if it
is a text-input control? I.e. a control that accepts input from the user.
What I want to do is add a text character to the control, but only if it can
hold text. For example if a button is focused, adding the char to this
controls Text-property would change the name of the button, which I don't
want...

1. What controls are "text-input" controls in CF?
Textbox, Combobox, NumericUpDown?, DomainUpDown?, more?

2. How can you determin if a control is of this type?
It must be done in the framework somewhere since typing a character in the
SIP when a button is focused won't change it's name, while doing the same
when a textbox is focused will add the character to the text...

3. Would it be the same in the full framework?

/ Peter
 
M

Marauderz

Off my head in VB.Net I'd do something like this

dim oControl as Control
for each oControl in me.Controls
if oControl is TypeOf(TextBox) then
'Do Textbox stuff
elseif -----
'and so on and so forth
end if
next

Should work....

But I think it'll take some work to get the currently focused control of a
form. =P
 
P

Peter B

Hi Marauderz!

Thanks for your help and ideas. The equivalent in C# is:
using System.Windows.Forms;

if( sender is TextBox || sender is ComboBox )
{
// bla bla
}

regards,

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top