📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool AnimateWindow(IntPtr hwnd, uint dwTime, uint dwFlags);
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, System.Int32 dwRop);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox2.Text = "";
if (textBox1.Text == "")
{ textBox1.Text = "默认字符"; }
int line = 8;
int colum = 8;
try
{
line = int.Parse(textBox3.Text);
colum = int.Parse(textBox4.Text);
if (line == 0 || colum == 0)
{ line = 8; colum = 8; textBox3.Text = "8"; textBox4.Text = "8"; return; }
}
catch { line = 8; colum = 8; textBox3.Text = "8"; textBox4.Text = "8"; return; }
string a = textBox1.Text;
HandleWarp(ref a, line);
a = Microsoft.VisualBasic.Strings.StrConv(a, Microsoft.VisualBasic.VbStrConv.Wide, 0);
string s = MakeItLooksLikeAncientChinese(a, line, colum);
textBox2.Text += s;
}
private void HandleWarp(ref string a, int line)
{
while (a.Contains("\n"))
{
int index = a.IndexOf("\n");
string temp = new string(' ', line - index % line);//
a = a.Insert(index + 1, temp);
a = a.Remove(index, 1);
}
}
private string MakeItLooksLikeAncientChinese(string origin, int line, int colum)
{
char[] ori = origin.ToCharArray();
char[] after = new char[line * (colum * 2 + 1) + line + 1];
for (int i = 1; i <= line * (colum * 2 + 1) + line + 1; i++)
{
after[i - 1] = '┊';
}
for (int i = 1; i <= line; i++)
{
after[colum * 2 + 1 + (i - 1) * (colum * 2 + 2)] = '\n';
}
after[line * (colum * 2 + 1) + line] = '\n';
bool flag = false;
for (int i = 1, count = 0, off = 0; i <= colum; i++, off += 2)
{
for (int j = 1; j <= line; j++, count++)
{
if (count < ori.Length)
{ after[colum * 2 - 1 - off + (colum * 2 + 2) * (j - 1)] = ori[count]; }
else
{
after[colum * 2 - 1 - off + (colum * 2 + 2) * (j - 1)] = ' ';
flag = true;
}
}
}
textBox2.Text += new string(after);
if (!flag)
{
origin = origin.Remove(0, colum * line);
MakeItLooksLikeAncientChinese(origin, line, colum);
return "SWPU 烟锁重楼";
}
else { return "SWPU 烟锁重楼"; }
}
private void Form1_Load(object sender, EventArgs e)
{
AnimateWindow(this.Handle, 600, 0x00000001 | 0x00020000);
button1_Click(new object(), new EventArgs());
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
AnimateWindow(this.Handle, 600, 0x00000002 | 0x00010000);
}
private void button2_Click(object sender, EventArgs e)
{
try{System.Windows.Forms.Clipboard.SetText(textBox2.Text);}
catch { }
}
private void button3_Click(object sender, EventArgs e)
{
FontDialog f = new FontDialog();
f.Font = textBox2.Font;
f.ShowDialog();
textBox2.Font = f.Font;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
button1_Click(new object(), new EventArgs());
}
private void button1_Click_1(object sender, EventArgs e)
{
textBox2.Text = Microsoft.VisualBasic.Strings.StrConv(textBox2.Text, Microsoft.VisualBasic.VbStrConv.TraditionalChinese, 0);
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
button1_Click(new object(), new EventArgs());
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
button1_Click(new object(), new EventArgs());
}
private void button4_Click(object sender, EventArgs e)
{
Graphics g1 = textBox2.CreateGraphics();//获得窗体图形对象
Image MyImage = new Bitmap(textBox2.Width, textBox2.Height, g1);
Graphics g2 = Graphics.FromImage(MyImage);//创建位图图形对象
IntPtr dc1 = g1.GetHdc();//获得窗体的上下文设备
IntPtr dc2 = g2.GetHdc();//获得位图文件的上下文设备
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);//写入到位图
g1.ReleaseHdc(dc1);//释放窗体的上下文设备
g2.ReleaseHdc(dc2);//释放位图文件的上下文设备
if (ofd.ShowDialog() == DialogResult.OK)
{
MyImage.Save(ofd.FileName, ImageFormat.Jpeg);//保存为jpeg文件
MessageBox.Show("保存图片结束!");
}
}
private void button6_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("IEXPLORE.EXE", "http://blog.csdn.net/cuipengfei1");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -