C#のサンプルコードです。C#も参照のこと。
26-日付の無い日記と2012-09-17より。
タブブラウザ。
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public List<WebBrowser> allWebsList;
public Form1()
{
InitializeComponent();
allWebsList = new List<WebBrowser>();
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
// タブコントロールに新しいタブとブラウザを作成する
WebBrowser web;
TabPage newTabPage;
web = new WebBrowser();
allWebsList.Add(web);
web.Dock = DockStyle.Fill;
newTabPage = new TabPage();
newTabPage.Controls.Add(web);
tabControl1.Controls.Add(newTabPage);
web.GoHome();
}
}
}
デザイナの方では、toolStrip1、tabControl1、toolStripButton1、Form1を作ってください。
デザイナで作成したコード。Form1.Designer.cs。
namespace WindowsFormsApplication1
{
partial class Form1
{
/// <summary>
/// 必要なデザイナー変数です。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 使用中のリソースをすべてクリーンアップします。
/// </summary>
/// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows フォーム デザイナーで生成されたコード
/// <summary>
/// デザイナー サポートに必要なメソッドです。このメソッドの内容を
/// コード エディターで変更しないでください。
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
this.toolStrip1.SuspendLayout();
this.SuspendLayout();
//
// toolStrip1
//
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripButton1});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(284, 25);
this.toolStrip1.TabIndex = 0;
this.toolStrip1.Text = "toolStrip1";
//
// tabControl1
//
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 25);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(284, 237);
this.tabControl1.TabIndex = 1;
//
// toolStripButton1
//
this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image")));
this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripButton1.Name = "toolStripButton1";
this.toolStripButton1.Size = new System.Drawing.Size(23, 22);
this.toolStripButton1.Text = "toolStripButton1";
this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.tabControl1);
this.Controls.Add(this.toolStrip1);
this.Name = "Form1";
this.Text = "Form1";
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.ToolStripButton toolStripButton1;
private System.Windows.Forms.TabControl tabControl1;
}
}
この前自分で作った、<p>にid="行番号"をつけるプログラム。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
RepA("st.html");
RepA("pm.html");
RepA("tx.html");
RepA("hs.html");
RepA("mm.html");
RepA("sk.html");
RepA("lt.html");
RepA("cp.html");
RepA("sc.html");
RepA("etc.html");
RepA("hs2.html");
RepB("lt2.html");
RepB("sk2.html");
RepB("hs3.html");
RepB("cp2.html");
RepB("lg.html");
RepB("sc2.html");
RepB("tg.html");
RepB("ms.html");
RepB("etc2.html");
RepB("tg2.html");
RepB("sk3.html");
RepB("cp3.html");
RepB("lt3.html");
RepB("tx2.html");
}
static void __RepCore(string strin, string pat)
{
string str = "";
Encoding enc = Encoding.GetEncoding(932);
using (StreamReader r = new StreamReader(strin, enc))
{
string line;
int c = 0;
while ((line = r.ReadLine()) != null) // 1行ずつ読み出し。
{
string mc;
if (Regex.IsMatch(line, pat))
{
mc = Regex.Replace(line, @"", "<p id=\"" + (c + 1) + "\">");
str += mc + "\n";
c++;
}
else
{
mc = line;
str += mc + "\n";
c++;
}
}
}
// ファイルにテキストを書き出し。
using (StreamWriter w = new StreamWriter(strin + ".o.html", false, enc))
{
w.WriteLine(str);
}
}
static void RepA(string strin)
{
__RepCore(strin, "----");
}
static void RepB(string strin)
{
__RepCore(strin, "◇◇");
}
}
}
Regexの使い方が馬鹿だ。
あとは、僕はxyzzyを使う。
正規表現のメモ。
検索:<p id="\(.*\)">----\n<p>\(.*\)
検索:<p id="\(.*\)">◇◇\n<p>\(.*\)
置換:<a href="tx2.html#\1">\2</a>,\n
検索:<p>[\n|].*$
検索:<p>.*$
検索:^\n$
検索: ..:..
----か◇◇で始まる行を、その行のpタグのid属性と次の行の内容でリンクに変換します。