[vb 2008 ] 구구단 프로그램예제
Class Window1
'WPF 두번째 예제 프로그램
'프그램명 : 구구단 프로그램
'제 작 일 : 2010. 01. 02
Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
Me.Title = "< 구구단 프로그램 >"
TextBox1.Text = ""
Button1.Content = " 확 인 "
Button2.Content = " 종 료 "
Label1.Content = ""
TextBox1.Focus()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim a As Integer
Label1.Content = ""
If IsNumeric(TextBox1.Text) = False Then
Label1.Content = "숫자 입력만 가능 합니다."
Exit Sub
Else
a = TextBox1.Text
End If
Call kubsum(a)
End Sub
Private Sub kubsum(ByVal a As Integer)
Dim i As Integer = 1
Dim c As Integer = 0
For i = 1 To 9
c = CInt(a) * i
Label1.Content = Label1.Content & a & " * " & i & " = " & c & vbCrLf
Next
End Sub
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles TextBox1.KeyDown
Dim a As Integer
Label1.Content = ""
If e.Key = Key.Enter Then
If IsNumeric(TextBox1.Text) = False Then
Label1.Content = "숫자 입력만 가능 합니다."
Exit Sub
Else
a = TextBox1.Text
End If
Call kubsum(a)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button2.Click
Me.Close()
End
End Sub
End Class
xaml source :
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="342" Width="300">
<Grid>
<Grid Margin="8,9,8,16" Name="Grid1" ForceCursor="False" ShowGridLines="False" OverridesDefaultStyle="True">
<Grid.RowDefinitions>
<RowDefinition Height="29*" />
<RowDefinition Height="217*" />
<RowDefinition Height="27*" />
<RowDefinition Height="6*" />
</Grid.RowDefinitions>
<Button HorizontalAlignment="Right" Margin="0,0,18,0" Name="Button1" Width="87">Button</Button>
<TextBox Margin="31,5,0,1" Name="TextBox1" TextAlignment="Center" HorizontalContentAlignment="Center" Foreground="Blue" HorizontalAlignment="Left" Width="70" />
<Label Grid.Row="1" Margin="4,6,6,0" Name="Label1" Grid.RowSpan="2" Foreground="Blue">Label</Label>
<Button Grid.Row="2" HorizontalAlignment="Right" Margin="0,0,18,0" Name="Button2" Width="84">Button</Button>
<Label Margin="100,3,0,0" Name="Label2" HorizontalAlignment="Left" Width="24" Height="29" Grid.RowSpan="2" VerticalAlignment="Top">단</Label>
</Grid>
</Grid>
</Window>