TabControlを使う WPF

VB Tips And Sample(HOME)VBプログラマの為のWPF入門

TabControlを使う WPF

Tabと言えば、狭いウィンドウ内に、多くの入力を必要とするフォームを作る際には、必須のコントロールでした。
今は、画面は横長がメインになっていると思いますが、それでもやっぱり必要なのでしょう。
Tabを作った人はすばらしい。
さて、このコントロールは非常に分かりやすく作られているみたいです。
ただ、TabControlをフォームにドラッグドロップして、Tabの中のGrid内に、必要なコントロールを入れてやればOK。
そのコントロールの値を取得するのは、フォーム上のコントロールの値を取得するのと変わらないみたいだ。 どのTabが選択されているかも、インデックス0~で取得可能。

タブコントロール
横のtab

「呼び出し履歴」

の機能も紹介。
このルーチンがどこから呼び出されている?
というスパゲティー状態になったら力を発揮する。
実行して、下図のように表示すればよいらしい。
呼び出し履歴
あとは、赤囲いの中の行を適当にクリックするとよい。

Public Class TabControl

    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click

        
        Call 呼び出し()

        Debug.Print(Me.TabControl1.SelectedIndex)


    End Sub

    Private Sub 呼び出し()
        Debug.Print(Me.lbl1.Content)
        Debug.Print(Me.lbl2.Content)
        Debug.Print(Me.lbl3.Content)
    End Sub
End Class


<Window x:Class="TabControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="TabControl" Height="297" Width="519" WindowStartupLocation="CenterScreen">
    <Grid>
        <StackPanel>
        <TabControl Height="220" Width="220"  HorizontalAlignment="Center" Name="TabControl1" VerticalAlignment="Top" Background="#82D2E05E" TabStripPlacement="Left">
            <TabItem Header="TabItem1" Name="TabItem1" >
                <Grid>
                    <Label Content="タブ1" Name="lbl1"/>
                </Grid>
            </TabItem>
            <TabItem Header="TabItem2" Name="TabItem2" IsSelected="True">
                <Grid>
                    <Label Content="タブ2" Name="lbl2"/>
                </Grid>
                    
            </TabItem>
            <TabItem Header="TabItem3" Name="TabItem3">
                <Grid>
                    <Label Content="タブ3" Name="lbl3"/>
                </Grid>
            </TabItem>
        </TabControl>
            <Button Content="Button" Height="23" Name="Button1" Width="75" />
        </StackPanel>
    </Grid>
</Window>

VB Tips And Sample(HOME)VBプログラマの為のWPF入門