locked
How to create clickable Label? RRS feed

  • Question

  • Hi All,

     

    Can any one please tell me how do I create Clickable and Focussable Label for Smartphone targetting .NET CF 1.0?

     

    Thanks in advance.

    Monday, April 28, 2008 7:53 AM

Answers

  • You can use LinkLabel control. Also there can be no clicks on SmartPhone platform since there’s nothing to click with.

    Tuesday, April 29, 2008 6:26 PM

All replies

  • Hi. I am programming for my Windows Mobile 6 phone - not a Smartphone - and use the form (or the label's container) mousedown event to compare the x and y of the mouse (stylus) click to the left,width,top and height of the label.

    I don't know if you have a stylus or not.

    As to a label receiving focus - they can't.

    I'm using vb.net 2005. Here is a procedure I wrote that accepts a lable reference, control reference, x and y and sets focus to the control - you could put anything inside the if statements.

    This is vb.net code

    Public Sub FocusControl(ByRef lblIn As Label, ByRef ctrl As Control, ByVal x As Integer, ByVal y As Integer)
            'use this from a mousedown event to get a click
            'typically from a label. It can be used for almost
            'anywhere on a form or displayable container

            If x >= lblIn.Left And x <= lblIn.Left + lblIn.Width Then
                If y >= lblIn.Top And y <= lblIn.Top + lblIn.Height Then
                    ctrl.Focus()
                End If
            End If
        End Sub

    you call this in a mousedown event -

    FocusControl(lblShiftDate, txtShiftDate, e.x, e.y)

    this worked when I was using .net 1.0 and stlll works in 2

    I hope this helps,

      Ricky


    Monday, April 28, 2008 9:21 AM
  • Hi frv4ever, thanx for reply.

     

    See, there there is no need of stylus. No stylus, no reading of X,Y coordinates. If we can focus a label, then the navigation keys of the Smartphone will do the trick. I was thinking of doing this by inheriting a label from ButtonBase or something like that. And that should perhaps provide the event handlers for Click and Focus (base.Click and base.GotFocus). But I am not getting how to do it. I am programming in C# 2005. If u have anything more to help, please send me, be it in VB.

     

    Thanx

    Monday, April 28, 2008 9:35 AM
  • The easiest way is to probably just create a class that inherits from 'UserControl'.  Then in the designer you can just drag a label on it, dock the label to the entire size of the control, then you can either just expose the label, or override the "Text" fields and such of the new control to get/set the text of the label.  Hopefully that helps.

     

    Tuesday, April 29, 2008 2:43 AM
  • Hi Steve

     

    Thanks for solution, but it did not work out that well as I expected. I am getting the error "Member not supported by device platform...........UserControl.add_Click is not supported method in this platform".

     

    Here the declaration of the class

    public partial class LabelButton : UserControl

     

    I even tried

     

    public partial class LabelButton : Control

    public partial class LabelButton : ButtonBase

     

    Any suggestions?

    Tuesday, April 29, 2008 7:39 AM
  • You can use LinkLabel control. Also there can be no clicks on SmartPhone platform since there’s nothing to click with.

    Tuesday, April 29, 2008 6:26 PM