Alex-MyRpg

Hi - quick question here: what's the difference between Control.Focus and Control.Select (is there any or are there just two different methods on some controls for readability purposes e.g. you "select" a textbox when you want to input text rather than "focus" it ). If someone could clarify the difference and/or an example of where to use each, that'd be great. Thanks in advance!

Re: Windows Forms General Control.Focus & Control.Select

nobugz

A container like a form has an ActiveControl. That's the control that gets the focus when the form gets the focus. Select() just makes a control the ActiveControl. Focus() gives it the focus *and* makes it the active control if that worked. That's why Select works in the form's Load event but Focus doesn't; the form isn't yet visible.





Re: Windows Forms General Control.Focus & Control.Select

Alex-MyRpg

Thanks for the quick answer, again. However, I must disagree in saying Select() just makes it the ActiveControl - it clearly does give focus to the control, because I can type in it where I couldn't before I made the call to Select(). Could you please define what you mean by "focus" and/or where *you* would use each call: Select() and Focus(). This is a very poorly understood part of .NET, since there is no documentation on it... - thanks!




Re: Windows Forms General Control.Focus & Control.Select

nobugz

Select() will not give the control the focus if the container doesn't have the focus or is not visible. Focus() will give the container the focus but only if that is possible (i.e. not disabled and not invisible). You'd normally use Focus() but should use Select() when Focus() can fail. For example, in the Load event (form is not visible) or when a modal dialog is shown (other forms are disabled). Use Control.CanFocus in case of doubt.





Re: Windows Forms General Control.Focus & Control.Select

Alex-MyRpg

Aha! All is clear now... :) Except I think Select() would be more appropriate usually since you only really need Focus() when something is not in the foreground, right




Re: Windows Forms General Control.Focus & Control.Select

nobugz

Right.