快捷搜索:  汽车  科技

csharp隐藏的控件能显示吗(电脑绝技教你22天学精Csharp之第十五天winform应用程序补充7)

csharp隐藏的控件能显示吗(电脑绝技教你22天学精Csharp之第十五天winform应用程序补充7)using System.IO;using System.Drawing;using System.Collections.Generic;using System.ComponentModel;using System.Data;

csharp隐藏的控件能显示吗(电脑绝技教你22天学精Csharp之第十五天winform应用程序补充7)(1)

csharp隐藏的控件能显示吗(电脑绝技教你22天学精Csharp之第十五天winform应用程序补充7)(2)

14、记事儿本应用程序

csharp隐藏的控件能显示吗(电脑绝技教你22天学精Csharp之第十五天winform应用程序补充7)(3)

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace _14_记事儿本应用程序

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender EventArgs e)

{

//加载程序的时候 隐藏panel

panel1.Visible = false;

//取消文本框的自动换行功能

textBox1.WordWrap = false;

}

/// <summary>

/// 点击按钮的时候 隐藏panel

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void button1_Click(object sender EventArgs e)

{

panel1.Visible = false;

}

private void 显示ToolStripMenuItem_Click(object sender EventArgs e)

{

panel1.Visible = true;

}

private void 影藏ToolStripMenuItem_Click(object sender EventArgs e)

{

panel1.Visible = false;

}

List<string> list = new List<string>();

/// <summary>

/// 打开对话框

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void 打开ToolStripMenuItem_Click(object sender EventArgs e)

{

OpenFileDialog ofd = new OpenFileDialog();

ofd.Title = "请选择要打开的文本文件";

ofd.InitialDirectory = @"C:\Users\SpringRain\Desktop";

ofd.Multiselect = true;

ofd.Filter = "文本文件|*.txt|所有文件|*.*";

ofd.ShowDialog();

//获得用户选中的文件的路径

string path = ofd.FileName;

//将文件的全路径存储到泛型集合中

list.Add(path);

//获得了用户打开文件的文件名

string fileName = Path.GetFileName(path);

//将文件名放到ListBox中

listBox1.Items.Add(fileName);

if (path == "")

{

return;

}

using (FileStream fsRead = new FileStream(path FileMode.OpenOrCreate FileAccess.Read))

{

byte[] buffer = new byte[1024 * 1024 * 5];

int r = fsRead.Read(buffer 0 buffer.Length);

textBox1.Text = Encoding.Default.GetString(buffer 0 r);

}

}

/// <summary>

/// 保存对话框

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void 保存ToolStripMenuItem_Click(object sender EventArgs e)

{

SaveFileDialog sfd = new SaveFileDialog();

sfd.InitialDirectory = @"C:\Users\SpringRain\Desktop";

sfd.Title = "请选择要保存的文件路径";

sfd.Filter = "文本文件|*.txt|所有文件|*.*";

sfd.ShowDialog();

//获得用户要保存的文件的路径

string path = sfd.FileName;

if (path == "")

{

return;

}

using (FileStream fsWrite = new FileStream(path FileMode.OpenOrCreate FileAccess.Write))

{

byte[] buffer = Encoding.Default.GetBytes(textBox1.Text);

fsWrite.Write(buffer 0 buffer.Length);

}

MessageBox.Show("保存成功");

}

private void 自动换行ToolStripMenuItem_Click(object sender EventArgs e)

{

if (自动换行ToolStripMenuItem.Text == "☆自动换行")

{

textBox1.WordWrap = true;

自动换行ToolStripMenuItem.Text = "★取消自动换行";

}

else if (自动换行ToolStripMenuItem.Text == "★取消自动换行")

{

textBox1.WordWrap = false;

自动换行ToolStripMenuItem.Text = "☆自动换行";

}

}

private void 字体ToolStripMenuItem_Click(object sender EventArgs e)

{

FontDialog fd = new FontDialog();

fd.ShowDialog();

textBox1.Font = fd.Font;

}

private void 颜色ToolStripMenuItem_Click(object sender EventArgs e)

{

ColorDialog cd = new ColorDialog();

cd.ShowDialog();

textBox1.ForeColor = cd.Color;

}

/// <summary>

/// 双击打开对应的文件

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void listBox1_DoubleClick(object sender EventArgs e)

{

//要获得双击的文件所对应的全路径

string path = list[listBox1.SelectedIndex];

using (FileStream fsRead = new FileStream(path FileMode.OpenOrCreate FileAccess.Read))

{

byte[] buffer = new byte[1024 * 1024 * 5];

int r = fsRead.Read(buffer 0 buffer.Length);

textBox1.Text = Encoding.Default.GetString(buffer 0 r);

}

}

}

}

15进程

using System;

using System.Collections.Generic;

using System.Diagnostics;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace _15进程

{

class Program

{

static void Main(string[] args)

{

//获得当前程序中所有正在运行的进程

//Process[] pros = Process.GetProcesses();

//foreach (var item in pros)

//{

// //不试的不是爷们

// //item.Kill();

// Console.WriteLine(item);

//}

//通过进程打开一些应用程序

//Process.Start("calc");

//Process.Start("mspaint");

//Process.Start("notepad");

//Process.Start("iexplore" "http://www.baidu.com");

//通过一个进程打开指定的文件

ProcessStartInfo psi = new ProcessStartInfo(@"C:\Users\SpringRain\Desktop\1.exe");

//第一:创建进程对象

Process p = new Process();

p.StartInfo = psi;

p.Start();

// p.star

Console.ReadKey();

}

}

}

16、线程

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading;

using System.Threading.Tasks;

namespace _16_线程

{

class Program

{

static void Main(string[] args)

{

Thread.Sleep(3000);

Console.WriteLine("Hello World");

Console.ReadKey();

}

}

}

17、线程

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace _17_线程

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

Thread th;

private void button1_Click(object sender EventArgs e)

{

//创建一个线程去执行这个方法

th = new Thread(Test);

//标记这个线程准备就绪了,可以随时被执行。具体什么时候执行这个线程,

//由cpu决定

//将线程设置为后台线程

th.IsBackground = true;

th.Start();

th.Abort();

th.Start();

}

private void Test()

{

for (int i = 0; i < 10000; i )

{

//Console.WriteLine(i);

textBox1.Text = i.ToString();

}

}

private void Form1_Load(object sender EventArgs e)

{

//取消跨线程的访问

Control.CheckForIllegalCrossThreadCalls = false;

}

private void Form1_FormClosing(object sender FormClosingEventArgs e)

{

//当你点击关闭窗体的时候,判断新线程是否为null

if (th != null)

{

//结束这个线程

th.Abort();

}

}

}

}

csharp隐藏的控件能显示吗(电脑绝技教你22天学精Csharp之第十五天winform应用程序补充7)(4)


猜您喜欢: