• 検索結果がありません。

グラフィックス 目次

N/A
N/A
Protected

Academic year: 2021

シェア "グラフィックス 目次"

Copied!
18
0
0

読み込み中.... (全文を見る)

全文

(1)

■ WPF での Windows フォーム複合コントロールのホスト ■

Windows Presentation Foundation(WPF)は、アプリケーションの作成に適した環境を提供する。但 し、Windows フォームのコードに多くの投資を行った場合は、コードを最初から記述し直すよりも、 WPF アプリケーションのコードの少なくとも一部を再利用する方が効率的で有る。最も一般的なシナ リオは、既存のWindows フォームコントロールが有る場合で有る。場合に依っては、此等のコントロ ールのソースコードにアクセス出来ない事が有る。WPF には、其の様なコントロールを WPF アプリケ ーションでホストする為の簡単な手順が用意されて居る。例えば、特殊なDataGridView コントロール をホストし乍、殆どのプログラミングにはWPF を使用出来る。 此のチュートリアルでは、WPF アプリケーションで Windows フォーム複合コントロールをホストして データエントリを実行するアプリケーションに付いて段階的に説明する。複合コントロールは DLL に パッケージ化されて居る。此の一般的な手順は、更に複雑なアプリケーションやコントロールに拡張出 来る。此のチュートリアルは、外観や機能が「チュートリアル: Windows フォームでの WPF 複合コン トロールのホスト」の例と粗同じに成る様に設計されて居る。主な違いは、ホストする側とされる側が 逆で有る事で有る。 チュートリアルは、2 つのセクションに分かれて居る。最初のセクションでは、Windows フォーム複合 コントロールの実装に付いて簡単に説明する。2 番目のセクションでは、WPF アプリケーションで複合 コントロールをホストし、コントロールからイベントを受け取って、コントロールのプロパティの一部 にアクセスする方法に付いて詳しく説明する。 此のチュートリアルでは、以下のタスクを行う。 ・Windows フォーム複合コントロールの実装 ・WPF ホストアプリケーションの実装 此のチュートリアルで示すタスクの完全なコード一覧に付いては、WPF での Windows フォーム複合 コントロールのホストのサンプルを参照してください。 ■ Windows フォーム複合コントロールの実装 此の例で使用するWindows フォーム複合コン トロールは、単純なデータ入力フォームで有る。 此のフォームは、ユーザーの名前と住所を受け 取った後、カスタムイベントを使用して其の情 報をホストに返す。レンダリングされたコント ロールを右の図に示す。

W

WP

PF

F

チュ

ュー

ート

トリ

リア

アル

(2)

プロジェクトを開始するには

1.Microsoft Visual Studio を起動して、[新しいプロジェクト] ダイアログボックスを開く。

2.ウィンドウのカテゴリで、[Windows フォームコントロールライブラリ] テンプレートを選択する。 ※ Express バージョンでは、上記のテンプレートは存在しないので、先ず、クラスライブラリ(又 は Windows フォームアプリケーション)を選択し、ユーザーコントロール(WPF)を追加し て、クラスライブラリ(又はWindows フォーム)を削除する。 3.新しいプロジェクトにMyControls と謂う名前を付ける。 4.配置場所としては、WpfHostingWindowsFormsControl 等、解り易い名前を付けた最上位フォル ダーを指定する。此のフォルダーには後でホストアプリケーションも配置する。 5.[OK] をクリックして、プロジェクトを作成する。既定のプロジェクトには、UserControl1 と謂う 名前の1 つのコントロールが含まれる。 6.ソリューションエクスプローラーで、UserControl1 の名前を MyControl1 に変更する。 プロジェクトは、次のシステムDLL を参照して居る必要が有る。此等の DLL の孰れかが既定で含まれ て居ない場合は、プロジェクトに追加する。 ・System ・System.Data ・System.Drawing ・System.Windows.Forms ・System.Xml フォームへのコントロールの追加 フォームにコントロールを追加するには、次の操作を実行する。 ・デザイナーでMyControl1 を開く。 5 つの Label コントロールと其れに対応する TextBox コントロールを、前の図と同じ様なサイズと位置 関係で、フォーム上に追加する。此の例では、TextBox コントロールには次の様な名前を付ける。 ・txtName ・txtAddress ・txtCity ・txtState ・txtZip OK と Cancel と謂うラベルを付けた 2 つの Button コントロールを追加する。此の例では、ボタンの名 前は夫々btnOK と btnCancel で有る。 サポートコードの実装 コードビューでフォームを開く。コントロールは、カスタム OnButtonClick イベントを発生させる事 で、収集したデータをホストに返す。データは、イベント引数オブジェクトに格納されて居る。次のコ ードは、イベントとデリゲートの宣言を示して居る。

