Screentip Size

5 posts, 1 answers
  1. James
    James avatar
    23 posts
    Member since:
    Nov 2017

    Posted 24 Sep 2019 Link to this post

    I have a question about auto-sized screentips.

    I would like to measure the screentip before it is displayed and move its position above a control instead of beneath it. In order to move the screentip above a control, I need to know its height.

    My question is how can I get a screentip's height before it is displayed? I assume I need to invoke a method. However, everything method I have tried has not worked.(ie DesiredSize)

    Thanks in advance.

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4086 posts

    Posted 25 Sep 2019 Link to this post

    Hello, James,   

    You can handle the PropertyChanged event of RadOffice2007ScreenTipElement. If the PropertyName is "Bounds", this means that the size is updated according to the content that needs to be displayed. 

            public RadForm1()
            {
                InitializeComponent();
    
                this.radButton1.Text = "This is a very long text that needs more space to be displayed";
                this.radButton1.ScreenTipNeeded += radButton1_ScreenTipNeeded;
                screenTip.PropertyChanged += screenTip_PropertyChanged;
            }
    
            private void screenTip_PropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "Bounds")
                {
                    Console.WriteLine(screenTip.Size);
                }
            }
            
            RadOffice2007ScreenTipElement screenTip = new RadOffice2007ScreenTipElement();
    
            private void radButton1_ScreenTipNeeded(object sender, ScreenTipNeededEventArgs e)
            {
                RadButtonElement element = e.Item as RadButtonElement;
                if (e.Item != null)
                {
                    screenTip.CaptionLabel.Text = "Select Employee Name";
                    screenTip.MainTextLabel.Text = "Current: " + element.Text;
                    screenTip.FooterTextLabel.Text = "Thank you!";
                    screenTip.FooterVisible = true;
                    element.ScreenTip = screenTip;
                }
            }

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. James
    James avatar
    23 posts
    Member since:
    Nov 2017

    Posted 25 Sep 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thank you Dess.

    This helps. However, I still have an issue.

    After I get the size of the screentip in the PropertyChanged event, how would I offset the screentip in that method?

    Currently, I am offsetting the Screentip in the ScreenTipNeeded event using the e.Offset property (ScreenTipNeededEventArgs).The PropertyChanged event isn't raised until after the screentip is assigned to element.screentip.

    I cannot seem to locate a method or property to offset the screentip other than the ScreenTipNeededEventArgs passed into the ScreenTipNeeded event.

  4. Answer
    Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4086 posts

    Posted 27 Sep 2019 Link to this post

     

    Hello, James,   

    Indeed, you will have the real screen tip size too late for setting the ScreenTipNeededEventArgs.Offset in the ScreenTipNeeded event. Note that the screen tip's size is calculated when you are going to show it. But the ScreenTipNeeded event has already been fired providing the necessary information for the screen tip. 
    Before setting the offset, you can force measuring the screen tip and thus you will know its size. Please refer to the following code snippet:

            public RadForm1()
            {
                InitializeComponent();
    
                this.radButton1.Text = "This is a very long text that needs more space to be displayed" + Environment.NewLine + "second " + Environment.NewLine + "third";
                this.radButton1.ScreenTipNeeded += radButton1_ScreenTipNeeded;
            }
    
            RadOffice2007ScreenTipElement screenTip = new RadOffice2007ScreenTipElement();
    
            private void radButton1_ScreenTipNeeded(object sender, ScreenTipNeededEventArgs e)
            {
                RadButtonElement element = e.Item as RadButtonElement;
                if (e.Item != null)
                {
                    screenTip.MainTextLabel.Font = new System.Drawing.Font("Arial", 16f, FontStyle.Bold);
                    screenTip.CaptionLabel.Text = "Select Employee Name";
                    screenTip.MainTextLabel.Text = "Current: " + element.Text;
                    screenTip.FooterTextLabel.Text = "Thank you!";
                    screenTip.FooterVisible = true;
                    element.ScreenTip = screenTip;
    
                    SizeF f = MeasurementControl.ThreadInstance.GetDesiredSize(screenTip, new SizeF(1000, 1000));
                    e.Offset = new System.Drawing.Size(0, (int)-f.Height);
                }
            }

    Should you have further questions please let me know.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. James
    James avatar
    23 posts
    Member since:
    Nov 2017

    Posted 09 Oct 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thank you Dess!

     

    Your last reply was exactly what I was looking for and it works.

     

Back to Top