Is it possible to develop transparent submenus using toolStrip or MainMenu?

Youngs 40 Reputation points
2024-03-21T02:12:32.9333333+00:00

hello.

I have a mission where I need to make a submenu window in a menu or toolstrip transparent.

I am not getting any direction at all.

If you have any keywords or sources that I can refer to, I would appreciate it.

User's image

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,931 questions
{count} votes

Accepted answer
  1. Jiale Xue - MSFT 45,266 Reputation points Microsoft Vendor
    2024-03-21T08:02:48.84+00:00

    Hi @Youngs , Welcome to Microsoft Q&A,

    Transparent background color is not supported in winform.

    If you are not specific using winform.

    It is recommended that you can use wpf.

    <Window x:Class="xx.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:_3_21_3"
            mc:Ignorable="d"
            Title="MainWindow" Height="450" Width="800">
        <Window.Resources>
            <Style TargetType="{x:Type MenuItem}">
                <Setter Property="OverridesDefaultStyle" Value="True"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type MenuItem}">
                            <Border Name="Border" Background="Transparent">
                                <Grid>
                                    <ContentPresenter Margin="6,3,6,3" ContentSource="Header" RecognizesAccessKey="True"/>
                                    <Popup Name="Popup" Placement="Right" IsOpen="{TemplateBinding IsSubmenuOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Slide">
                                        <Border Name="SubmenuBorder" SnapsToDevicePixels="True" Background="Transparent">
                                            <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"/>
                                        </Border>
                                    </Popup>
                                </Grid>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsSuspendingPopupAnimation" Value="True">
                                    <Setter TargetName="Popup" Property="PopupAnimation" Value="None"/>
                                </Trigger>
                                <Trigger Property="IsHighlighted" Value="True">
                                    <Setter TargetName="Border" Property="Background" Value="LightBlue"/>
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter Property="Foreground" Value="LightGray"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Window.Resources>
    
        <Grid Background="Blue">
            <Menu Height="24" VerticalAlignment="Top">
                <MenuItem Header="File">
                    <MenuItem Header="New"/>
                    <MenuItem Header="Open"/>
                    <MenuItem Header="Save"/>
                </MenuItem>
                <MenuItem Header="Edit">
                    <MenuItem Header="Cut"/>
                    <MenuItem Header="Copy"/>
                    <MenuItem Header="Paste"/>
                </MenuItem>
            </Menu>
        </Grid>
    </Window>
    
    

    User's image

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.