Announcement

Collapse
No announcement yet.

Scrollable Label?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Scrollable Label?

    Hey David,

    Is it possible to scroll through a label object? Basically I would users to scroll through the text assigned to a label if the data becomes too long to display(Like the Listbox objects) in my plug-in.

    I guess that I could figure out how many lines I can fit in the label and then load parts of the string as the down/up arrow is pressed.

    I noticed that there is the following in the SDK; I just haven't seen it used in the sample code:

    CFControls.skinLabel
    needScroll - Label need scrolling flag (Field)

    Just wanted to see if you might have a recommendation for this.

  • #2
    Any thoughts?

    Comment


    • #3
      needScroll is a flag you can set to use if you want too... Labels can be created to scroll, but it would have to be programming in on the plugin side currently...

      it's not that hard to get a temp variable and scroll the lables you need to scroll, pulling off the text and invalidating the lable area...

      david
      __________________
      CENTRAFUSE http://www.centrafuse.com
      01 Jeep Cherokee Sport 4x4 Installed
      M10000/512Mb/20GB, Lilliput 7", Holux GM-210

      Comment


      • #4
        Originally posted by veetid View Post
        needScroll is a flag you can set to use if you want too... Labels can be created to scroll, but it would have to be programming in on the plugin side currently...

        it's not that hard to get a temp variable and scroll the lables you need to scroll, pulling off the text and invalidating the lable area...

        david
        Sorry to be a pain but I am not quite sure how to go about this...

        I would need to set some kind of limit based off of the label itself in order to determine when the string I am loading into the label is too long and has to be split.

        Which properties could I use to accomplish this?

        Comment


        • #5
          Originally posted by JWise1203 View Post
          Sorry to be a pain but I am not quite sure how to go about this...

          I would need to set some kind of limit based off of the label itself in order to determine when the string I am loading into the label is too long and has to be split.

          Which properties could I use to accomplish this?
          here you go:

          Code:
          string text = "new text for the label";
          CFControls.skinLabel temp = (CFControls.skinLabel)labelArray[CF_getLabelID("NAMEOFMYLABEL")];
          
          if(text != null)
          {
          		temp.Text = text;
          		temp.Draw = true;
          	
          		StringFormat sf = StringFormat.GenericDefault; 
          		sf.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
          
          		Graphics g = this.CreateGraphics();
          		int iWidth = (int)g.MeasureString(temp.Text, temp.Font, 0, sf).Width;
          
          		if(iWidth > temp.Bounds.Width)
          		{
          			//Do What you need to do because the text is too long
          		}
          		
          		g.Dispose();
          		labelArray[CF_getLabelID("MAINTITLE")] = temp;
          		this.Invalidate(new Rectangle(temp.Bounds.X, temp.Bounds.Y, temp.Bounds.Width, temp.Bounds.Height), false);
          }
          david
          __________________
          CENTRAFUSE http://www.centrafuse.com
          01 Jeep Cherokee Sport 4x4 Installed
          M10000/512Mb/20GB, Lilliput 7", Holux GM-210

          Comment


          • #6
            Originally posted by veetid View Post
            here you go:

            Code:
            string text = "new text for the label";
            CFControls.skinLabel temp = (CFControls.skinLabel)labelArray[CF_getLabelID("NAMEOFMYLABEL")];
            
            if(text != null)
            {
            		temp.Text = text;
            		temp.Draw = true;
            	
            		StringFormat sf = StringFormat.GenericDefault; 
            		sf.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
            
            		Graphics g = this.CreateGraphics();
            		int iWidth = (int)g.MeasureString(temp.Text, temp.Font, 0, sf).Width;
            
            		if(iWidth > temp.Bounds.Width)
            		{
            			//Do What you need to do because the text is too long
            		}
            		
            		g.Dispose();
            		labelArray[CF_getLabelID("MAINTITLE")] = temp;
            		this.Invalidate(new Rectangle(temp.Bounds.X, temp.Bounds.Y, temp.Bounds.Width, temp.Bounds.Height), false);
            }
            david

            I put this code into my plug-in and am having issues with the code thinking the text is out of bounds, when it really isn't.

            I have attached an example of what I am trying to do.

            I am writing a plug-in for AOL Instant Messenger and I need the label to handle two things:

            1. Once the message text becomes to large, automatically scroll the label to show the most current text.

            2. Via the up and down buttons, allow the user to scroll the text in the label and read older text not currently displayed on the screen.


            Hopefully that is descriptive enough, I have tried to work with the example code, but haven't been able to get things working right.
            Attached Files

            Comment


            • #7
              It's as simple as storing the main string in a variable and only updating the labels text with what can fit...


              david
              __________________
              CENTRAFUSE http://www.centrafuse.com
              01 Jeep Cherokee Sport 4x4 Installed
              M10000/512Mb/20GB, Lilliput 7", Holux GM-210

              Comment


              • #8
                Originally posted by veetid View Post
                It's as simple as storing the main string in a variable and only updating the labels text with what can fit...


                david
                Yes, I guess what I was getting at in the last post was the code you posted was telling me the the main string would be out of bounds when in fact it had plenty of room to fit.

                I was wondering if the code you provided was for another use ... say for the main song title label scroll.

                Comment


                • #9
                  Originally posted by JWise1203 View Post
                  Yes, I guess what I was getting at in the last post was the code you posted was telling me the the main string would be out of bounds when in fact it had plenty of room to fit.

                  I was wondering if the code you provided was for another use ... say for the main song title label scroll.
                  It was, you just asked for an example of how to measure a string I thought... It was just an example, not code to copy/paste and use...

                  sorry for the misunderstanding...

                  I can help you write what you need after I get RC4 released...

                  david
                  __________________
                  CENTRAFUSE http://www.centrafuse.com
                  01 Jeep Cherokee Sport 4x4 Installed
                  M10000/512Mb/20GB, Lilliput 7", Holux GM-210

                  Comment


                  • #10
                    David, any chance that you could help me out with this, this weekend?

                    Comment


                    • #11
                      Originally posted by JWise1203 View Post
                      David, any chance that you could help me out with this, this weekend?
                      you just have a timer, check the length of the string compared to the length of the text field... truncate off a letter and update the label text in the timer...


                      there are probably a million examples of doing this style of thing on google, just need to apply to CFPlugin functions, which shouldn't be difficult..

                      I gave you the .NET code to measure a string with a specified font...

                      david
                      __________________
                      CENTRAFUSE http://www.centrafuse.com
                      01 Jeep Cherokee Sport 4x4 Installed
                      M10000/512Mb/20GB, Lilliput 7", Holux GM-210

                      Comment


                      • #12
                        Ok David,

                        I haven't gotten a chance to look at this till tonight ... I have gotten the out of bounds exception to work properly by modifying your sample code slightly.

                        Basically I needed to get the height or area and not just the width of the label rectangle, since I am concerned about the text going going out of bounds vertically.

                        Code:
                        string text = strMessage;
                        CFControls.skinLabel temp = (CFControls.skinLabel)labelArray[CF_getLabelID("MESSAGEWINDOW")];
                        
                        if(text != null)
                        {
                        	temp.Text = text;
                        	temp.Draw = true;
                        
                        	StringFormat sf = StringFormat.GenericDefault; 
                        	sf.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
                        
                        	Graphics g = this.CreateGraphics();
                        	int iWidth = (int)g.MeasureString(temp.Text, temp.Font, 0, sf).Width;
                        	int iHeight = (int)g.MeasureString(temp.Text, temp.Font, 0, sf).Height;
                        	int iArea = iWidth * iHeight;
                        
                        	if(iArea > (temp.Bounds.Width * temp.Bounds.Height))
                        	{
                        		//Do What you need to do because the text is too long
                        		System.Diagnostics.Trace.WriteLine("***************  Caught OOB!!!   *****************");
                        		System.Diagnostics.Trace.WriteLine("Text Area: " + iArea);
                        		System.Diagnostics.Trace.WriteLine("Rec Area: " + (temp.Bounds.Width * temp.Bounds.Height));
                        		System.Diagnostics.Trace.WriteLine("***************  Caught OOB!!!   *****************");
                        	}
                        
                        	g.Dispose();
                        	labelArray[CF_getLabelID("MAINTITLE")] = temp;
                        	this.Invalidate(new Rectangle(temp.Bounds.X, temp.Bounds.Y, temp.Bounds.Width, temp.Bounds.Height), false);
                        }

                        The label is only getting updated when a message is sent or received, not off of a timer.

                        Now that I have the code working which will fire when the text is out of bounds I have two issues left:

                        1. When the message text is out of bounds, only display the end of the message (sort of like the ScrollToCarret method for a textbox).

                        2. Provide the user the ability to scroll through the entire message by pressing up and down arrows.

                        My question to you is if this can be done through th exposed CF API?
                        Attached Files

                        Comment

                        Working...
                        X