How to set Caption in Label

General discussion on Visual TFT Software.
Post Reply
Author
Message
dhineshr
Posts: 11
Joined: 26 Jan 2015 15:43
Location: Bangalore
Contact:

How to set Caption in Label

#1 Post by dhineshr » 26 Jan 2015 16:03

I have designed a screen to set date and time, The design consists of 5 Labels(Date,Time), 5 Boxes(Highlight Date and Time), and 6 Buttons (4 Navigation, OK, Cancel). Left and Right Navigation's are used to highlight the Date/Time. The top and down buttons are used for increment/decrement the numbers (Day,Month,Year,Hour,Min).
Screenshot
Screenshot
date.JPG (40.74 KiB) Viewed 4693 times
Initially I am setting default date and time in their respective labels. When the particular Label is highlighted, the increment/decrement should work based on the label. For example, If I Highlight the Hour Label, the up/down button is used to increment/decrement the Value by changing the Label_Caption. I was trying the below code which is not changing the Label_Caption.

Code: Select all

void B_DATE_UPOnClick() 
{
if (Box1.Visible == 1)
{
   if ( 0 < dd )
   {
      if( dd < 31)
      {
      dd++;
      c = (char)(dd);
      strcpy(Label4_Caption, c);
      DrawLabel(&Label4);
      }
   }
}
}
The above code is the Click event of
Up button
Box1
denotes the Yellow box Highlighted on Date
dd
denotes the Date (1-31)
c
is the character
Label4
is the label where caption should be changed when clicking Up button.

When this event is triggered I not getting any changes
Dhinesh Radhakrishnan,
New to Embedded.
http://www.mcsyssoft.com

dibor
Posts: 208
Joined: 29 Dec 2014 18:59

Re: How to set Caption in Label

#2 Post by dibor » 27 Jan 2015 10:37

Hi
Try strcpy(Label4.Caption, c); (instead strcpy(Label4_Caption, c);)

And I think variable "c" mast be array (like c[2])

Regards.

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: How to set Caption in Label

#3 Post by marina.petrovic » 27 Jan 2015 14:57

Hi,

Like dibor already mentioned, please, try to use strcpy() routine like:

Code: Select all

strcpy(Label4.Caption, c);
Also, please, take a look at this forum topics:
http://www.mikroe.com/forum/viewtopic.php?f=160&t=56933
http://www.mikroe.com/forum/viewtopic.php?f=164&t=56040

Pay attention, after you make changes to label (or button) component properties, in order to update the display of the label you need to call DrawLabel() function.
Also, make sure that you clean the old value first.
You can simple draw rectangle colored in background color, or you can draw label with background color,
change back the font color to label color, update the caption property and then call DrawLabel function.

Best regards,
Marina

Megahurts
Posts: 900
Joined: 01 Oct 2009 22:48
Location: Rocky Mountains, USA.

Re: How to set Caption in Label

#4 Post by Megahurts » 29 Jan 2015 11:51

Hi,

Just a couple of quick additions to the suggestions posted also:
Make sure the Label object's "Static" property is set to "False" in V-TFT also, otherwise you can not change the Labels Caption property.

You could also use Button components (with "Static" @ False) instead of labels and just change the fill color properties to indicate when they are selected for adjusting their values.
This method eliminates the need to first clear the old value displayed before changing their Caption property with the new value when an adjustment button has been pressed.
Redrawing the Button(s) after any changes to their properties is always required.

Hope this helps also, Robert.
HW: easyPIC5|PICFlash2|easyBT|smartGSM|easyGSM|PICPLC16|mmWorkStation|FT800 Eve|PIC Clicker/2|
MMBs:PIC18F,PIC33EP,PIC32|CLICKs:DAC,ADC,GPS L10,Thermo,8x8B LED,Stepper,W/B OLED,9DOF,GPS3,tRF,Hall I|

SW: mP for PIC|mB for PIC-dsPIC-PIC32|Visual-TFT|

dhineshr
Posts: 11
Joined: 26 Jan 2015 15:43
Location: Bangalore
Contact:

Re: How to set Caption in Label

#5 Post by dhineshr » 06 Feb 2015 14:48

Thanks for all your suggestions, Like you said, it is working fine. But I got an issue,

For Clearing the Label, I use the following Code on the Click Event,

Click Event

Code: Select all

strcpy(Label4_Caption, ch);
Clear_Label4();
DrawLabel(&Label4);
Clear_Label Function

Code: Select all

void Clear_Label4() 
{
    unsigned saved_color;
    saved_color = Label4.Font_Color;
    Label4.Font_Color = Box1.Color;
    DrawLabel(&Label4);
    Label4.Font_Color = saved_color;
}
Here the problem is whenever I increment, The Text is displayed as overwritten on old caption. I was doing to draw the screen every time I change the Caption causing the screen to load each time. Is there any other solution to overcome this?
Dhinesh Radhakrishnan,
New to Embedded.
http://www.mcsyssoft.com

vt23
Posts: 44
Joined: 17 Jun 2014 10:36

Re: How to set Caption in Label

#6 Post by vt23 » 21 Aug 2015 13:05

Hello,
this is maybe late answer. But simple.
Click Event should be:

Code: Select all

Clear_Label4();
strcpy(Label4_Caption, ch);
DrawLabel(&Label4);
Vitek

Post Reply

Return to “Visual TFT General”