2025年3月27日

WPF 自定义控件之 Button

摘要: XAML: <Button x:Class="MyMediaPlayer.UserControls.RoundedImageButton" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http: 阅读全文

posted @ 2025-03-27 11:43 空明流光 阅读(4) 评论(0) 推荐(0) 编辑

2025年3月26日

wpf 中 自定义模板关键属性 ContentPresenter 和 ItemsHost

摘要: 在 WPF 中,<ContentPresenter /> 是一个非常重要的元素,通常用于自定义控件模板中。它的主要作用是表示控件的内容,并且允许你将内容(例如文本、图像或其他控件)插入到控件的特定位置。 1‌. 自定义 Button 模板‌: <ControlTemplate TargetType= 阅读全文

posted @ 2025-03-26 11:44 空明流光 阅读(2) 评论(0) 推荐(0) 编辑

2025年3月25日

wpf 加载自定义字体

摘要: var families = Fonts.GetFontFamilies(new Uri("pack://application:,,,/MyMediaPlayer;component/Fonts/")); foreach (var family in families) { Console.Wri 阅读全文

posted @ 2025-03-25 15:17 空明流光 阅读(3) 评论(0) 推荐(0) 编辑

2025年3月24日

mvvm 事件绑定

摘要: Xaml: <!-- MainWindow.xaml --> <Window x:Class="WpfApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://s 阅读全文

posted @ 2025-03-24 12:27 空明流光 阅读(6) 评论(0) 推荐(0) 编辑

2025年3月23日

wpf webview2 大坑

摘要: 最大的坑:没有任何控件可以显示在 WebView2 控件之上,就算显示在那儿了,事件也可以响应,但绝对看不见,WebView2 控件都给你刷新成网页视觉内容了。 官方建议使用 wpf WebView2CompositionControl 替代,确实解决了上述 bug。没深入研究,但一启动网页右键上下 阅读全文

posted @ 2025-03-23 21:27 空明流光 阅读(15) 评论(0) 推荐(0) 编辑

Task.WhenAny 的陷阱

摘要: 最近做的一个下载程序经常会陷入死循环,一直下载,未报异常,但就是下载的文件不存在。 public async Task<bool> DownloadFileTimeout(string fileUrl, string savePath) { var timeoutTask = Task.Delay( 阅读全文

posted @ 2025-03-23 09:12 空明流光 阅读(7) 评论(0) 推荐(0) 编辑

2025年3月20日

WPF 绑定资源文件出错 无法将 Properties.Resources StaticExtension 值解析为枚举、静态字段或静态属性

摘要: 解决方法:选中项目中资源文件 Resources.resx,在属性窗口中将 ResXFileCodeGenerator 改为 PublicResXFileCodeGenerator 有点扯淡呀,VS问题,不同版本创建的这个选项不一样 阅读全文

posted @ 2025-03-20 20:30 空明流光 阅读(3) 评论(0) 推荐(0) 编辑

2025年3月18日

如何正确初始化 Webview2

摘要: var webView = new Microsoft.Web.WebView2.Wpf.WebView2(); gridMain.Children.Add(webView); await webView.EnsureCoreWebView2Async(null); webView.Source = 阅读全文

posted @ 2025-03-18 17:38 空明流光 阅读(7) 评论(0) 推荐(0) 编辑

2025年3月6日

c# OllamaSharp DeepSeek 有上下文可连续对话

摘要: 使用 ollama 安装完 deepseek 后, nuget 安装 OllamaSharp ,使用如下代码可实现完整对话,我使用的模型是 DeepSeek-Coder-V2-Lite,以下是核心代码: public class DeepSeekChat { IChatClient chatClie 阅读全文

posted @ 2025-03-06 09:49 空明流光 阅读(48) 评论(0) 推荐(0) 编辑

2025年2月4日

动态改变 log4net 日志位置

摘要: private static void changeLogFileLocation() { var logPath = ProfileHelper.GetLogPath(); // 获取当前的日志记录器 var hierarchy = (Hierarchy)LogManager.GetReposit 阅读全文

posted @ 2025-02-04 12:23 空明流光 阅读(15) 评论(0) 推荐(0) 编辑

winform 无窗体保持消息循环

摘要: static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetC 阅读全文

posted @ 2025-02-04 11:44 空明流光 阅读(8) 评论(0) 推荐(0) 编辑

2025年1月16日

Newtonsoft.Json 序列化时按格式自动换行

摘要: File.WriteAllText(wordCouplePinyinFilepath, JsonConvert.SerializeObject(dictWordCouples, new JsonSerializerSettings { Formatting = Formatting.Indented 阅读全文

posted @ 2025-01-16 22:48 空明流光 阅读(22) 评论(0) 推荐(0) 编辑

2025年1月13日

c# 打印各种符号和所有汉字一区的汉字

摘要: void Main() { var items = new List<string> {@"\uFF00-\uFFEF",@"\u2150-\u218F",@"\u2200-\u22FF",@"\u2460-\u24FF",@"\u2600-\u26FF",@"\u3000-\u303F", @"\ 阅读全文

posted @ 2025-01-13 17:52 空明流光 阅读(23) 评论(0) 推荐(0) 编辑

2024年12月29日

汉字及扩展汉字编码范围

摘要: 基本汉字([\u4e00-\u9fa5]): 这个范围包含了常见的汉字,是最基本的汉字字符集,常用于日常书写和印刷。 包括了现代汉语常用的绝大多数字符,包含了常见的词汇和地名等。 扩展汉字 A 区([\u3400-\u4DBF]): 这个区域包含了一些较为少见的汉字,主要是古文、方言字、或特殊符号等 阅读全文

posted @ 2024-12-29 15:51 空明流光 阅读(335) 评论(0) 推荐(0) 编辑

2024年12月21日

c# 通过正则对多个匹配结果进行个性化替换

摘要: void Main() { string input = "abcdef ghi jklmnop qrst uvwxyz"; // 正则表达式匹配所有字母(包括大小写字母) string pattern = @"[a-zA-Z]+"; // 使用 MatchEvaluator 在替换时处理每个匹配项 阅读全文

posted @ 2024-12-21 16:47 空明流光 阅读(23) 评论(0) 推荐(0) 编辑

2024年12月14日

wpf textbox 实现水印

摘要: <TextBox Width="200" VerticalContentAlignment="Center" Background="Transparent" Tag="Enter here..."> <TextBox.Style> <Style TargetType="{x:Type TextBo 阅读全文

posted @ 2024-12-14 12:07 空明流光 阅读(49) 评论(0) 推荐(0) 编辑

2024年11月5日

js 阻止后退

摘要: 第一步: // 禁止后退功能 if (typeof history.pushState == 'function') { history.pushState(null, null, location.href); history.back(); history.forward(); } 第二步: / 阅读全文

posted @ 2024-11-05 12:41 空明流光 阅读(101) 评论(0) 推荐(0) 编辑

2024年10月29日

c# winform 强制开启 dpi 感知

摘要: [DllImport("user32.dll")] private static extern bool SetProcessDPIAware(); 阅读全文

posted @ 2024-10-29 15:50 空明流光 阅读(24) 评论(0) 推荐(0) 编辑

2024年10月26日

.net8 winform 发布

摘要: 或者执行命令:dotnet publish -p:PublishSingleFile=true 阅读全文

posted @ 2024-10-26 19:11 空明流光 阅读(58) 评论(0) 推荐(0) 编辑

2024年10月22日

c# winform 将 Form 添加到控件中

摘要: var form1 = new Form() { TopLevel = false, Visible = true }; tabs.TabPages[0].Controls.Add(form1); form1.BringToFront(); 阅读全文

posted @ 2024-10-22 09:28 空明流光 阅读(45) 评论(0) 推荐(0) 编辑

2024年10月20日

js 中主窗口与 iframe 通信

摘要: if (window.top window.self) { window.addEventListener('message', function (event) { alert(event.data) }); } else { window.parent.postMessage("Hello fr 阅读全文

posted @ 2024-10-20 14:44 空明流光 阅读(41) 评论(0) 推荐(0) 编辑

c# 动态增删 url 中的 query string 查询参数

摘要: void Main() { var url = "http://www.demo.com/demo.html?a=1&b=2"; var uri = new Uri(url); var parameters = HttpUtility.ParseQueryString(uri.Query); par 阅读全文

posted @ 2024-10-20 12:10 空明流光 阅读(19) 评论(0) 推荐(0) 编辑

2024年10月19日

WebView2 拦截查看所有的请求

摘要: 有两种方式: 1. 使用 devtool protocol: // 启用网络监控 await webView.CoreWebView2.CallDevToolsProtocolMethodAsync("Network.enable", "{}"); //注册 Network.requestWillB 阅读全文

posted @ 2024-10-19 10:32 空明流光 阅读(606) 评论(1) 推荐(1) 编辑

2024年10月18日

c# winform datagridview 显示行号

摘要: 长时间不写,就忘了,备忘一下 dataGridView1.RowHeadersVisible = true; dataGridView1.RowHeadersWidth = 150; dataGridView1.RowStateChanged += (s, args) => { args.Row.H 阅读全文

posted @ 2024-10-18 20:19 空明流光 阅读(254) 评论(0) 推荐(0) 编辑

2024年10月16日

c# winform 显示一个 tip

摘要: public void showTip(string text, int duration = 2000) { var form = new Form { Size = new Size(1, 1), StartPosition = FormStartPosition.CenterScreen }; 阅读全文

posted @ 2024-10-16 23:30 空明流光 阅读(36) 评论(0) 推荐(0) 编辑

c# .net8 winform 嵌入 wpf 控件

摘要: .net framework 例子很多,但 .netcore 的很难找,经过和 gpt 很长时间的沟通,完成了。 关键点是 vs2022 似乎还不支持设计时的 ElementHost,所以必须通过代码初始化。 1. 新建一个 wpf 控件库 2. 创建一个导圆角的 TextBox,控件名为 User 阅读全文

posted @ 2024-10-16 19:12 空明流光 阅读(387) 评论(0) 推荐(0) 编辑

2024年10月14日

C# Mutex 在异步方法中线程同步失效

摘要: Mutex 在异步方法中线程同步失效: private readonly Mutex mutexInitialize = new Mutex(); public async Task<bool> Initialize() { mutexInitialize.WaitOne(); try { ... 阅读全文

posted @ 2024-10-14 23:38 空明流光 阅读(48) 评论(0) 推荐(0) 编辑

C# WinForm 菜单项的大小、高宽的手动控制

摘要: 转载:C# WinForm 菜单项的大小、高宽的手动控制 - 清潭荷韵 - 博客园 (cnblogs.com) 感觉有用,怕搜不到,于是转一下 控制菜单项的第一级的下级菜单项的大小: 直接通过(ContextMenuStrip对象).AutoSize = false、(ContextMenuStri 阅读全文

posted @ 2024-10-14 18:47 空明流光 阅读(87) 评论(0) 推荐(0) 编辑

webview2 获取页面截图

摘要: var ms = new MemoryStream(); await Browser.CoreWebView2.CapturePreviewAsync(CoreWebView2CapturePreviewImageFormat.Png, ms); { var bytes = ms.ToArray() 阅读全文

posted @ 2024-10-14 15:09 空明流光 阅读(253) 评论(0) 推荐(0) 编辑

2024年10月12日

c# winform 高 dpi 自适应开发步骤

摘要: 1. 在不启用 dpi aware 模式下开发 2. 启动 dpi aware 3. 对有问题的控件使用 DpiHelper 对定位和大小或者图像进行转换 参见 解决 DPI 问题 - Visual Studio (Windows) | Microsoft Learn 部分官方示例: 若要从将在 V 阅读全文

posted @ 2024-10-12 13:52 空明流光 阅读(199) 评论(0) 推荐(0) 编辑

2024年10月11日

c# 注册协议处理程序

摘要: static void registerAsHttpHandler() { // Register as the default handler for the http: protocol. const string protocolValue = "HTTP:Hypertext Transfer 阅读全文

posted @ 2024-10-11 22:07 空明流光 阅读(9) 评论(0) 推荐(0) 编辑

c# 捕获系统快捷键

摘要: private void GlobalKeyCapture_KeyDown(object sender, KeyEventArgs e) { //判断当前进程是否是活动进程,以决定是否响应 var currentProcess = getActiveProcess(); if (currentPro 阅读全文

posted @ 2024-10-11 11:57 空明流光 阅读(24) 评论(0) 推荐(0) 编辑

2024年9月29日

c# webclient 使用默认代理的代码

摘要: void Main() { using (WebClient client = new WebClient()) { // 使用默认代理 client.Proxy = WebRequest.GetSystemWebProxy(); // 你可以选择是否设置凭据 client.Credentials 阅读全文

posted @ 2024-09-29 21:15 空明流光 阅读(21) 评论(0) 推荐(0) 编辑

2024年9月2日

c++ string 与 wstring 互转并解决显示乱码

摘要: string 转 wstring: #include <iostream> #include <sstream> #include <locale> #include <string> #include <codecvt> int main() { std::string utf8_str = "你 阅读全文

posted @ 2024-09-02 12:29 空明流光 阅读(336) 评论(0) 推荐(0) 编辑

2024年7月20日

winform 的 datagridview 动态刷新

摘要: 要实现在 datagridview 中动态的增删改查、排序、筛选,目前能用的比较友好的方案似乎只有 datatable,网上有人说用 BindingList 的,我替你们试过了,无法筛选,坑很多 public partial class Form1 : Form { private DataTabl 阅读全文

posted @ 2024-07-20 13:02 空明流光 阅读(510) 评论(0) 推荐(0) 编辑

2024年7月16日

winform 动态截断或者补全文字宽度

摘要: 使用 TabControl 时,发现它的选项卡宽度会随文字长度变化,我自己做了一个浏览器,发现很难看,于是写了个算法,对文字长度进行填充或截断,效果很不错: 调用代码: using (var g = tabs.CreateGraphics()) { tabPage.Text = " " + PadA 阅读全文

posted @ 2024-07-16 13:34 空明流光 阅读(28) 评论(0) 推荐(1) 编辑

2024年5月28日

nuget 离线使用方法

摘要: 要从另一项目导入nuget包,找到 packages 目录完整路径 在 nuget 管理页面,设置源那里增加一个源,路径设置为 packages 的完整路径,名子随便起 然后,选择这个源,就可以选择安装其中包含的nuget包了 阅读全文

posted @ 2024-05-28 16:03 空明流光 阅读(173) 评论(0) 推荐(0) 编辑

2024年5月26日

c# 通过 SendMessage 实现跨进程数据通信

摘要: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System. 阅读全文

posted @ 2024-05-26 18:47 空明流光 阅读(172) 评论(0) 推荐(0) 编辑

2024年5月17日

Uri.EscapeDataString 和 Server.UrlEncoding 的区别

摘要: 今天在iis中访问一个即含有空格又含有#的文件名时,通过 iis 直接访问都无法到达,显示404,即便是 urlencode 文件名后依然无济于事,最后通过 gpt 问到了答案。 Uri.EscapeDataString和Server.UrlEncode是.NET Framework中用于URL编码 阅读全文

posted @ 2024-05-17 14:41 空明流光 阅读(161) 评论(0) 推荐(0) 编辑

2024年5月7日

.net maui tts 文本朗读

摘要: // 定义朗读文本 string text = "这是我的应用程序!"; // 获取可用的朗读人 var locales = await TextToSpeech.GetLocalesAsync(); // 选择特定的朗读人var chosenLocale = locales.FirstOrDefa 阅读全文

posted @ 2024-05-07 13:43 空明流光 阅读(94) 评论(0) 推荐(0) 编辑

导航