(3)

MyControl1 クラスに次のコードを追加する。

Visual Basic

Public Delegate Sub MyControlEventHandler(ByVal sender As Object, _ ByVal args As MyControlEventArgs)

Public Event OnButtonClick As MyControlEventHandler

Visual C#

public delegate void MyControlEventHandler(object sender, MyControlEventArgs args); public event MyControlEventHandler OnButtonClick;

MyControlEventArgs クラスには、ホストに返される情報が格納される。 次のクラスをフォームに追加する。

Visual Basic

Public Class MyControlEventArgs Inherits EventArgs

Private _Name As String

Private _StreetAddress As String Private _City As String

Private _State As String Private _Zip As String Private _IsOK As Boolean

Public Sub New(ByVal result As Boolean, ByVal name As String, ByVal address As String, _ ByVal city As String, ByVal state As String, ByVal zip As String)

_IsOK = result _Name = name _StreetAddress = address _City = city _State = state _Zip = zip End Sub

Public Property MyName() As String Get Return _Name End Get Set _Name = value End Set End Property

Public Property MyStreetAddress() As String Get

Return _StreetAddress End Get

(4)

_StreetAddress = value End Set

End Property

Public Property MyCity() As String Get Return _City End Get Set _City = value End Set End Property

Public Property MyState() As String Get Return _State End Get Set _State = value End Set End Property

Public Property MyZip() As String Get Return _Zip End Get Set _Zip = value End Set End Property

Public Property IsOK() As Boolean Get Return _IsOK End Get Set _IsOK = value End Set End Property End Class Visual C#

