Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Compact Framework / May 2008

Tip: Looking for answers? Try searching our database.

get rid of focus

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Serge Wautier - 09 May 2008 14:42 GMT
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.
Armando Rocha - 09 May 2008 14:55 GMT
hi,

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

Signature

Armando Rocha
Mobile Developer

http://www.ifthensoftware.com

> Env.: WM6 / VS2008 / CF 3.5
>
[quoted text clipped - 22 lines]
>
> Serge.
Armando Rocha - 09 May 2008 15:10 GMT
Hi,

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

Signature

Armando Rocha
Mobile Developer

http://www.ifthensoftware.com

> hi,
>
[quoted text clipped - 26 lines]
>>
>> Serge.
Arun - 09 May 2008 18:59 GMT
Hi Serge,

Set the textbox tabstop property to false.
this.textBox1.TabStop = 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 = true;
       }

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

   }

Hope this helps,
Cheers,
Arun

On May 9, 7:10 am, "Armando Rocha" <armandoro...@ifthensoftware.com>
wrote:
> Hi,
>
[quoted text clipped - 44 lines]
>
> - Show quoted text -

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.