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

Replace Open / Save File dialog boxes with my own

3 Answers 212 Views
RibbonBar
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 10 Jul 2019, 05:34 PM

Visual Studio 2017
VB.Net
Telerik UI for WinForms R2 2019 SP1

I need to enforce a root folder for users and only give them access files and folders within this root folder and I have my own dialog box for this. Can I use my dialog box when the user clicks Open or Save or Save As?

3 Answers, 1 is accepted

Sort by
0
Nadya
Telerik team
answered on 11 Jul 2019, 11:32 AM
Hello Jeff,

Yes, it is possible to achieve this behavior, but according to the provided information it is not clear which RadControl you use in your application. Could you please specify which is the RadControl you would like to add the RadRibbonBar?
This is needed because before applying the new created custom RadRibbonBar to the application you need to know which events to override. For example, if you are using the RadRichTextEditor you can create a custom class that inherits RichTextEditorRibbonBar, and then override the necessary events. A sample exam is shown in the following code snippet:

Class CustomRichTextEditorRibbonBar
    Inherits RichTextEditorRibbonBar
    Protected Overrides Sub BackstageButtonOpen_Click(ByVal sender As Object, ByVal e As EventArgs)
        ' add your own dialog box here
    End Sub
End Class

More information is available here: https://docs.telerik.com/devtools/winforms/controls/richtexteditor/ui-for-applying-rich-text-formatting/how-to/custom-ribbon.html

I am looking forward to your reply.

Regards,
Nadya
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.
0
Jeff
Top achievements
Rank 1
answered on 15 Jul 2019, 09:52 PM

I'm using the pre-configured word-like form so didn't want to recreate the ribbonbar . I added classes to override the buttons rather than the entire ribbon bar and this is giving me the results I wanted. Thanks for the suggestion of creating a custom class. 

    Class CustomOpenButton
        Inherits BackstageButtonItem
        Protected Overrides Sub OnClick(e As EventArgs)
            'Do what you need to do       
        End Sub
    End Class
 
    Class CustomSaveButton
        Inherits BackstageButtonItem
        Protected Overrides Sub OnClick(e As EventArgs)
            'Do what you need to do
        End Sub
    End Class
 
    Class CustomSaveAsButton
        Inherits BackstageButtonItem
        Protected Overrides Sub OnClick(e As EventArgs)
             'Do what you need to do
        End Sub
    End Class
 
Private Sub CustomizeMenu()
        Dim RibbonBar = CType(richTextEditorRibbonBar1, RichTextEditorRibbonBar)
        Dim backstageViewElemet = CType(RibbonBar.BackstageControl.BackstageElement, BackstageViewElement)
        Dim itemsPanel = CType(backstageViewElemet.ItemsPanelElement, BackstageItemsPanelElement)
        Dim contentPanel = CType(backstageViewElemet.ContentElement, BackstageContentPanelElement)
        Dim NewCustomOpenButton As New CustomOpenButton
        Dim NewCustomSaveButton As New CustomSaveButton
        Dim NewCustomSaveAsButton As New CustomSaveAsButton
        Dim ItemIndex As Integer = 0
        For Each ViewElement In RibbonBar.BackstageControl.Items
            'New
            'Open
            'Print
            'Print Preview
            'Save
            'Save As
            Select Case Trim(ViewElement.AccessibleName)
                Case "Open"
                    ViewElement.Visibility = ElementVisibility.Collapsed
                    Dim OldButton As New BackstageButtonItem
                    OldButton = CType(ViewElement, BackstageButtonItem)
                    With NewCustomOpenButton
                        .Text = "  Open"
                        .Image = OldButton.Image
                    End With
                Case "Save"
                    ViewElement.Visibility = ElementVisibility.Collapsed
                    Dim OldButton As New BackstageButtonItem
                    OldButton = CType(ViewElement, BackstageButtonItem)
                    With NewCustomSaveButton
                        .Text = "  Save"
                        .Image = OldButton.Image
                    End With
                    With NewCustomSaveAsButton
                        .Text = "  Save As"
                        .Image = OldButton.Image
                    End With
                Case "Save As" 'I want this to be a button
                    Dim OldButton As New BackstageTabItem
                    OldButton = CType(ViewElement, BackstageTabItem)
                    ViewElement.Visibility = ElementVisibility.Collapsed
            End Select
            ItemIndex += 1
        Next
 
        'Insert the new buttons after the "For Next". Adjust the index to put them in the correct place
        richTextEditorRibbonBar1.BackstageControl.BackstageElement.Items.Insert(1, NewCustomOpenButton)
        richTextEditorRibbonBar1.BackstageControl.BackstageElement.Items.Insert(5, NewCustomSaveButton)
        richTextEditorRibbonBar1.BackstageControl.BackstageElement.Items.Insert(6, NewCustomSaveAsButton)
 
        'Remove Content Element items
        contentPanel.Visibility = ElementVisibility.Collapsed
 
        'Remove the "Save" button from the quick access area
        RibbonBar.QuickAccessToolBarItems.Item(0).Visibility = ElementVisibility.Collapsed
 
        'Remove Ribbon Tabs.
        Dim TabHome As RibbonTab = CType(RibbonBar.CommandTabs(0), RibbonTab)
        Dim TabInsert As RibbonTab = CType(RibbonBar.CommandTabs(1), RibbonTab)
        Dim TabPageLayout As RibbonTab = CType(RibbonBar.CommandTabs(2), RibbonTab)
        Dim TabReference As RibbonTab = CType(RibbonBar.CommandTabs(3), RibbonTab)
        Dim TabMailings As RibbonTab = CType(RibbonBar.CommandTabs(4), RibbonTab)
        Dim TabReview As RibbonTab = CType(RibbonBar.CommandTabs(5), RibbonTab)
        Dim TabView As RibbonTab = CType(RibbonBar.CommandTabs(6), RibbonTab)
        RibbonBar.CommandTabs.Remove(TabReference)
        RibbonBar.CommandTabs.Remove(TabMailings)
        RibbonBar.CommandTabs.Remove(TabReview)
        RibbonBar.CommandTabs.Remove(TabView)
 
End Sub
0
Nadya
Telerik team
answered on 17 Jul 2019, 03:47 AM
Hello Jeff,

I am glad that you found out a suitable solution for your specific requirement. Do not hesitate to contact us if you have other questions.

Regards,
Nadya
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.
Tags
RibbonBar
Asked by
Jeff
Top achievements
Rank 1
Answers by
Nadya
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or