public class MyControlEventArgs : EventArgs {

private string _Name;

private string _StreetAddress; private string _City;

private string _State; private string _Zip;

(5)

private bool _IsOK;

public MyControlEventArgs(bool result, string name, string address, string city, string state, string zip) { _IsOK = result; _Name = name; _StreetAddress = address; _City = city; _State = state; _Zip = zip; }

public string MyName {

get { return _Name; } set { _Name = value; } }

public string MyStreetAddress {

get { return _StreetAddress; } set { _StreetAddress = value; } }

public string MyCity {

get { return _City; } set { _City = value; } }

public string MyState {

get { return _State; } set { _State = value; } }

public string MyZip {

get { return _Zip; } set { _Zip = value; } }

public bool IsOK {

get { return _IsOK; } set { _IsOK = value; } }

(6)

ユーザーが [OK] ボタン、又は、[Cancel] ボタンをクリックすると、Click イベントハンドラーはデー タを格納したMyControlEventArgs オブジェクトを作成し、OnButtonClick イベントを発生させる。2

つのハンドラーの違いは、イベント引数のIsOK プロパティ丈で有る。此のプロパティに依り、ホスト

は孰れのボタンがクリックされたのかを判別出来る。[OK] ボタンの場合は true が設定され、[Cancel]

ボタンの場合はfalse が設定される。次のコード例は、2 つのボタンハンドラーを示して居る。

MyControl1 クラスに次のコードを追加する。

Visual Basic

Private Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles btnOK.Click

Dim retvals As New MyControlEventArgs(True, _

txtName.Text, txtAddress.Text, txtCity.Text, txtState.Text, txtZip.Text) RaiseEvent OnButtonClick(Me, retvals)

End Sub

Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles btnCancel.Click

Dim retvals As New MyControlEventArgs(False, _

txtName.Text, txtAddress.Text, txtCity.Text, txtState.Text, txtZip.Text) RaiseEvent OnButtonClick(Me, retvals)

End Sub

Visual C#

private void btnOK_Click(object sender, System.EventArgs e) {

MyControlEventArgs retvals = new MyControlEventArgs(true, txtName.Text, txtAddress.Text, txtCity.Text, txtState.Text, txtZip.Text); OnButtonClick(this, retvals); }

private void btnCancel_Click(object sender, System.EventArgs e) {

MyControlEventArgs retvals = new MyControlEventArgs(false, txtName.Text, txtAddress.Text, txtCity.Text, txtState.Text, txtZip.Text); OnButtonClick(this, retvals); }

(7)

アセンブリへの厳密な名前の設定とアセンブリのビルド

WPF アプリケーションから此のアセンブリを参照するには、アセンブリに厳密な名前を付ける必要が 有る。厳密な名前を作成するには、Sn.exe でキーファイルを作成し、其れをプロジェクトに追加する。 1.Visual Studio のコマンドプロンプトを開く。此の操作を行うには、[スタート] ボタンをクリック

し、[総てのプログラム]、[Microsoft Visual Studio 2010]、[Visual Studio ツール] の順にポイント して、[Visual Studio コマンドプロンプト] をクリックする。カスタマイズされた環境変数でコン ソールウィンドウが起動される。

※ Express バージョンでは、Sn.exe は、下記の場所辺りに有る(巻末参照)。 C:¥Program Files¥Microsoft SDKs¥Windows¥v7.0A¥bin¥NETFX 4.0 Tools C:¥Program Files¥Microsoft Visual Studio 8¥SDK¥v2.0¥Bin

2.コマンドプロンプトで、cd コマンドを使用してプロジェクトフォルダーに移動する。 3.次のコマンドを実行し、MyControls.snk と謂う名前のキーファイルを生成する。 Sn.exe -k MyControls.snk 4.キーファイルをプロジェクトに組み込むには、ソリューションエクスプローラーでプロジェクト名 を右クリックし、[プロパティ] をクリックする。プロジェクトデザイナで、[署名] タブをクリック し、[アセンブリの署名] チェックボックスをオンにして、キーファイルを参照する。 5.ソリューションをビルドする。ビルドでは、MyControls.dll と謂う名前の DLL が生成される。 ※ Express バージョンでは、プロジェクトのプロパティで、アプリケーションの種類を、クラス ライブラリに変更してから、ビルドする(Windows フォームで作成した場合)。 ■ WPF ホストアプリケーションの実装 WPF ホストアプリケーションは、 WindowsFormsHost コントロー ルを使用してMyControl1 をホス トする。アプリケーションは、 OnButtonClick イベントを処理 して、コントロールからデータを 受け取る。亦、WPF アプリケー ションからコントロールの一部の プロパティを変更出来るオプショ ンボタンのコレクションも有る。 最終的なアプリケーションを次の 図に示す。

(8)

プロジェクトの作成 1.Visual Studio を開き、[新しいプロジェクト] を選択する。 2.ウィンドウのカテゴリで、[WPF アプリケーション] テンプレートを選択する。 3.新しいプロジェクトにWpfHost と謂う名前を付ける。 4.配置場所としては、MyControls プロジェクトの配置先と同じ最上位フォルダーを指定する。 ※ 別々に保存した場合は、前述のプロジェクトで作成した MyControls.dll を此のプロジェクトの プロジェクトフォルダーにコピーして置くと良い。 5.[OK] をクリックして、プロジェクトを作成する。 MyControl1、及び、他のアセンブリを含む DLL への参照も追加する必要が有る。 1.ソリューションエクスプローラーで、プロジェクト名を右クリックし、[参照の追加] を選択する。 2.[参照] タブをクリックし、MyControls.dll を格納して居るフォルダーを参照する。此のチュートリ アルの場合は、MyControls¥bin¥Debug フォルダーで有る。 3.MyControls.dll を選択し、[OK] をクリックする。 4.WindowsFormsIntegration.dll と謂う名前の WindowsFormsIntegration アセンブリに参照を追加 する。 基本レイアウトの実装 ホストアプリケーションのユーザーインターフェイス(UI)は、MainWindow.xaml で実装される。此 のファイルは、レイアウトを定義するExtensible Application Markup Language(XAML)マークア ップを含み、Windows フォームコントロールをホストする。アプリケーションは次の 3 つの領域に分 かれて居る。

・[Control Properties] パネルには、ホストされるコントロールの様々なプロパティの変更に使用出来 るオプションボタンのコレクションが含まれる。

・[Data from Control] パネルには、ホストされるコントロールから返されるデータを表示する TextBlock 要素が含まれる。

・ホストされるコントロール自体。

基本的なレイアウトを次のXAML に示す。MyControl1 をホストする為に必要なマークアップは此の例

では省略されて居るが、此れに付いては後で説明する。

MainWindow.xaml 内の XAML を次のコードに置き換える。Visual Basic を使用して居る場合は、クラ スをx:Class="MainWindow" に変更する。

(9)

XAML <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="WpfHost.MainWindow" xmlns:mcl="clr-namespace:MyControls;assembly=MyControls" Loaded="Init"> <DockPanel> <DockPanel.Resources>

<Style x:Key="inlineText" TargetType="{x:Type Inline}"> <Setter Property="FontWeight" Value="Normal"/> </Style>

<Style x:Key="titleText" TargetType="{x:Type TextBlock}"> <Setter Property="DockPanel.Dock" Value="Top"/>

<Setter Property="FontWeight" Value="Bold"/> <Setter Property="Margin" Value="10,5,10,0"/> </Style> </DockPanel.Resources> <StackPanel Orientation="Vertical" DockPanel.Dock="Left" Background="Bisque" Width="250"> <TextBlock Margin="10,10,10,10" FontWeight="Bold" FontSize="12">Control Properties</TextBlock>

<TextBlock Style="{StaticResource titleText}">Background Color</TextBlock> <StackPanel Margin="10,10,10,10"> <RadioButton Name="rdbtnOriginalBackColor" IsChecked="True" Click="BackColorChanged">Original</RadioButton> <RadioButton Name="rdbtnBackGreen" Click="BackColorChanged">LightGreen</RadioButton> <RadioButton Name="rdbtnBackSalmon" Click="BackColorChanged">LightSalmon</RadioButton> </StackPanel>

<TextBlock Style="{StaticResource titleText}">Foreground Color</TextBlock> <StackPanel Margin="10,10,10,10"> <RadioButton Name="rdbtnOriginalForeColor" IsChecked="True" Click="ForeColorChanged">Original</RadioButton> <RadioButton Name="rdbtnForeRed" Click="ForeColorChanged">Red</RadioButton> <RadioButton Name="rdbtnForeYellow" Click="ForeColorChanged">Yellow</RadioButton> </StackPanel>

(10)

<TextBlock Style="{StaticResource titleText}">Font Family</TextBlock> <StackPanel Margin="10,10,10,10"> <RadioButton Name="rdbtnOriginalFamily" IsChecked="True" Click="FontChanged">Original</RadioButton> <RadioButton Name="rdbtnTimes"

Click="FontChanged">Times New Roman</RadioButton> <RadioButton Name="rdbtnWingdings"

Click="FontChanged">Wingdings</RadioButton> </StackPanel>

<TextBlock Style="{StaticResource titleText}">Font Size</TextBlock> <StackPanel Margin="10,10,10,10"> <RadioButton Name="rdbtnOriginalSize" IsChecked="True" Click="FontSizeChanged">Original</RadioButton> <RadioButton Name="rdbtnTen" Click="FontSizeChanged">10</RadioButton> <RadioButton Name="rdbtnTwelve" Click="FontSizeChanged">12</RadioButton> </StackPanel>

<TextBlock Style="{StaticResource titleText}">Font Style</TextBlock> <StackPanel Margin="10,10,10,10"> <RadioButton Name="rdbtnNormalStyle" IsChecked="True" Click="StyleChanged">Original</RadioButton> <RadioButton Name="rdbtnItalic" Click="StyleChanged">Italic</RadioButton> </StackPanel>

<TextBlock Style="{StaticResource titleText}">Font Weight</TextBlock> <StackPanel Margin="10,10,10,10"> <RadioButton Name="rdbtnOriginalWeight" IsChecked="True" Click="WeightChanged"> Original </RadioButton> <RadioButton Name="rdbtnBold" Click="WeightChanged">Bold</RadioButton> </StackPanel> </StackPanel> <WindowsFormsHost Name="wfh" DockPanel.Dock="Top" Height="300"> <mcl:MyControl1 Name="mc"/> </WindowsFormsHost>

(11)

<StackPanel Orientation="Vertical" Height="Auto"

Background="LightBlue"> <TextBlock Margin="10,10,10,10" FontWeight="Bold"

FontSize="12">Data From Control</TextBlock> <TextBlock Style="{StaticResource titleText}">

Name: <Span Name="txtName" Style="{StaticResource inlineText}"/> </TextBlock>

<TextBlock Style="{StaticResource titleText}">

Street Address: <Span Name="txtAddress" Style="{StaticResource inlineText}"/> </TextBlock>

<TextBlock Style="{StaticResource titleText}">

City: <Span Name="txtCity" Style="{StaticResource inlineText}"/> </TextBlock>

<TextBlock Style="{StaticResource titleText}">

State: <Span Name="txtState" Style="{StaticResource inlineText}"/> </TextBlock>

<TextBlock Style="{StaticResource titleText}">

Zip: <Span Name="txtZip" Style="{StaticResource inlineText}"/> </TextBlock>

</StackPanel> </DockPanel> </Window>

最初のStackPanel 要素には、ホストされるコントロールの様々な既定のプロパティを変更出来る一連

のRadioButton コントロールが含まれる。其の後に有る WindowsFormsHost 要素は、MyControl1 を

ホストする。最後のStackPanel 要素には、ホストされるコントロールから返されるデータを表示する

TextBlock 要素が含まれる。要素の順序、及び、Dock 属性と Height 属性の設定に依り、隙間や歪みが 無い様に、ホストされるコントロールがウィンドウに埋め込まれる。 コントロールのホスト 次のコードは前出のXAML を再掲した物だが、此処では MyControl1 をホストする為に必要な要素に 焦点を当てゝ居る。 XAML <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="WpfHost.MainWindow" xmlns:mcl="clr-namespace:MyControls;assembly=MyControls" Loaded="Init"> ... <WindowsFormsHost Name="wfh" DockPanel.Dock="Top" Height="300"> <mcl:MyControl1 Name="mc"/>

(12)

xmlns 名前空間の割り当ての属性に依り、ホストされるコントロールを格納する MyControls 名前空間 への参照が作成される。此の割り当てに依り、XAML で MyControl1 を <mcl:MyControl1> として表 す事が出来る。

XAML に含まれる次の 2 つの要素がホストを処理する。

・WindowsFormsHost は、WPF アプリケーションでの Windows フォームコントロールのホスト を可能にするWindowsFormsHost 要素を表す。

・MyControl1 を表す mcl:MyControl1 は、WindowsFormsHost 要素の子コレクションに追加され

る。結果として、此のWindows フォームコントロールは WPF ウィンドウの一部としてレンダ リングされ、アプリケーションからコントロールと通信出来る。 分離コードファイルの実装 分離コードファイルMainWindow.xaml.vb 又は MainWindow.xaml.cs には、前のセクションで説明し たUI の機能を実装する手順コードが含まれる。主要なタスクは次の通りで有る。 ・MyControl1 の OnButtonClick イベントへのイベントハンドラーのアタッチ。 ・一連のオプションボタンの設定に基づく、MyControl1 の様々なプロパティの変更。 ・コントロールに依って収集されたデータの表示。 アプリケーションの初期化 初期化コードは、ウィンドウのLoaded イベントのイベントハンドラーに含まれ、イベントハンドラー をコントロールのOnButtonClick イベントにアタッチする。

MainWindow.xaml.vb 又は MainWindow.xaml.cs で、MainWindow クラスに次のコードを追加する。

Visual Basic

Private app As Application Private myWindow As Window

Private initFontWeight As FontWeight Private initFontSize As [Double] Private initFontStyle As FontStyle

Private initBackBrush As SolidColorBrush Private initForeBrush As SolidColorBrush Private initFontFamily As FontFamily Private UIIsReady As Boolean = False

Private Sub Init(ByVal sender As Object, ByVal e As RoutedEventArgs) app = System.Windows.Application.Current

myWindow = CType(app.MainWindow, Window)

myWindow.SizeToContent = SizeToContent.WidthAndHeight wfh.TabIndex = 10

initFontSize = wfh.FontSize initFontWeight = wfh.FontWeight initFontFamily = wfh.FontFamily

(13)

initFontStyle = wfh.FontStyle

initBackBrush = CType(wfh.Background, SolidColorBrush) initForeBrush = CType(wfh.Foreground, SolidColorBrush)

Dim mc As MyControl1 = wfh.Child

AddHandler mc.OnButtonClick, AddressOf Pane1_OnButtonClick UIIsReady = True

End Sub

Visual C#

private Application app; private Window myWindow; FontWeight initFontWeight; Double initFontSize; FontStyle initFontStyle; SolidColorBrush initBackBrush; SolidColorBrush initForeBrush; FontFamily initFontFamily; bool UIIsReady = false;

private void Init(object sender, EventArgs e) { app = System.Windows.Application.Current; myWindow = (Window)app.MainWindow; myWindow.SizeToContent = SizeToContent.WidthAndHeight; wfh.TabIndex = 10; initFontSize = wfh.FontSize; initFontWeight = wfh.FontWeight; initFontFamily = wfh.FontFamily; initFontStyle = wfh.FontStyle; initBackBrush = (SolidColorBrush)wfh.Background; initForeBrush = (SolidColorBrush)wfh.Foreground; (wfh.Child as MyControl1).OnButtonClick += new MyControl1.MyControlEventHandler(Pane1_OnButtonClick); UIIsReady = true; }

前述のXAML に依って、MyControl1 が WindowsFormsHost 要素の子要素コレクションに追加されて 居る為、WindowsFormsHost 要素の Child をキャストして MyControl1 への参照を取得出来る。其の

後、其の参照を使用して、イベントハンドラーをOnButtonClick にアタッチする事が出来る。

コントロール自体への参照を提供する丈でなく、WindowsFormsHost では様々なコントロールのプロ パティも公開されて居り、アプリケーションから其れを操作出来る。初期化コードは、後でアプリケー ションで使用する為、此等の値をプライベートグローバル変数に代入する。

(14)

Visual Basic Imports MyControls Visual C# using MyControls; OnButtonClick イベントの処理 ユーザーがコントロールのボタンの孰れかをクリックすると、MyControl1 が OnButtonClick イベント を発生させる。 MainWindow クラスに次のコードを追加する。 Visual Basic

'Handle button clicks on the Windows Form control

Private Sub Pane1_OnButtonClick(ByVal sender As Object, ByVal args As MyControlEventArgs) txtName.Inlines.Clear() txtAddress.Inlines.Clear() txtCity.Inlines.Clear() txtState.Inlines.Clear() txtZip.Inlines.Clear() If args.IsOK Then txtName.Inlines.Add(" " + args.MyName) txtAddress.Inlines.Add(" " + args.MyStreetAddress) txtCity.Inlines.Add(" " + args.MyCity) txtState.Inlines.Add(" " + args.MyState) txtZip.Inlines.Add(" " + args.MyZip) End If End Sub Visual C#

//Handle button clicks on the Windows Form control

private void Pane1_OnButtonClick(object sender, MyControlEventArgs args) { txtName.Inlines.Clear(); txtAddress.Inlines.Clear(); txtCity.Inlines.Clear(); txtState.Inlines.Clear(); txtZip.Inlines.Clear(); if (args.IsOK) { txtName.Inlines.Add( " " + args.MyName ); txtAddress.Inlines.Add( " " + args.MyStreetAddress ); txtCity.Inlines.Add( " " + args.MyCity ); txtState.Inlines.Add( " " + args.MyState ); txtZip.Inlines.Add( " " + args.MyZip ); } }

(15)

テキストボックスのデータは、MyControlEventArgs オブジェクトに格納される。ユーザーが [OK] ボ タンをクリックすると、イベントハンドラーはデータを抽出して、MyControl1 の下のパネルに表示す る。 コントロールのプロパティの変更 WindowsFormsHost 要素は、ホストされるコントロールの幾つかの既定のプロパティを公開する。此 れに依り、アプリケーションのスタイルにより一致する様に、コントロールの外観を変更出来る。左側 のパネルに有る一連のオプションボタンを使用すると、色やフォントのプロパティを変更出来る。各ボ タン セットには Click イベントに対するハンドラーが有り、ユーザーに依るオプションボタンの選択を 検出して、コントロールの対応するプロパティを変更する。 MainWindow クラスに次のコードを追加する。 Visual Basic

Private Sub BackColorChanged(ByVal sender As Object, ByVal e As RoutedEventArgs) If sender.Equals(rdbtnBackGreen) Then

wfh.Background = New SolidColorBrush(Colors.LightGreen) ElseIf sender.Equals(rdbtnBackSalmon) Then

wfh.Background = New SolidColorBrush(Colors.LightSalmon) ElseIf UIIsReady = True Then

wfh.Background = initBackBrush End If

End Sub

Private Sub ForeColorChanged(ByVal sender As Object, ByVal e As RoutedEventArgs) If sender.Equals(rdbtnForeRed) Then

wfh.Foreground = New SolidColorBrush(Colors.Red) ElseIf sender.Equals(rdbtnForeYellow) Then

wfh.Foreground = New SolidColorBrush(Colors.Yellow) ElseIf UIIsReady = True Then

wfh.Foreground = initForeBrush End If

End Sub

Private Sub FontChanged(ByVal sender As Object, ByVal e As RoutedEventArgs) If sender.Equals(rdbtnTimes) Then

wfh.FontFamily = New FontFamily("Times New Roman") ElseIf sender.Equals(rdbtnWingdings) Then

wfh.FontFamily = New FontFamily("Wingdings") ElseIf UIIsReady = True Then

wfh.FontFamily = initFontFamily End If

End Sub

(16)

ElseIf sender.Equals(rdbtnTwelve) Then wfh.FontSize = 12

ElseIf UIIsReady = True Then wfh.FontSize = initFontSize End If

End Sub

Private Sub StyleChanged(ByVal sender As Object, ByVal e As RoutedEventArgs) If sender.Equals(rdbtnItalic) Then

wfh.FontStyle = FontStyles.Italic ElseIf UIIsReady = True Then wfh.FontStyle = initFontStyle End If

End Sub

Private Sub WeightChanged(ByVal sender As Object, ByVal e As RoutedEventArgs) If sender.Equals(rdbtnBold) Then

wfh.FontWeight = FontWeights.Bold ElseIf UIIsReady = True Then

wfh.FontWeight = initFontWeight End If

End Sub

Visual C#

private void BackColorChanged(object sender, RoutedEventArgs e) {

if (sender == rdbtnBackGreen)

wfh.Background = new SolidColorBrush(Colors.LightGreen); else if (sender == rdbtnBackSalmon)

wfh.Background = new SolidColorBrush(Colors.LightSalmon); else if (UIIsReady == true)

wfh.Background = initBackBrush; }

private void ForeColorChanged(object sender, RoutedEventArgs e) {

if (sender == rdbtnForeRed)

wfh.Foreground = new SolidColorBrush(Colors.Red); else if (sender == rdbtnForeYellow)

wfh.Foreground = new SolidColorBrush(Colors.Yellow); else if (UIIsReady == true)

wfh.Foreground = initForeBrush; }

private void FontChanged(object sender, RoutedEventArgs e) {

if (sender == rdbtnTimes)

(17)

else if (sender == rdbtnWingdings)

wfh.FontFamily = new FontFamily("Wingdings"); else if (UIIsReady == true)

wfh.FontFamily = initFontFamily; }

private void FontSizeChanged(object sender, RoutedEventArgs e) {

if (sender == rdbtnTen) wfh.FontSize = 10;

else if (sender == rdbtnTwelve) wfh.FontSize = 12;

else if (UIIsReady == true) wfh.FontSize = initFontSize; }

private void StyleChanged(object sender, RoutedEventArgs e) {

if (sender == rdbtnItalic)

wfh.FontStyle = FontStyles.Italic; else if (UIIsReady == true)

wfh.FontStyle = initFontStyle; }

private void WeightChanged(object sender, RoutedEventArgs e) {

if (sender == rdbtnBold)

wfh.FontWeight = FontWeights.Bold; else if (UIIsReady == true)

wfh.FontWeight = initFontWeight; } アプリケーションをビルドして実行する。Windows フォーム複合コントロールにテキストを追加して [OK] をクリックする。其のテキストがラベルに表示される。別のオプションボタンをクリックして、 コントロール上の影響を確認する。 http://msdn.microsoft.com/ja-jp/library/ms750944(v=vs.110).aspx http://msdn.microsoft.com/ja-jp/library/ee649089(v=vs.110).aspx

(18)

■ キーペアを作成する方法 ■ 1.[スタート] ボタンをクリックし、[総てのプログラム] → [アクセサリ] の順にポイントし、[コマン ドプロンプト] をクリックする。 ※ コマンドプロンプト(DOS 窓)が開く。 2.コマンドプロンプトで、cd コマンドを使用して、プロジェクトフォルダーに移動する。 ※ コマンドラインで、cd [スペース] と入力し、プロジェクトフォルダー(ソリューションファイ ルと同階層に有るフォルダー)をDOS 窓にドラッグ&ドロップして、Enter キーを押すと、簡 単に移動する事が出来る。 3.次のコマンドを実行して、MyControls.snk と謂うキーファイルを生成する。 Sn.exe -k MyControls.snk ※ Sn.exe が格納されて居るフォルダーは、パスが通ってないので、フルパスで記述する必要が有 る(Sn.exe を DOS 窓にドラッグ&ドロップすると、簡単に記述する事が出来る)。 ※ 猶、Sn.exe は、下記のフォルダーに格納されて居る。 C:¥Program Files¥Microsoft SDKs¥Windows¥v7.0A¥bin C:¥Program Files¥Microsoft Visual Studio 8¥SDK¥v2.0¥Bin

参照

関連したドキュメント

Using Virtual Tenant Network (VTN) function, four private networks were prepared on single physical network with OpenFlow switch.. Relocation of computer does not

そればかりか,チューリング機械の能力を超える現実的な計算の仕組は,今日に至るま

Maurer )は,ゴルダンと私が以前 に証明した不変式論の有限性定理を,普通の不変式論

Jones, 村上順, 大槻知忠, 葉廣和夫, (量子力学, 統計学, 物理学など様々な分野との結びつき ながら大きく発展中!!

Maurer )は,ゴルダンと私が以前 に証明した不変式論の有限性定理を,普通の不変式論

・1の居室の定員は1人である。 ・利用者1人当たりの床面積は内法で 10.8 ㎡~12.2

1 一定規模以下のものに限り建築可能 2 当該用途に供する部分が2階以下かつ 1,500 ㎡以下の場合に限り建築可能 3

5号マンホール 内のり 210cm×120cm 角形 内径 1,800 ㎜以下の管の中間点 6号マンホール 内のり 260cm×120cm 角形 内径 2,200 ㎜以下の管の中間点 7号マンホール 内のり