📄 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 mshtml;
using System.IO;
namespace _111
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//object zero = 0;
//object es = "";
//axWebBrowser1.Navigate(textBox1.Text, ref zero, ref es, ref es, ref es);
//openFileDialog1.ShowDialog();
//OpenFileDialog ofd = new OpenFileDialog();
//ofd.Title = "打开(Open)";
//ofd.FileName = "";
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "打开(Open)";
ofd.FileName = "";
ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);//确定打开的初始位置在MyDocuments文件夹
//MessageBox.Show(ofd.InitialDirectory.ToString());//显示浏览界面的初始路径
//为了获取特定的系统文件夹,可以使用System.Environment类
//的静态方法GetFolderPath()。该方法接受一个Environment.SpecialFolder枚举,其中可以定义要返回路径的哪个系统目录
ofd.Filter = "文本文件(*.txt)|*.txt";
ofd.ValidateNames = true; //文件有效性验证ValidateNames,验证用户输入是否是一个有效的Windows文件名
ofd.CheckFileExists = true; //验证路径有效性
ofd.CheckPathExists = true; //验证文件有效性
try
{
if (ofd.ShowDialog() == DialogResult.OK)
{
StreamReader sr = new StreamReader(ofd.FileName, System.Text.Encoding.Default);
this.textBox1.Text = sr.ReadToEnd();
MessageBox.Show(ofd.FileName.ToString());//显示打开文件的路径
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
private void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
IHTMLDocument2 IHTMLDocument = (IHTMLDocument2)axWebBrowser1.Document;
IHTMLElementCollection links = IHTMLDocument.links;
listBox1.Items.Clear();
foreach (HTMLAnchorElementClass el in links)
{
listBox1.Items.Add(el.outerHTML);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -