This is a migrated thread and some comments may be shown as answers.

Desktop Alert Not Resizing Accordingly To the ContentText Set

8 Answers 360 Views
DesktopAlert
This is a migrated thread and some comments may be shown as answers.
Jenson
Top achievements
Rank 2
Jenson asked on 04 Jun 2012, 01:31 AM
Hi,

I would like to know whether anyone else is facing the same issue like mine.

I'm using RadDesktopAlert on Visual Studio 2008 (C#), and I never set any button to trigger the desktop alert. 

I'm calling it whenever I want to display the alert.

I leave the FixedSize value to its default 0, 0 (which should resize automatically according to the content text set.

However, I noticed that's not the case, they will always put in the text to fit the "fixed" size, after that, the remaining text exceeded the alert window size would be replaced with "..." at the bottom of the displayed text.

May I know whether this is a bug or some settings issue?

Thank you.

Regards,
Jenson

8 Answers, 1 is accepted

Sort by
0
Jenson
Top achievements
Rank 2
answered on 07 Jun 2012, 03:35 AM
Now I also noticed if I used <html> formatting in the ContentText, it will not display "..." for text exceeding the display window size, it would just not be displayed.

For example, this is the formatting I put for ContentText

strContent = "<html>Item for "
   + "<br>" + "Item Code: " + strRawMaterialCode
   + "<br>" + "Item Name: " + strRawMaterialName
   + ", has been deleted successfully. ";

Which I will pass to a private function ShowDesktopAlert(string, string);

private void ShowDesktopAlert(string strCaption, string strContent)
{
    try
    {
        rdaRawMaterial.CaptionText = strCaption;
        rdaRawMaterial.ContentText = strContent;
        rdaRawMaterial.Show();
    }
    catch (Exception ex)
    {
        MessageBox.Show("Unable to display Desktop Alert.", "No Desktop Alert");
    }
}

But it's displayed incompletely. It would only displayed up to the first <br>.

Thanks.

Regards,
Jenson
0
Accepted
Ivan Todorov
Telerik team
answered on 07 Jun 2012, 07:24 AM
Hi Jenson,

Thank you for contacting us.

Currently, RadDesktopAlert does not support AutoSize. However, you can measure the text you want to display before you open the alert and then set its FixedSize property. The following sample demonstrates this:
public Form1()
{
    InitializeComponent();
    this.radDesktopAlert1.FixedSize = new System.Drawing.Size(330, 330);
}
 
private void radButton1_Click(object sender, EventArgs e)
{
    //20 - vertical margins, 70 - caption height
    MeasurementGraphics graphics = MeasurementGraphics.CreateMeasurementGraphics();
    SizeF sizeF = graphics.Graphics.MeasureString(this.radDesktopAlert1.ContentText, this.Font, this.radDesktopAlert1.FixedSize.Width - 20);
 
    this.radDesktopAlert1.FixedSize = new Size(this.radDesktopAlert1.FixedSize.Width - 20, (int)sizeF.Height + 70);
    this.radDesktopAlert1.Show();
}

Note that the above method will work with plain text only. If you need to use HTML-like formatted text, then the approach would be slightly different.

I hope this will help you. Please let me know if you have any additional questions.

Regards,
Ivan Todorov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Jenson
Top achievements
Rank 2
answered on 07 Jun 2012, 07:35 AM
Dear Ivan,

Thanks for your reply. May I know how should I achieve this if I want to use HTML-like formatted text? (As shown in the code I've pasted in my first post).

As plain text is good if I only want to display a short and sweet message.

Btw, any plan from Telerik to enable the AutoSize of FixedSize value?

Thank you.

Cheers,
Jenson
0
Accepted
Ivan Todorov
Telerik team
answered on 07 Jun 2012, 02:47 PM
Hello Jenson,

Here is how you can measure the text when you also have some HTML-like formatting:
private void radButton1_Click(object sender, EventArgs e)
{
    this.radDesktopAlert1.Popup.LoadElementTree();
    RadDesktopAlertElement alertElement = ((DesktopAlertPopup)this.radDesktopAlert1.Popup).RootElement.Children[0] as RadDesktopAlertElement;
    alertElement.ContentElement.Measure(new SizeF(this.radDesktopAlert1.FixedSize.Width, float.PositiveInfinity));
    this.radDesktopAlert1.FixedSize = new Size(this.radDesktopAlert1.FixedSize.Width, (int)alertElement.ContentElement.DesiredSize.Height + 50);
    this.radDesktopAlert1.Show();
}

This solution should also work if the text is plain.

As to adding AutoSize support to RadDesktopAlert, no, we currently do not have plans or time frames for adding such a feature. However, this feature sound reasonable and therefore I have logged it in our Public Issue Tracking System as a feature request. Here is the link to the PITS item. You can subscribe to it to track if for changes or vote for it to increase its priority.

Your Telerik points have been updated. Feel free to ask if you have any future questions.

Greetings,
Ivan Todorov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Jenson
Top achievements
Rank 2
answered on 08 Jun 2012, 02:13 AM
Dear Ivan,

Thanks for the helps and efforts.

I would love to see this features coming out, but so far no one has voted for it yet. I've just cast my vote for this.

I commented there that there should be a restriction on the maximum of characters to be allowed in RadDesktopAlert ContentText, otherwise, people might abuse the flexibility and blow up the Alert to fill the whole screen, which definitely defeat the purpose of using a RadDesktopAlert, unless that's one of the flexibility Telerik would like to give the rights back to developers to decide how they want to use their Telerik controls :-)

Thank you!

Cheers,
Jenson
0
Ivan Todorov
Telerik team
answered on 12 Jun 2012, 09:15 AM
Hello Jenson,

The PITS item was created at the moment I wrote my previous post so not having any votes is pretty normal. Thank you very much for your feedback. We really appreciate that you have shared it with us.

Should you have any future questions, do not hesitate to contact us.

Kind regards,
Ivan Todorov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Shanti 😎
Top achievements
Rank 2
Veteran
answered on 29 Mar 2021, 03:50 PM
    Private Shared Function toShowDesktopAlert(value As String, icon As Image, backcolor As Color, AutoCloseDelay As Integer)
        Try
            Dim Reminder As New RadDesktopAlert

            'INITIALISZING PROPERTIES
            Reminder = New RadDesktopAlert
            Reminder.ShowPinButton = False
            Reminder.ShowOptionsButton = False
            Reminder.FixedSize = New System.Drawing.Size(330, 330)
            Reminder.Popup.Opacity = 1

            Reminder.Popup.AlertElement.ButtonsPanel.Visibility = ElementVisibility.Collapsed
            Reminder.Popup.AlertElement.CaptionElement.Visibility = ElementVisibility.Collapsed
            Reminder.Popup.BackColor = Color.Transparent
            Reminder.Popup.AlertElement.BackColor = backcolor
            Reminder.Popup.AlertElement.BorderColor = backcolor
            Reminder.Popup.AlertElement.ForeColor = backcolor
            Reminder.Popup.AlertElement.NumberOfColors = 1
            Reminder.Popup.AlertElement.GradientStyle = GradientStyles.Solid
            Reminder.Popup.AlertElement.Shape = New RoundRectShape(8)

            Dim dockPanel As DockLayoutPanel = New DockLayoutPanel()
            dockPanel.LastChildFill = True
            dockPanel.StretchHorizontally = True

            Dim imageElement As LightVisualElement = New LightVisualElement()
            imageElement.Image = icon
            imageElement.ImageLayout = ImageLayout.Center
            imageElement.Margin = New System.Windows.Forms.Padding(5, 0, 0, 0)

            Dim textElement As RadLabelElement = New RadLabelElement()
            textElement.Text = value
            textElement.ForeColor = Color.White
            textElement.StretchHorizontally = True
            textElement.TextAlignment = ContentAlignment.MiddleLeft
            textElement.Margin = New System.Windows.Forms.Padding(10, 0, 0, 0)

            dockPanel.Children.Add(imageElement)
            dockPanel.Children.Add(textElement)
            Reminder.Popup.AlertElement.ContentElement.Children.Add(dockPanel)

            Reminder.Popup.AlertElement.ContentElement.TextAlignment = ContentAlignment.MiddleLeft
            Reminder.Popup.AlertElement.ContentElement.ImageAlignment = ContentAlignment.MiddleLeft
            Reminder.ScreenPosition = AlertScreenPosition.Manual
            Reminder.AutoCloseDelay = AutoCloseDelay
            Reminder.PopupAnimation = False
            Reminder.Popup.LoadElementTree()

            Dim alertElement As RadDesktopAlertElement = TryCast((CType(Reminder.Popup, DesktopAlertPopup)).RootElement.Children(0), RadDesktopAlertElement)
            alertElement.ContentElement.Measure(New SizeF(Reminder.FixedSize.Width, Single.PositiveInfinity))
            Reminder.FixedSize = New Size(Reminder.FixedSize.Width, CInt(alertElement.ContentElement.DesiredSize.Height) + 20)
            Reminder.Popup.Location = New Point((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Reminder.FixedSize.Width / 2), 125)

            Return Reminder

        Catch ex As Exception
            Throw ex
        End Try

    End Function
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 30 Mar 2021, 04:33 AM

Hi, Tovino,

Thank you for sharing your solution with the community.

Since this is a very old forum post, I would like to note that since R1 2017 RadDesktopAlert supports auto sizing. Hence, if the AutoSize property is set to true and the alert's content requires more space, RadDesktopAlert will be automatically resized to fit the text.

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

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
DesktopAlert
Asked by
Jenson
Top achievements
Rank 2
Answers by
Jenson
Top achievements
Rank 2
Ivan Todorov
Telerik team
Shanti 😎
Top achievements
Rank 2
Veteran
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or