今回作成したサンプルプログラム
Imports GrapeCity.Win.Input Public Class Form1 Dim ex As Excel.Application Private Sub Form1_FormClosed(ByVal sender As Object, _ ByVal e As System.Windows.Forms.FormClosedEventArgs) _ Handles Me.FormClosed ex.ActiveWorkbook.Save() ex.Application.Quit() End Sub Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Me.Width = 280 Me.Height = 330 ex = CreateObject("Excel.Application") With ex .Visible = True 'バックグラウンドで処理するならFalseに設定する .Workbooks.Open("c:\外出交通費精算.xls") End With Me.Edit3.HistoryList = New String() _ {"東京", "有楽町", "新橋", "品川", "新宿", "渋谷"} Me.Edit4.HistoryList = New String() _ {"東京", "有楽町", "新橋", "品川", "新宿", "渋谷"} ' 日曜日の日付スタイルを設定します。 Calendar1.Weekdays.Sunday.ReflectToTitle = ReflectTitle.Both Calendar1.Weekdays.Sunday.SubStyle.BackColor = Color.Pink Calendar1.Weekdays.Sunday.SubStyle.ForeColor = Color.Red Calendar1.Weekdays.Sunday.WeekFlags = WeekFlags.All ' 土曜日の日付スタイルを設定します。 Calendar1.Weekdays.Saturday.ReflectToTitle = ReflectTitle.Both Calendar1.Weekdays.Saturday.SubStyle.BackColor = Color.PowderBlue Calendar1.Weekdays.Saturday.SubStyle.ForeColor = Color.Blue Calendar1.Weekdays.Saturday.WeekFlags = WeekFlags.All End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click If Me.Calculator1.Visible = True Then Me.Edit5.Text = Me.Calculator1.Value Me.Width = 280 Me.Calculator1.Visible = False ElseIf Me.Calendar1.Visible = True Then Me.Edit2.Text = Me.Calendar1.SelectedDate Me.Width = 280 Me.Calendar1.Visible = False End If End Sub Private Sub Button1_Click_1(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Me.Width = 500 Me.Calculator1.Visible = True Me.Calendar1.Visible = False Me.Button2.Enabled = True End Sub Private Sub Button4_Click_1(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button4.Click Me.Width = 650 Me.Calculator1.Visible = False Me.Calendar1.Visible = True Me.Button2.Enabled = False End Sub Private Sub Button3_Click_1(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button3.Click With ex .Worksheets("Sheet1").rows("2:2").insert() .Cells(2, 1) = Edit1.Text .Cells(2, 2) = Edit2.Text .Cells(2, 3) = Edit3.Text .Cells(2, 4) = Edit4.Text .Cells(2, 5) = Edit5.Text .Cells(2, 6) = Combo1.Value End With Edit2.Text = "" Edit5.Text = "" End Sub Private Sub Button1_MouseHover1(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Button1.MouseHover Me.BalloonTip1.Show(Me.Button1) End Sub Private Sub Button1_MouseLeave1(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Button1.MouseLeave Me.BalloonTip1.Hide() End Sub Private Sub Button5_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button5.Click Me.Width = 280 End Sub Private Sub Calendar1_SelectedDateChanged(ByVal sender _ As Object, ByVal e As System.EventArgs) _ HandlesCalendar1.SelectedDateChanged Me.Edit2.Text = Me.Calendar1.SelectedDate End Sub Private Sub Button4_MouseHover(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Button4.MouseHover Me.BalloonTip1.Show(Me.Button4) End Sub Private Sub Button4_MouseLeave(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Button4.MouseLeave Me.BalloonTip1.Hide() End Sub Private Sub Button6_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button6.Click Me.Close() End Sub End Class
まとめ
InputMan for .NET 4.0Jの一部のコントロールを使用して、Excelにデータを入力するフォームを作成してみました。Visual Studioの標準コントロールでもできますが、より使い勝手のよいアプリケーションに仕上げ、なおかつ他のアプリケーションと差をつけるなら、InputMan for .NET 4.0Jの各コンポーネントを使うのがオススメです。
InputMan for .NET 4.0Jには、まだまだ便利なコントロールがありますので、次回は別のコントロールを使ったアプリケーション作成例を紹介します。