Env.: WM6 / VS2008 / CF 3.5

Hi All,

I have this winform used to view info (not edit it). It contains a set of
labels and textboxes set in readonly mode.

The problem is that the focus is set automatically to first text box and the
caret is displayed. This is confusing to users because you think you can
type something in there. How can I get rid of this caret?

My dirty workaround is as such: ((Control)MyLabel).Focus();

-> Sets the focus to a label. It's dirty because Label hides Focus() (hence
the typecast). Which means I'm not supposed to use it. (BTW the compiler
emits a warning to remind me so).

Does anyone know of a more elegant/'legal' solution?

Note: Turning the textboxes into labels is not a good option here because
the form is sometimes used in 'view' mode and sometimes in 'edit' mode. And
I want to keep a single layout for both modes.

TIA,

Serge.

Re: get rid of focus by Armando

Armando
Fri May 09 08:55:38 CDT 2008

hi,

try put the focus on form (this.focus())

--
Armando Rocha
Mobile Developer

http://www.ifthensoftware.com
"Serge Wautier" <serge@wautier.nospam.net> escreveu na mensagem
news:eMvrcqdsIHA.4716@TK2MSFTNGP06.phx.gbl...
> Env.: WM6 / VS2008 / CF 3.5
>
> Hi All,
>
> I have this winform used to view info (not edit it). It contains a set of
> labels and textboxes set in readonly mode.
>
> The problem is that the focus is set automatically to first text box and
> the caret is displayed. This is confusing to users because you think you
> can type something in there. How can I get rid of this caret?
>
> My dirty workaround is as such: ((Control)MyLabel).Focus();
>
> -> Sets the focus to a label. It's dirty because Label hides Focus()
> (hence the typecast). Which means I'm not supposed to use it. (BTW the
> compiler emits a warning to remind me so).
>
> Does anyone know of a more elegant/'legal' solution?
>
> Note: Turning the textboxes into labels is not a good option here because
> the form is sometimes used in 'view' mode and sometimes in 'edit' mode.
> And I want to keep a single layout for both modes.
>
> TIA,
>
> Serge.


Re: get rid of focus by Armando

Armando
Fri May 09 09:10:36 CDT 2008

Hi,

focus on form dont work, but if you define textbox.enable = false; then
focus is not set.

--
Armando Rocha
Mobile Developer

http://www.ifthensoftware.com
"Armando Rocha" <armandorocha@ifthensoftware.com> escreveu na mensagem
news:89F374EA-E61F-4978-B930-F3BBB2EF0F1B@microsoft.com...
> hi,
>
> try put the focus on form (this.focus())
>
> --
> Armando Rocha
> Mobile Developer
>
> http://www.ifthensoftware.com
> "Serge Wautier" <serge@wautier.nospam.net> escreveu na mensagem
> news:eMvrcqdsIHA.4716@TK2MSFTNGP06.phx.gbl...
>> Env.: WM6 / VS2008 / CF 3.5
>>
>> Hi All,
>>
>> I have this winform used to view info (not edit it). It contains a set of
>> labels and textboxes set in readonly mode.
>>
>> The problem is that the focus is set automatically to first text box and
>> the caret is displayed. This is confusing to users because you think you
>> can type something in there. How can I get rid of this caret?
>>
>> My dirty workaround is as such: ((Control)MyLabel).Focus();
>>
>> -> Sets the focus to a label. It's dirty because Label hides Focus()
>> (hence the typecast). Which means I'm not supposed to use it. (BTW the
>> compiler emits a warning to remind me so).
>>
>> Does anyone know of a more elegant/'legal' solution?
>>
>> Note: Turning the textboxes into labels is not a good option here because
>> the form is sometimes used in 'view' mode and sometimes in 'edit' mode.
>> And I want to keep a single layout for both modes.
>>
>> TIA,
>>
>> Serge.
>


Re: get rid of focus by Arun

Arun
Fri May 09 12:59:51 CDT 2008

Hi Serge,

Set the textbox tabstop property to false.
this.textBox1.TabStop =3D false;

But still it will allow user to tap on the textbox to get the focus,
you can add gotfocus event and put the focus to form, soemthing like
this.
This is because, you cannot capture mouse events and click event on CF
textbox control.

private void textBox1_GotFocus(object sender, EventArgs e)
{
textBox1.TopLevelControl.Focus();
}

If you have multiple textboxes to do the same stuff, create a extended
textbox control and override the gotfocus.

public class TextBoxEx : TextBox
{

public TextBoxEx()
{
ReadOnly =3D true;
}

protected override void OnGotFocus(EventArgs e)
{
this.TopLevelControl.Focus();
base.OnGotFocus(e);
}

}

Hope this helps,
Cheers,
Arun

On May 9, 7:10=A0am, "Armando Rocha" <armandoro...@ifthensoftware.com>
wrote:
> Hi,
>
> focus on form dont work, but if you define textbox.enable =3D false; then
> focus is not set.
>
> --
> Armando Rocha
> Mobile Developer
>
> http://www.ifthensoftware.com
> "Armando Rocha" <armandoro...@ifthensoftware.com> escreveu na mensagemnews=
:89F374EA-E61F-4978-B930-F3BBB2EF0F1B@microsoft.com...
>
>
>
> > hi,
>
> > try put the focus on form (this.focus())
>
> > --
> > Armando Rocha
> > Mobile Developer
>
> >http://www.ifthensoftware.com
> > "Serge Wautier" <se...@wautier.nospam.net> escreveu na mensagem
> >news:eMvrcqdsIHA.4716@TK2MSFTNGP06.phx.gbl...
> >> Env.: WM6 / VS2008 / CF 3.5
>
> >> Hi All,
>
> >> I have this winform used to view info (not edit it). It contains a set =
of
> >> labels and textboxes set in readonly mode.
>
> >> The problem is that the focus is set automatically to first text box an=
d
> >> the caret is displayed. This is confusing to users because you think yo=
u
> >> can type something in there. How can I get rid of this caret?
>
> >> My dirty workaround is as such: ((Control)MyLabel).Focus();
>
> >> -> Sets the focus to a label. It's dirty because Label hides Focus()
> >> (hence the typecast). Which means I'm not supposed to use it. (BTW the
> >> compiler emits a warning to remind me so).
>
> >> Does anyone know of a more elegant/'legal' solution?
>
> >> Note: Turning the textboxes into labels is not a good option here becau=
se
> >> the form is sometimes used in 'view' mode and sometimes in 'edit' mode.=

> >> And I want to keep a single layout for both modes.
>
> >> TIA,
>
> >> Serge.- Hide quoted text -
>
> - Show quoted text -