Quantcast
Channel: 木子屋 - Win编程
Browsing all 206 articles
Browse latest View live

Image may be NSFW.
Clik here to view.

C#获取本机安装的所有打印机名称

复制内容到剪贴板 程序代码using System;using System.Drawing.Printing;using System.Windows.Forms;namespace WindowsFormsApplication1{    public partial class Form1 : Form    {        public Form1()        {...

View Article


Image may be NSFW.
Clik here to view.

58热敏小票打印机走纸测试

1.打印文本复制内容到剪贴板 程序代码private void printDocument1_PrintPage(object sender, PrintPageEventArgs e){    Font font = new Font("宋体", 12);    Brush brush = Brushes.Black;    e.Graphics.DrawString("要打印的字符",...

View Article


Image may be NSFW.
Clik here to view.

WinForm分多页打印示例

复制内容到剪贴板 程序代码using System;using System.Drawing;using System.Drawing.Printing;using System.Windows.Forms;namespace WindowsFormsApplication1{    public partial class Form1 : Form    {        private...

View Article

Image may be NSFW.
Clik here to view.

WinForm使用单例模式一例

例如在Windows应用程序中用下面代码打开一个窗体:复制内容到剪贴板 程序代码private void button1_Click(object sender, EventArgs e){    (new...

View Article

Image may be NSFW.
Clik here to view.

C#打印时隐藏“正在打印”窗口的方法

C#打印默认会显示“正在打印”窗口:可通过设置PrintDocument.PrintController属性值隐藏“正在打印”窗口:复制内容到剪贴板 程序代码printDocument1.PrintController = new StandardPrintController();

View Article


Image may be NSFW.
Clik here to view.

C#判断传入的路径字符串是文件还是文件夹

复制内容到剪贴板 程序代码static bool IsFile(string path){    return !string.IsNullOrEmpty(Path.GetExtension(path));}当然了,f:\mzwu表示一个没有扩展名的文件也是可能的,有这情况存在的另想办法吧:)

View Article

Image may be NSFW.
Clik here to view.

JSON字符串转C#匿名对象工具

经常需在C#程序中使用第三方接口返回的JSON字符串,针对JSON写一个类太麻烦,Newtonsoft.Json有一个方法可以将JSON字符串转为C#匿名对象:复制内容到剪贴板 程序代码public static T DeserializeAnonymousType<T>(string value, T...

View Article

Image may be NSFW.
Clik here to view.

RichTextBox控件添加指定颜色文本示例

复制内容到剪贴板 程序代码private void Form1_Load(object sender, EventArgs e){    AppendText(richTextBox1, "红", Color.FromArgb(255, 0, 0));    AppendText(richTextBox1, "橙", Color.FromArgb(255, 125, 0));...

View Article


Image may be NSFW.
Clik here to view.

RichTextBox.Find遍历搜索字符串中的坑

RichTextBox.Find遍历搜索字符串有两个重载方法可供调用:复制内容到剪贴板 程序代码public int Find(string str, int start, RichTextBoxFinds options);public int Find(string str, int start, int end, RichTextBoxFinds...

View Article


Image may be NSFW.
Clik here to view.

LINQ to Entities使用表达式树生成的SQL语句比较

不使用表达式树:复制内容到剪贴板 程序代码var query = context.People.Where(item => item.Age == 20); 引用内容Select     [Extent1].[Id] AS [Id],     [Extent1].[Name] AS [Name],     [Extent1].[Age] AS [Age]    FROM...

View Article

Image may be NSFW.
Clik here to view.

WPF应用程序入口函数(Main函数)小结

Windows窗体应用程序的入口函数在Program.cs文件中,但WPF应用程序没有这个文件,WPF应用程序入口函数在哪里呢?手工添加一个入口函数,生成项目,出错:原来WPF应用程序入口函数在obj\Release\App.g.cs文件中:复制内容到剪贴板 程序代码public partial class App : System.Windows.Application {...

View Article

Image may be NSFW.
Clik here to view.

C#事件防止重复注册和移除全部事件示例

复制内容到剪贴板 程序代码public class WebBrowserEventManager{    private EventHandlerList _ehList = new EventHandlerList();    private WebBrowser _wb = null;    /// <summary>    /// 构造函数    ///...

View Article

Image may be NSFW.
Clik here to view.

WebBrowser.DocumentText中文乱码解决方法

复制内容到剪贴板 程序代码Encoding encoding = Encoding.UTF8; //页面编码using (StreamReader stream = new StreamReader(webBrowser1.DocumentStream, encoding)){    textBox1.Text = stream.ReadToEnd();}

View Article


Image may be NSFW.
Clik here to view.

Application.DoEvents使用示例

例如有下边一段代码,当程序运行后,从点击按钮到退出循环这段时间,整个应用程序将“卡死”,文本框一直空白最后突然显示10000:复制内容到剪贴板 程序代码private void button1_Click(object sender, EventArgs e){    for (int i = 1; i <= 10000; i++)    {        textBox1.Text =...

View Article

Image may be NSFW.
Clik here to view.

Winform窗体最大化遮盖系统任务栏解决方法

今天将一个Winform窗体设计成最大化后,运行发现它遮盖了系统任务栏,经多次测试发现原来是同时禁用了最大化按钮且设置窗体边框样式为FormBorderStyle.FixedSingle才会出现这种情况:复制内容到剪贴板 程序代码private void Form1_Load(object sender, EventArgs e){    this.MaximizeBox = false;...

View Article


Image may be NSFW.
Clik here to view.

多次创建WebBrowser控件会导致应用程序占用内存居高不下

今天发现刚写的WinForm应用程序占用内存不正常,经分析测试发现是由于多次创建WebBrowser控件导致,为了便于说明问题,下边是简化后的代码:Form1.cs:复制内容到剪贴板 程序代码public partial class Form1 : Form{    public Form1()    {        InitializeComponent();    }    private...

View Article

Image may be NSFW.
Clik here to view.

CYQ.Data开源数据层框架使用示例

一、准备工具创建Sqlite数据库test.db,添加表Person:复制内容到剪贴板 程序代码Create TABLE Person (    Id   INTEGER PRIMARY KEY AUTOINCREMENT                 UNIQUE                 NOT NULL,    Name TEXT    NOT NULL,    Age...

View Article


Image may be NSFW.
Clik here to view.

NuGet安装旧版本程序包的方法

NuGet默认只能安装最新版本程序包,如果需要旧版本程序包,只能通过程序包管理控制台来安装:常用命令复制内容到剪贴板 程序代码Install-Package PackageName [-Version <string>] [-IgnoreDependencies]Uninstall-Package PackageName...

View Article

Image may be NSFW.
Clik here to view.

EntityFramework 6连接Sqlite数据库示例

第一步:在NuGet安装System.Data.Sqlite程序包第二步:生成实体类我试了很多次,尝试用Entity Framework Power Tools Beta 4连接Sqlite生成实体类,但都失败了,最后的解决办法是在SQL Server创建一个相同结构的库,EF Power Tools连接SQL Server生成实体类,生成完后记得修改配置文件中数据库连接字符串:复制内容到剪贴板...

View Article

EntityFramework各版本历史记录

EF 6.1.2EF6.1.2 is mostly about bug fixes, you can see a list of the fixes included in EF6.1.2 on our CodePlex site.We also accepted a couple of noteworthy changes from members of the community:...

View Article
Browsing all 206 articles
Browse latest View live