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

Display a form just below a RadButtonElement placed on title bar

1 Answer 72 Views
Buttons, RadioButton, CheckBox, etc
This is a migrated thread and some comments may be shown as answers.
Swaroop
Top achievements
Rank 1
Veteran
Swaroop asked on 16 Oct 2020, 02:47 PM

Hello,
Ive added a RadButtonElement to my RadForm's TitleBar using the below mentioned code:


Public Class RadForm1
Dim b1 As New RadButtonElement
Sub RadForm_Load(...) Handles RadForm.Load
FormElement.TitleBar.SystemButtons.Children.Insert(0, b1)
End Sub
End Class


Now what I want to achieve is when I click on b1 a small form (RadForm2) should be displayed just below b1. For that I tried to get the location of b1 so that I can use the b1's location value to set the location of RadForm2. But the location value of b1 returns 0,0.
So maybe I can't achieve what I want using the ButtonElement's location value as it seams the location value of any button element on the TitleBar is always 0,0.
So is there anyway I can get RadForm2 to be displayed just below b1?


1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 21 Oct 2020, 09:13 AM

Hello, Swaroop,

The provided code snippet is greatly appreciated.

You can get the location of the newly added button by using the ControlBoundingRectangle property. The exact X and Y coordinates you can get from ControlBoundingRectangle.X and ControlBoundingRectangle.Y. Note, that this will give the control coordinates within the form. Before positioning the second form you should translate them into the screen coordinate system.

I prepared a sample example for your reference:

Public Partial Class RadForm1
    Inherits Telerik.WinControls.UI.RadForm
    Private b1 As RadButtonElement = New RadButtonElement()
    Public Sub New()
        InitializeComponent()
        b1.Text = "b1"
       AddHandler b1.Click, AddressOf  Me.B1_Click
        FormElement.TitleBar.SystemButtons.Children.Insert(0, b1)
    End Sub
End Class

Private Sub B1_Click(ByVal sender As Object, ByVal e As EventArgs)
   ' Get the button location
    Dim form_pt As Point = New Point(b1.ControlBoundingRectangle.X, b1.ControlBoundingRectangle.Y)
    ' Translate into the screen coordinate system.
    Dim screen_pt As Point = Me.PointToScreen(form_pt)
    Dim frm As RadForm = New RadForm()
    frm.StartPosition = FormStartPosition.Manual
    frm.Location = screen_pt
    frm.Show()
End Sub

I hope this helps. Should you have other questions do not hesitate to contact me.

 

Regards,
Nadya
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
Buttons, RadioButton, CheckBox, etc
Asked by
Swaroop
Top achievements
Rank 1
Veteran
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or