|
| 1 | +--- |
| 2 | +title: How to use RadTitleBar on a standard MS Form/RadForm |
| 3 | +description: This article demonstrates how to use RadTitle on a standard MS Form/RadForm. |
| 4 | +type: how-to |
| 5 | +page_title: How to use RadTitleBar on a standard MS Form/RadForm |
| 6 | +slug: titlebar-on-form |
| 7 | +position: 0 |
| 8 | +tags: formsanddialogs,titlebar, forms, minimize, maximize, winforms |
| 9 | +res_type: kb |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +|Product Version|Product|Author| |
| 15 | +|----|----|----| |
| 16 | +|2025.3.812|RadTitleBar for WinForms|[Nadya Karaivanova](https://www.telerik.com/blogs/author/nadya-karaivanova)| |
| 17 | + |
| 18 | +## Description |
| 19 | + |
| 20 | +The standard Form as well as RadForm do provide their own title bar integrated in the form. However, a common requirement is to want to customize the buttons on the form, or change their behavior, etc. Here comes [RadTitleBar](https://docs.telerik.com/devtools/winforms/controls/forms-and-dialogs/radtitlebar/radtitlebar) that allows it to be fully customized. |
| 21 | + |
| 22 | +## Solution |
| 23 | + |
| 24 | +To use RadTitleBar on a standard Form or RadForm, and achieve the same behavior when minimizing/maximizing the form, you need to override the `WndProc()` as shown below: |
| 25 | + |
| 26 | +A full code snippet is illustrated below. You can use the following approach for either [MS Form](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.form?view=windowsdesktop-9.0) or [RadForm](https://docs.telerik.com/devtools/winforms/controls/forms-and-dialogs/form/form). |
| 27 | + |
| 28 | + |
| 29 | +````C# |
| 30 | + |
| 31 | +public partial class Form1 : Form |
| 32 | +{ |
| 33 | + public Form1() |
| 34 | + { |
| 35 | + InitializeComponent(); |
| 36 | + //remove title bar of existing Form |
| 37 | + this.ControlBox = false; |
| 38 | + this.FormBorderStyle = FormBorderStyle.None; |
| 39 | + |
| 40 | + //Add RadTitleBar |
| 41 | + RadTitleBar radTitleBar = new Telerik.WinControls.UI.RadTitleBar(); |
| 42 | + radTitleBar.Dock = DockStyle.Top; |
| 43 | + this.Controls.Add(radTitleBar); |
| 44 | + |
| 45 | + } |
| 46 | + |
| 47 | + protected override void WndProc(ref Message m) |
| 48 | + { |
| 49 | + if (m.Msg == NativeMethods.WM_GETMINMAXINFO) |
| 50 | + { |
| 51 | + NativeMethods.MINMAXINFO info = (NativeMethods.MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.MINMAXINFO)); |
| 52 | + |
| 53 | + if (this.Parent == null) |
| 54 | + { |
| 55 | + Screen scr = Screen.FromControl(this); |
| 56 | + Rectangle workingArea = scr.WorkingArea; |
| 57 | + Rectangle screenRect = scr.Bounds; |
| 58 | + |
| 59 | + info.ptMaxSize.x = workingArea.Width; |
| 60 | + info.ptMaxSize.y = workingArea.Height; |
| 61 | + info.ptMaxPosition.x = workingArea.X - screenRect.X; |
| 62 | + info.ptMaxPosition.y = workingArea.Y - screenRect.Y; |
| 63 | + Marshal.StructureToPtr(info, m.LParam, false); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + base.WndProc(ref m); |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +```` |
| 72 | +````VB.NET |
| 73 | + |
| 74 | +Public Partial Class Form1 |
| 75 | + Inherits Form |
| 76 | + |
| 77 | + Public Sub New() |
| 78 | + InitializeComponent() |
| 79 | + ' remove title bar of existing Form |
| 80 | + Me.ControlBox = False |
| 81 | + Me.FormBorderStyle = FormBorderStyle.None |
| 82 | + |
| 83 | + ' Add RadTitleBar |
| 84 | + Dim radTitleBar As RadTitleBar = New Telerik.WinControls.UI.RadTitleBar() |
| 85 | + radTitleBar.Dock = DockStyle.Top |
| 86 | + Me.Controls.Add(radTitleBar) |
| 87 | + End Sub |
| 88 | + |
| 89 | + Protected Overrides Sub WndProc(ByRef m As Message) |
| 90 | + If m.Msg = NativeMethods.WM_GETMINMAXINFO Then |
| 91 | + Dim info As NativeMethods.MINMAXINFO = CType(Marshal.PtrToStructure(m.LParam, GetType(NativeMethods.MINMAXINFO)), NativeMethods.MINMAXINFO) |
| 92 | + |
| 93 | + If Me.Parent Is Nothing Then |
| 94 | + Dim scr As Screen = Screen.FromControl(Me) |
| 95 | + Dim workingArea As Rectangle = scr.WorkingArea |
| 96 | + Dim screenRect As Rectangle = scr.Bounds |
| 97 | + info.ptMaxSize.x = workingArea.Width |
| 98 | + info.ptMaxSize.y = workingArea.Height |
| 99 | + info.ptMaxPosition.x = workingArea.X - screenRect.X |
| 100 | + info.ptMaxPosition.y = workingArea.Y - screenRect.Y |
| 101 | + Marshal.StructureToPtr(info, m.LParam, False) |
| 102 | + End If |
| 103 | + End If |
| 104 | + |
| 105 | + MyBase.WndProc(m) |
| 106 | + End Sub |
| 107 | +End Class |
| 108 | + |
| 109 | +```` |
| 110 | + |
0 commit comments