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

Removing the maximize and minimize buttons

2 Answers 404 Views
Window
This is a migrated thread and some comments may be shown as answers.
Simon Allport
Top achievements
Rank 2
Simon Allport asked on 07 Sep 2011, 02:56 PM
Hi,
Is there away to  remove the maximize and minimize buttons from the Rad Window. I would like to this dynamically in code.
Notes note = new Notes();
int NoteID = note.AddNote(_wardcode);
 
 Telerik.Windows.Controls.RadWindow rw = new Telerik.Windows.Controls.RadWindow();
 rw.Width = nw / 5;
 rw.Height = nh / 4;
 rw.Name = "NotePad" + NoteID;
 rw.BorderThickness = new Thickness(0);
 rw.BorderBrush = null;
 rw.Header = "Note" + DateTime.Now.ToShortDateString();
 
 Grid grid = new Grid();
 
 grid.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 240, 255, 255));
  
 System.Windows.Controls.RichTextBox rtxtbx = new System.Windows.Controls.RichTextBox();
 rtxtbx.Name = "txtNotePad" + NoteID;
 rtxtbx.FontSize = fontsize * 2;
 rtxtbx.GotFocus += new RoutedEventHandler(rtxtbx_GotFocus);
 rtxtbx.LostFocus += delegate(object sender, RoutedEventArgs e) { rtxtbx_LostFocus(sender, e, NoteID); };
 
 rw.LayoutChangeEnded += delegate(object sender, EventArgs e) { Page2_LayoutChangeEnded(sender, e, NoteID); };
 rw.Closed += delegate(object sender, WindowClosedEventArgs e) { Page2_Closed(sender, e, NoteID); };
 rw.LostFocus += new RoutedEventHandler(rw_LostFocus);
  
 grid.Children.Add(rtxtbx);
 rw.Content = grid;
 rw.Show();

Any help would be great

Thanks

Simon

2 Answers, 1 is accepted

Sort by
0
Dani
Telerik team
answered on 08 Sep 2011, 08:43 AM
Hi Simon,

Normally, you would hide or remove the minimize and maximize buttons from the control template of RadWindow. You need to generate the style for RadWindow and manually hide the buttons. An alternative is to handle the Loaded event  of the root element of RadWindow control template and hide the buttons in the event handler. This is not a nice and elegant way to accomplish the task, so I do not recomment it.

As you wish to do that dynamically, the most simple way is to set the ResizeMode to NoResize.  Of course, if you set that,  the window will not be resizeable.

Hopefully, this will give you a clue which course of action to take.

All the best,
Dani
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
N Mackay
Top achievements
Rank 1
answered on 22 Sep 2011, 09:56 AM
I just noticed this.

We had the same issue and it's a massive oversight in the WPF framework, it's not Telerik's fault.

Disabling the buttons is a less painful solution, it uses API calls which I don't like (may not be windows8 compatible) but it's an option

Imports System
Imports System.Windows
Imports System.Windows.Interop
Imports System.Runtime.InteropServices
  
Namespace MyNamespace
  
    Public Class WindowHelper
  
        Private Const GWL_STYLE As Int32 = -16
        Private Const WS_MAXIMIZEBOX As Int32 = &H10000
        Private Const WS_MINIMIZEBOX As Int32 = &H20000
  
        <DllImport("User32.dll", EntryPoint:="GetWindowLong")> _
        Private Shared Function GetWindowLongPtr(ByVal hWnd As IntPtr, ByVal nIndex As Int32) As Int32
        End Function
  
        <DllImport("User32.dll", EntryPoint:="SetWindowLong")> _
        Private Shared Function SetWindowLongPtr(ByVal hWnd As IntPtr, ByVal nIndex As Int32, ByVal dwNewLong As Int32) As Int32
        End Function
  
  
        Public Shared Sub DisableMaximize(ByVal window As Window)
  
            SyncLock window
  
                Dim hWnd As IntPtr = New WindowInteropHelper(window).Handle
                Dim windowStyle As Int32 = GetWindowLongPtr(hWnd, GWL_STYLE)
                SetWindowLongPtr(hWnd, GWL_STYLE, windowStyle And Not WS_MAXIMIZEBOX)
  
            End SyncLock
  
        End Sub
        Public Shared Sub DisableMinimize(ByVal window As Window)
  
            SyncLock window
  
                Dim hWnd As IntPtr = New WindowInteropHelper(window).Handle
                Dim windowStyle As Int32 = GetWindowLongPtr(hWnd, GWL_STYLE)
                SetWindowLongPtr(hWnd, GWL_STYLE, windowStyle And Not WS_MINIMIZEBOX)
  
            End SyncLock
  
        End Sub
  
    End Class
  
End Namespace

And you can call if from your window

Private Sub MyWindow_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
  
            Try
  
                '// Disable the minimise button, WPF cannot do this
                '// This has to be raised in the activated event as the buttons won't disable until the window is shown
  
                WindowHelper.DisableMinimize(Me)

it might help someone.
Tags
Window
Asked by
Simon Allport
Top achievements
Rank 2
Answers by
Dani
Telerik team
N Mackay
Top achievements
Rank 1
Share this question
or