WPF透明框设置Demo
<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());
});
}
}
}
#####
愿你一寸一寸地攻城略地,一点一点地焕然一新
#####
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix