当前位置: 首页 > news >正文

网站开发与网页制作网站规划项目与设计实例

网站开发与网页制作,网站规划项目与设计实例,官网网站建设方案书,网站怎么做登陆WPF 并没有内置FontDialog和ColorDialog,但可以通过引用 Windows Forms 的控件来实现字体和颜色选择对话框功能。FontDialog 允许用户选择字体、样式、大小等设置。 添加 Windows Forms的引用 项目工程:右键“引用”》“添加引用”》勾选System.Window…

WPF 并没有内置FontDialog和ColorDialog,但可以通过引用 Windows Forms 的控件来实现字体和颜色选择对话框功能。FontDialog 允许用户选择字体、样式、大小等设置。

添加 Windows Forms的引用

  1. 项目工程:右键“引用”=》“添加引用”=》勾选System.Windows.Forms
    在这里插入图片描述
  2. 浏览选择System.Windows.Forms.dll动态库文件
    默认路径:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework
    在这里插入图片描述
    3.添加成功
    在这里插入图片描述
  • 在C# WPF应用程序中,不能直接使用System.Drawing.Font,因为System.Drawing.Font是Windows Forms的一部分,而不是WPF。WPF使用System.Windows.Media.FontFamily来表示字体。需要做相应的转换才可以使用;
  • WinForm中的Color( System.Drawing.Color)与Wpf中Color(System.Windows.Media.Color)也需要要相互转换才能使用;

代码示例

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;
using System.Windows.Forms;namespace WpfColorFontDialog
{/// <summary>/// MainWindow.xaml 的交互逻辑/// </summary>public partial class MainWindow : Window{public MainWindow(){InitializeComponent();}private void btnSetFont_Click(object sender, RoutedEventArgs e){System.Windows.Forms.FontDialog fontDialog = new System.Windows.Forms.FontDialog();if (fontDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK){// System.Drawing.Font DFont = new System.Drawing.Font("宋体", 10, System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic);System.Drawing.Font drawingFont = fontDialog.Font;FontFamily fontFamily = new FontFamily(drawingFont.Name);double fontSize = drawingFont.Size;FontWeight fontWeight = FontWeights.Bold;if (drawingFont.Bold){fontWeight = FontWeights.Bold;}else {fontWeight = FontWeights.Normal;}FontStyle fontStyle = (drawingFont.Style & System.Drawing.FontStyle.Italic) != 0 ? FontStyles.Italic : FontStyles.Normal;txtBlock.FontFamily = fontFamily;txtBlock.FontSize = fontSize;txtBlock.FontStyle = fontStyle;txtBlock.FontWeight = fontWeight;}}private void btnSetColor_Click(object sender, RoutedEventArgs e){System.Windows.Forms.ColorDialog colorDialog = new System.Windows.Forms.ColorDialog();if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK){System.Windows.Media.Color MColor = new System.Windows.Media.Color();MColor = System.Windows.Media.Color.FromArgb(colorDialog.Color.A, colorDialog.Color.R, colorDialog.Color.G, colorDialog.Color.B);System.Windows.Media.Brush BColor = new SolidColorBrush(MColor);txtBlock.Background = BColor;}}}
}

在这里插入图片描述
在这里插入图片描述

http://www.yayakq.cn/news/120148/

相关文章:

  • 网站建设确认单四川省建行网站
  • 深圳网站制作的公司排名网站建设技术风险
  • 无锡网站建设哪家专业网站邮箱接口怎么设置
  • 如何给公司做自己的网站搜索网站logo怎么做
  • 网站平台建设及运营推广策划方案做电话销售需要的网站
  • 福鼎网站优化公司自己学习做网站
  • 网站建设 工作室网站微建站
  • 保山做网站建设wordpress模板设置
  • 免费零食网站模板在统计局网站上如何做图表
  • 保定网站推广多少钱棋牌软件开发平台
  • 化妆品电商网站模板网页制作与设计讨论
  • 网站镜像代理怎么做小规模公司简介怎么写
  • 网站关键词快速排名工具网站建设开发怎么选专业
  • 有那个网站做简历模板2017响应式网站 全站
  • 网站栏目页描述怎么写做百度推广送的网站
  • 有没有通信专业业余做兼职的网站免费自学平面设计的网站
  • 做plc课程设计的网站免费网站安全检测
  • 商城网站建设功能点价格做静态头像网站
  • 做经营网站怎么赚钱吗做网站选哪个语言
  • 简要列举网站常见类型工信部网站备案流程
  • 中国空间站对接成功南阳网站改版
  • 买机箱网站免费生成短链接
  • 做淘宝店铺标志的网站盐城网站开发公司电话
  • 网络设计是什么工作麻城seo
  • 建设银行网上营业厅官方网站下载网站建设与维护就业怎么样
  • 网站字体样式东莞市公司网站建设服务机构
  • 如何做别人的网站线上设计师做效果图
  • 网站制作的常见问题wordpress输出
  • 珠海专业网站建设长沙市门户网站建设
  • 公司增加英文网站要怎么做建设局是什么单位