private void menuItemSaveHtml_Click(object sender, EventArgs e) { if (!this.isHtmlTarget) { DialogResult result = MessageBox.Show(this, "このAAは「MS Pゴシック 12Pt 行間 2ピクセル」ではないため、HTMLにした場合にズレが発生します。\r\n\r\n続行しますか?", "メッセージ", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result != DialogResult.OK) { return; } } this.saveFileDialog.Filter = "HTML (*.html) | *.html"; this.saveFileDialog.DefaultExt = "html"; string filename = new FileInfo(this.mm.FileName).Name; if (filename.LastIndexOf('.') >= 0) { filename = filename.Substring(0, filename.LastIndexOf('.')); } filename = filename + "_AA"; this.saveFileDialog.FileName = filename; string s1_UTF = "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<title>アスキーアート</title>\n</head>\n<body style=\"font-family:'MS Pゴシック';font-size:16px;line-height:18px;\">"; string s1_SJIS = "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-31J\">\n<title>アスキーアート</title>\n</head>\n<body style=\"font-family:'MS Pゴシック';font-size:16px;line-height:18px;\">"; string s2 = "</body>\n</html>"; string s = this.aa.Replace("<", "<").Replace(">", ">").Replace("\r\n", "<br>\r\n"); //Debug.Write(s.IndexOf("\n")); //saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string charSet = ""; if (this.saveFileDialog.InitialDirectory == "") { this.saveFileDialog.InitialDirectory = Application.StartupPath + "\\"; } if (CustomSaveCharFileDialog.Save(this.saveFileDialog, this, ref charSet) == DialogResult.OK) { using (StreamWriter sw = new StreamWriter(saveFileDialog.FileName, false, Encoding.GetEncoding(charSet))) { if (charSet == "UTF-8") { sw.WriteLine(s1_UTF); } else { sw.WriteLine(s1_SJIS); } sw.WriteLine(s); sw.WriteLine(s2); } } }
private void menuItemSaveTxt_Click(object sender, EventArgs e) { this.saveFileDialog.Filter = "テキスト(*.txt)|*.txt"; this.saveFileDialog.DefaultExt = ".txt"; string filename = new FileInfo(this.mm.FileName).Name; if (filename.LastIndexOf('.') >= 0) { filename = filename.Substring(0, filename.LastIndexOf('.')); } filename = filename + "_AA"; this.saveFileDialog.FileName = filename; if (this.saveFileDialog.InitialDirectory == "") { this.saveFileDialog.InitialDirectory = Application.StartupPath + "\\"; } string charSet = ""; if (CustomSaveCharFileDialog.Save(this.saveFileDialog, this, ref charSet) == DialogResult.OK) { filename = this.saveFileDialog.FileName; using (StreamWriter sw = new StreamWriter(filename, false, Encoding.GetEncoding(charSet))) { sw.Write(this.aa); } } }