首页 > 其他分享 >WPF透明框设置Demo

WPF透明框设置Demo

时间:2023-12-14 14:12:43浏览次数:32  
标签:透明 Windows Demo System columnHeader editTextBox using WPF tableControl

<Window x:Class="GuiDB.EBMultiEditTextWin"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:GuiDB"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800" Background="Transparent" 
       Opacity="1"
        WindowStyle="None"
        Topmost="True"
        AllowsTransparency="True" ShowInTaskbar="False"
        KeyDown="Window_KeyDown" 
        Loaded="Window_Loaded"
        >
    <Grid>
        <TextBox x:Name="editTextBox" Visibility="Hidden" Background="White"  Foreground="Black" 
                 BorderBrush="White" CaretBrush="White"
                 TextWrapping="Wrap" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"
                  
                 PreviewLostKeyboardFocus="editTextBox_PreviewLostKeyboardFocus"
                 />
    </Grid>
</Window>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace GuiDB
{
    /// <summary>
    /// EBMultiEditTextWin.xaml 的交互逻辑
    /// </summary>
    public partial class EBMultiEditTextWin : Window
    {
        EBMultiTableControl _tableControl;
        EBColumn _columnHeader;

        public EBMultiEditTextWin(EBMultiTableControl tableControl,EBColumn header,double textW,double textH,double top,double left)
        {
            InitializeComponent();

            _tableControl = tableControl;
            _columnHeader = header;
            this.Width = textW;
            this.Height = textH;
            editTextBox.Width = textW;
            editTextBox.Height = textH;
            this.Top = top;
            this.Left = left;

            
        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key.ToString() == "Return")
            {
                _columnHeader.Content = editTextBox.Text;
                _tableControl.ReDraw();
                Close();
            }
            else if (e.Key.ToString() == "Escape")
            {
                _tableControl.ReDraw();
                Close();
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            editTextBox.Visibility = Visibility.Visible;
            editTextBox.FontSize = 10;
            editTextBox.Text = _columnHeader.Content;

            editTextBox.SelectAll();
            editTextBox.Focus();
        }

        private void editTextBox_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            _columnHeader.IfBeSel = false;
            _tableControl.DownPt = null;
            _tableControl.ReDraw();
            
            Task.Run(() =>
            {
                Dispatcher.Invoke(() => Close());
            });
        }
    }
}

标签:透明,Windows,Demo,System,columnHeader,editTextBox,using,WPF,tableControl
From: https://www.cnblogs.com/johnyang/p/17901054.html

相关文章

  • [转][C#][WPF]原生使用 INotifyPropertyChanged
    在上一篇基础上,我们添加对字段的绑定效果:界面添加:<TextBoxText="{BindingName}"Width="120"Height="31"/>在 MainWindowModel里添加:publicclassMainWindowModel:INotifyPropertyChanged{publiceventPropertyChangedEventHandlerProper......
  • 【Avalonia】Avalonia的学习笔记以及与WPF的不同点
    1.axaml中引用命名空间xmlns:model="using:IDataTemplateSample.Models"2.Grid支持行列的简化写法<GridRowDefinitions="Auto,Auto,*"ColumnDefinitions="Auto,*"/>3.DataTemplate根据DataType自动选择对应类型的样式,使用Window.DataTemplates加载多个DataTem......
  • [转][C#][WPF]原生使用 ICommand
    传参这里参考:https://www.cnblogs.com/zhlziliaoku/p/5867556.html界面上添加一个按钮 <ButtonContent="点击"Width="120"Height="31"Command="{BindingshowCommand}"CommandParameter="{BindingRelativeSource={RelativeSourcese......
  • WPF限制字符串的最长显示长度,超出后尾部显示...
    在WPF中,如果你想要限制一个字符串的显示长度,并在超出后用省略号(...)表示,你可以使用TextBlock控件和设置它的TextTrimming属性。这种方法可以自动截断文本并在末尾添加省略号。<TextBlockText="{BindingYourString}"TextTrimming="CharacterEllipsis"Max......
  • WPF 解决PasswordBox 属性Password无法绑定到后台的问题
    在WPF中,你可以使用密码框的Password属性来绑定到后台,但是由于安全性考虑,WPF的密码框不直接支持双向绑定。然而,你仍然可以通过其他方式实现将密码框的内容绑定到后台。一种常见的方法是创建一个附加属性(AttachedProperty)来实现密码框的双向绑定。以下是一个简单的示例代码:c......
  • [转][C#][WPF]MVVM 下的 ComboBox 数据绑定效果
    参考:https://www.cnblogs.com/xpvincent/p/3848790.html参考:https://blog.csdn.net/zhudaokuan/article/details/109059333前端:<ComboBoxName="cmbBox"ItemsSource="{Bindinglist}"DisplayMemberPath="Code"SelectedValu......
  • 如何将 sap.ui.Table 控件的背景设置成透明
    笔者曾经写过一篇文章,介绍了如何在SAPUI5应用里设置背景图片:下图1是背景图片,图2是把这个背景图片加到SAPUI5应用之后的效果。后来有朋友追问:如果我的SAPUI5应用里使用的表格控件,没有用响应式表格sap.m.Table,而是sap.ui.table.Table,那又该如何实现?其实思路和我本文的思......
  • 界面控件DevExpress WPF导航组件,助力升级应用程序用户体验!(下)
    DevExpressWPF的SideNavigation(侧边导航)、TreeView、导航面板组件能帮助开发者在WPF项目中添加Windows样式的资源管理器栏或OutlookNavBar(导航栏),DevExpressWPFNavBar和Accordion控件包含了许多开发人员友好的功能,专门设计用于帮助用户构建极佳的应用功能。在上文中(点击这里回......
  • 写了一个flinkcdc的简单demo,大概说一下实现过程和建议点
    架构图大致如下:版本信息大致如下,具体版本信息根据自己的需求进行调整即可:oracle:19cflinkcdc:2.4.0kafka:3.1.2flink:1.15.4mysql:8.0.27springboot:2.5.6实现需求:1.使用flinkcdc采集oracle中的数据(历史数据+增量数据:含增删改)同步至kafka的某个topic中2.使用flink消费kafka中......
  • WPF 制作三个点从左到右过渡隐藏显示
     Code:<Windowx:Class="WpfApp1.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.micros......