C# WindowsForm エクスプローラ Form1.Designer.cs ― 2022年08月25日 11:55
namespace myExprore
{
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.panel1 = new System.Windows.Forms.Panel();
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.panel2 = new System.Windows.Forms.Panel();
this.explorerBrowser1 = new Microsoft.WindowsAPICodePack.Controls.WindowsForms.ExplorerBrowser();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.BackColor = System.Drawing.SystemColors.Control;
this.panel1.Controls.Add(this.button1);
this.panel1.Controls.Add(this.textBox1);
this.panel1.Location = new System.Drawing.Point(-1, -1);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(830, 30);
this.panel1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(3, 4);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "Navigate";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(84, 6);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(738, 19);
this.textBox1.TabIndex = 0;
//
// panel2
//
this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel2.BackColor = System.Drawing.Color.YellowGreen;
this.panel2.Controls.Add(this.explorerBrowser1);
this.panel2.Location = new System.Drawing.Point(-1, 29);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(830, 669);
this.panel2.TabIndex = 1;
//
// explorerBrowser1
//
this.explorerBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
this.explorerBrowser1.Location = new System.Drawing.Point(0, 0);
this.explorerBrowser1.Name = "explorerBrowser1";
this.explorerBrowser1.PropertyBagName = "Microsoft.WindowsAPICodePack.Controls.WindowsForms.ExplorerBrowser";
this.explorerBrowser1.Size = new System.Drawing.Size(830, 669);
this.explorerBrowser1.TabIndex = 0;
this.explorerBrowser1.NavigationComplete += new System.EventHandler<Microsoft.WindowsAPICodePack.Controls.NavigationCompleteEventArgs>(this.explorerBrowser1_NavigationComplete);
this.explorerBrowser1.SelectionChanged += new System.EventHandler(this.explorerBrowser1_SelectionChanged);
//
// statusStrip1
//
this.statusStrip1.Location = new System.Drawing.Point(0, 701);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(833, 22);
this.statusStrip1.TabIndex = 2;
this.statusStrip1.Text = "statusStrip1";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(833, 723);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "Form1";
this.Shown += new System.EventHandler(this.Form1_Shown);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.StatusStrip statusStrip1;
private Microsoft.WindowsAPICodePack.Controls.WindowsForms.ExplorerBrowser explorerBrowser1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
}
}
C# WindowsForm メディアプレイヤー Form1.cs ― 2022年08月25日 11:53
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace myWMPlayer
{
public partial class Form1 : Form
{
WMPLib.IWMPPlaylist myplaylist;
WMPLib.IWMPMedia songs;
string strFileName;
public Form1(string[] args)
{
InitializeComponent();
myplaylist = axWindowsMediaPlayer1.playlistCollection.newPlaylist("myplaylist");// プレイリストを作成
axWindowsMediaPlayer1.currentPlaylist = myplaylist;// プレイリストをメディアプレイヤーに設定
axWindowsMediaPlayer1.settings.enableErrorDialogs = true;
axWindowsMediaPlayer1.settings.setMode("shuffle", false);// シャッフル再生する場合は true。しない場合は false。
if (args.Length > 0)
{
songs = axWindowsMediaPlayer1.newMedia(args[0]);
myplaylist.appendItem(songs);// プレイリストにファイル追加
plyToList();
}
}
private void fileToPly()// ファイルをプレイリストにセット
{
foreach (string strFilePath in openFileDialog1.FileNames)//複数選択したファイル分だけ繰り返す
{
songs = axWindowsMediaPlayer1.newMedia(strFilePath);
myplaylist.appendItem(songs);// プレイリストにファイル追加
}
plyToList();
}
private void plyToList()// リストボックスにプレイリスト内のファイル名を表示
{
listBox1.Items.Clear();
for (int i = 0; i <= myplaylist.count - 1; i++)
{
listBox1.Items.Add(System.IO.Path.GetFileName(myplaylist.Item[i].sourceURL));
}
if (myplaylist.count >= 2)
{
btnSHazusu.Enabled = true;
btnEHazusu.Enabled = true;
}
else
{
btnSHazusu.Enabled = false;
btnEHazusu.Enabled = false;
}
}
private void btnOpen_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
//MessageBox.Show(openFileDialog1.FileName,"Infomation",MessageBoxButtons.OK,MessageBoxIcon.Information);
//axWindowsMediaPlayer1.URL = @"C:\myC\myWMPlayer\deta\制服_オールナイトニッポンより.mp4";
//axWindowsMediaPlayer1.URL = openFileDialog1.FileName;
this.Text = System.IO.Path.GetDirectoryName(openFileDialog1.FileName);
fileToPly();
btnTuika.Enabled = true;
timer1.Enabled = true;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = axWindowsMediaPlayer1.currentMedia.durationString;
toolStripStatusLabel2.Text = axWindowsMediaPlayer1.Ctlcontrols.currentPositionString;
toolStripStatusLabel3.Text = System.IO.Path.GetFileName(axWindowsMediaPlayer1.currentMedia.sourceURL);
}
private void btnTuika_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
fileToPly();
}
}
private void btnEHazusu_Click(object sender, EventArgs e)
{
myplaylist.removeItem(myplaylist.Item[myplaylist.count - 1]); //最後のアイテムを削除
plyToList();
}
private void btnSHazusu_Click(object sender, EventArgs e)
{
myplaylist.removeItem(myplaylist.Item[0]); //先頭のアイテムを削除
plyToList();
}
private void listBox1_DragOver(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void listBox1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] drpfiles = (string[])e.Data.GetData(DataFormats.FileDrop);
string drpfilePath;
for (int i = 0; i < drpfiles.Length; i++)
{
drpfilePath = drpfiles[i];
songs = axWindowsMediaPlayer1.newMedia(drpfilePath);
myplaylist.appendItem(songs);// プレイリストにファイル追加
}
plyToList();
}
}
}
}
C# WindowsForm メディアプレイヤー Form1.Designer.cs ― 2022年08月25日 11:52
namespace myWMPlayer
{
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()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.panel1 = new System.Windows.Forms.Panel();
this.btnSHazusu = new System.Windows.Forms.Button();
this.btnEHazusu = new System.Windows.Forms.Button();
this.btnTuika = new System.Windows.Forms.Button();
this.btnOpen = new System.Windows.Forms.Button();
this.panel2 = new System.Windows.Forms.Panel();
this.panel4 = new System.Windows.Forms.Panel();
this.listBox1 = new System.Windows.Forms.ListBox();
this.panel3 = new System.Windows.Forms.Panel();
this.axWindowsMediaPlayer1 = new AxWMPLib.AxWindowsMediaPlayer();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabel2 = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabel3 = new System.Windows.Forms.ToolStripStatusLabel();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.panel4.SuspendLayout();
this.panel3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.axWindowsMediaPlayer1)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
this.openFileDialog1.Multiselect = true;
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.White;
this.panel1.Controls.Add(this.btnSHazusu);
this.panel1.Controls.Add(this.btnEHazusu);
this.panel1.Controls.Add(this.btnTuika);
this.panel1.Controls.Add(this.btnOpen);
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(1127, 26);
this.panel1.TabIndex = 2;
//
// btnSHazusu
//
this.btnSHazusu.Enabled = false;
this.btnSHazusu.Location = new System.Drawing.Point(185, 2);
this.btnSHazusu.Name = "btnSHazusu";
this.btnSHazusu.Size = new System.Drawing.Size(124, 23);
this.btnSHazusu.TabIndex = 3;
this.btnSHazusu.Text = "先頭のファイルを外す";
this.btnSHazusu.UseVisualStyleBackColor = true;
this.btnSHazusu.Click += new System.EventHandler(this.btnSHazusu_Click);
//
// btnEHazusu
//
this.btnEHazusu.Enabled = false;
this.btnEHazusu.Location = new System.Drawing.Point(315, 2);
this.btnEHazusu.Name = "btnEHazusu";
this.btnEHazusu.Size = new System.Drawing.Size(128, 23);
this.btnEHazusu.TabIndex = 2;
this.btnEHazusu.Text = "末尾のファイルを外す";
this.btnEHazusu.UseVisualStyleBackColor = true;
this.btnEHazusu.Click += new System.EventHandler(this.btnEHazusu_Click);
//
// btnTuika
//
this.btnTuika.Enabled = false;
this.btnTuika.Location = new System.Drawing.Point(86, 2);
this.btnTuika.Name = "btnTuika";
this.btnTuika.Size = new System.Drawing.Size(93, 24);
this.btnTuika.TabIndex = 1;
this.btnTuika.Text = "ファイルを追加";
this.btnTuika.UseVisualStyleBackColor = true;
this.btnTuika.Click += new System.EventHandler(this.btnTuika_Click);
//
// btnOpen
//
this.btnOpen.Location = new System.Drawing.Point(3, 2);
this.btnOpen.Name = "btnOpen";
this.btnOpen.Size = new System.Drawing.Size(77, 24);
this.btnOpen.TabIndex = 0;
this.btnOpen.Text = "ファイルを開く";
this.btnOpen.UseVisualStyleBackColor = true;
this.btnOpen.Click += new System.EventHandler(this.btnOpen_Click);
//
// panel2
//
this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel2.BackColor = System.Drawing.SystemColors.Info;
this.panel2.Controls.Add(this.panel4);
this.panel2.Controls.Add(this.panel3);
this.panel2.Location = new System.Drawing.Point(0, 28);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(1124, 512);
this.panel2.TabIndex = 3;
//
// panel4
//
this.panel4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel4.BackColor = System.Drawing.Color.LemonChiffon;
this.panel4.Controls.Add(this.listBox1);
this.panel4.Location = new System.Drawing.Point(901, 3);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(221, 509);
this.panel4.TabIndex = 1;
//
// listBox1
//
this.listBox1.AllowDrop = true;
this.listBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listBox1.FormattingEnabled = true;
this.listBox1.HorizontalScrollbar = true;
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(0, 0);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(221, 509);
this.listBox1.TabIndex = 0;
this.listBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.listBox1_DragDrop);
this.listBox1.DragOver += new System.Windows.Forms.DragEventHandler(this.listBox1_DragOver);
//
// panel3
//
this.panel3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel3.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.panel3.Controls.Add(this.axWindowsMediaPlayer1);
this.panel3.Location = new System.Drawing.Point(3, 3);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(896, 506);
this.panel3.TabIndex = 0;
//
// axWindowsMediaPlayer1
//
this.axWindowsMediaPlayer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.axWindowsMediaPlayer1.Enabled = true;
this.axWindowsMediaPlayer1.Location = new System.Drawing.Point(0, 0);
this.axWindowsMediaPlayer1.Name = "axWindowsMediaPlayer1";
this.axWindowsMediaPlayer1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWindowsMediaPlayer1.OcxState")));
this.axWindowsMediaPlayer1.Size = new System.Drawing.Size(896, 506);
this.axWindowsMediaPlayer1.TabIndex = 0;
//
// statusStrip1
//
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabel1,
this.toolStripStatusLabel2,
this.toolStripStatusLabel3});
this.statusStrip1.Location = new System.Drawing.Point(0, 545);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(1127, 22);
this.statusStrip1.TabIndex = 4;
this.statusStrip1.Text = "statusStrip1";
//
// toolStripStatusLabel1
//
this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
this.toolStripStatusLabel1.Size = new System.Drawing.Size(34, 17);
this.toolStripStatusLabel1.Text = "time";
//
// toolStripStatusLabel2
//
this.toolStripStatusLabel2.Name = "toolStripStatusLabel2";
this.toolStripStatusLabel2.Size = new System.Drawing.Size(31, 17);
this.toolStripStatusLabel2.Text = "now";
//
// toolStripStatusLabel3
//
this.toolStripStatusLabel3.Name = "toolStripStatusLabel3";
this.toolStripStatusLabel3.Size = new System.Drawing.Size(34, 17);
this.toolStripStatusLabel3.Text = "song";
//
// timer1
//
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1127, 567);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "axWindowsMediaPlayer";
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.panel4.ResumeLayout(false);
this.panel3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.axWindowsMediaPlayer1)).EndInit();
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button btnOpen;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel2;
private System.Windows.Forms.Button btnTuika;
private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.Panel panel4;
private AxWMPLib.AxWindowsMediaPlayer axWindowsMediaPlayer1;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel3;
private System.Windows.Forms.Button btnEHazusu;
private System.Windows.Forms.Button btnSHazusu;
}
}
C# WindowsForm メディアプレイヤー Program.cs ― 2022年08月25日 11:50
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace myWMPlayer
{
internal static class Program
{
/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1(args));
}
}
}
C# WPF メモ帳 MainWindow.xaml.cs ― 2022年08月25日 11:40
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Reflection;
namespace WpfMemo
{
/// <summary>
/// MainWindow.xaml の相互作用ロジック
/// </summary>
public partial class MainWindow : Window
{
Boolean _bold = false;
Boolean _italic = false;
Boolean _strike = false;
Boolean _uline = false;
public Dictionary<int, string> Okisa_Dic { get; set; }
public Dictionary<int, string> Haba_Dic { get; set; }
public MainWindow()
{
Okisa_Dic = new Dictionary<int, string>()
{
{10, "10" },
{12, "12" },
{14, "14" },
{16, "16" },
{18, "18" },
{20, "20" },
{22, "22" },
{24, "24" },
{26, "26" },
{28, "28" },
{36, "36" },
{48, "48" },
{72, "72" },
};
Haba_Dic = new Dictionary<int, string>()
{
{100, "100" },
{1000, "1000" },
{10000, "10000" },
{100000, "100000" },
};
InitializeComponent();
cbxColor.DataContext = GetColorList();
DataContext = this;
richTB.HorizontalScrollBarVisibility = ScrollBarVisibility.Visible;
//richTB.Document.PageWidth = 1000;
}
/// <summary>
/// すべての色を取得するメソッド
/// </summary>
/// <returns></returns>
private MyColor[] GetColorList()
{
return typeof(Colors).GetProperties(BindingFlags.Public | BindingFlags.Static)
.Select(i => new MyColor() { Color = (Color)i.GetValue(null), Name = i.Name }).ToArray();
}
/// <summary>
/// 色と色名を保持するクラス
/// </summary>
public class MyColor
{
public Color Color { get; set; }
public string Name { get; set; }
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
var dialog = new SaveFileDialog();
dialog.Filter = "xamlファイル (*.xaml)|*.xaml|全てのファイル (*.*)|*.*";
if (dialog.ShowDialog() == true)
{
SaveXamlPackage(dialog.FileName); //"C:\\test.xaml"); // パス付の保存ファイル名
}
}
// Save XAML in RichTextBox to a file specified by _fileName
// _fileNameで指定するファイルを、RichTextBoxでXAMLを保存します。
void SaveXamlPackage(string _fileName)
{
TextRange range;
FileStream fStream;
range = new TextRange(richTB.Document.ContentStart, richTB.Document.ContentEnd);
fStream = new FileStream(_fileName, FileMode.Create);
range.Save(fStream, DataFormats.XamlPackage);
fStream.Close();
windMain.Title = _fileName;
}
// Load XAML into RichTextBox from a file specified by _fileName
void LoadXamlPackage(string _fileName)
{
TextRange range;
FileStream fStream;
range = new TextRange(richTB.Document.ContentStart, richTB.Document.ContentEnd);
fStream = new FileStream(_fileName, FileMode.OpenOrCreate);
range.Load(fStream, DataFormats.XamlPackage);
fStream.Close();
windMain.Title = _fileName;
}
private void btnLoad_Click(object sender, RoutedEventArgs e)
{
var dialog = new OpenFileDialog();
dialog.Filter = "xamlファイル (*.xaml)|*.xaml|全てのファイル (*.*)|*.*";
if (dialog.ShowDialog() == true)
{
LoadXamlPackage(dialog.FileName);
}
}
private void btnCopy_Click(object sender, RoutedEventArgs e)
{
richTB.Copy();
}
private void btnPaste_Click(object sender, RoutedEventArgs e)
{
richTB.Paste();
}
private void btnCut_Click(object sender, RoutedEventArgs e)
{
richTB.Cut();
}
/*
var textRange = richTB.Selection;
// 文字色
textRange.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);
// フォント
textRange.ApplyPropertyValue(TextElement.FontFamilyProperty, new FontFamily("Verdana"));
// フォントサイズ
textRange.ApplyPropertyValue(TextElement.FontSizeProperty, 12.0);
// フォントスタイル
textRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
*/
private void btnBold_Click(object sender, RoutedEventArgs e)
{
var textRange = richTB.Selection;
// フォントウエイト
_bold = !_bold;
if (_bold == true)
{
textRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
}
else
{
textRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Regular);
}
}
private void btnItalic_Click(object sender, RoutedEventArgs e)
{
var textRange = richTB.Selection;
// フォントスタイル
_italic = !_italic;
if (_italic == true)
{
textRange.ApplyPropertyValue(TextElement.FontStyleProperty, FontStyles.Italic);
}
else
{
textRange.ApplyPropertyValue(TextElement.FontStyleProperty, FontStyles.Normal);
}
}
private void btnStrike_Click(object sender, RoutedEventArgs e)
{
var textRange = richTB.Selection;
// 取り消し線
_strike = !_strike;
if (_strike == true)
{
textRange.ApplyPropertyValue(TextBlock.TextDecorationsProperty, TextDecorations.Strikethrough);
}
else
{
textRange.ApplyPropertyValue(TextBlock.TextDecorationsProperty, new TextDecorationCollection());
}
}
private void btnULine_Click(object sender, RoutedEventArgs e)
{
var textRange = richTB.Selection;
// アンダーライン
_uline = !_uline;
if (_uline == true)
{
textRange.ApplyPropertyValue(TextBlock.TextDecorationsProperty, TextDecorations.Underline);
}
else
{
textRange.ApplyPropertyValue(TextBlock.TextDecorationsProperty, new TextDecorationCollection());
}
}
private void cbxOkisa_DropDownClosed(object sender, EventArgs e)
{
try
{
int idmy = (int)cbxOkisa.SelectedValue;
// フォントサイズ
var textRange = richTB.Selection;
textRange.ApplyPropertyValue(TextElement.FontSizeProperty, (double)idmy);
}
catch
{
MessageBox.Show("フォントサイズを指定してください");
}
}
private void cbxColor_DropDownClosed(object sender, EventArgs e)
{
try
{
var mycolor = (MyColor)((ComboBox)sender).SelectedItem;
var color = mycolor.Color;
var name = mycolor.Name;
// 文字色
var textRange = richTB.Selection;
textRange.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(color));//Brushes.Red);
}
catch
{
MessageBox.Show("フォントカラーを指定してください");
}
}
private void richTB_SelectionChanged(object sender, RoutedEventArgs e)
{
tbxSelect.Text = richTB.Selection.Text;
}
private void cbxGyoHaba_DropDownClosed(object sender, EventArgs e)
{
try
{
int idmy = (int)cbxGyoHaba.SelectedValue;
// 行の幅
richTB.Document.PageWidth = idmy;
}
catch
{
MessageBox.Show("行の幅を指定してください");
}
}
}
}