PageRenderTime 26ms CodeModel.GetById 15ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Source Code/PowerSong/Item Management/frmSetBackground.vb

#
Visual Basic | 101 lines | 68 code | 32 blank | 1 comment | 0 complexity | 2017de4f3f538d4f494d10834a70dd71 MD5 | raw file
  1Imports System.Windows.Forms
  2Imports PowerSong.SongDatabase
  3Imports PowerSong.SongDatabase.Style
  4Imports PowerSong.SongDatabase.Items
  5
  6Public Class frmSetBackground
  7
  8    Private FBackground As OverrideBackground = Nothing
  9
 10    Public ReadOnly Property Background() As OverrideBackground
 11        Get
 12            UpdateBackground()
 13            Return FBackground
 14        End Get
 15    End Property
 16
 17    Public Sub New(Optional ByVal currentBackground As OverrideBackground = Nothing)
 18
 19        InitializeComponent()
 20
 21        If currentBackground IsNot Nothing Then
 22
 23            Select Case currentBackground.Type
 24
 25                Case EBackgroundType.Image
 26                    txtBackgroundImage.Text = currentBackground.Value
 27                    optImage.Checked = True
 28
 29                Case EBackgroundType.None
 30                    optDefault.Checked = True
 31
 32                Case EBackgroundType.SolidColour
 33                    pbSolidColour.BackColor = currentBackground.Value
 34                    optSolidColour.Checked = True
 35
 36                Case Else
 37                    ' Everything else is ignored because we can't handle anything else
 38
 39            End Select
 40
 41        End If
 42
 43    End Sub
 44
 45    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
 46        Me.DialogResult = System.Windows.Forms.DialogResult.OK
 47        Me.Close()
 48    End Sub
 49
 50    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
 51        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
 52        Me.Close()
 53    End Sub
 54
 55    Private Sub btnSelectImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectImage.Click
 56
 57        If dlgOpenImage.ShowDialog = Windows.Forms.DialogResult.OK Then
 58            txtBackgroundImage.Text = dlgOpenImage.FileName
 59            optImage.Checked = True
 60        End If
 61
 62    End Sub
 63
 64    Private Sub btnSelectSolidColour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectSolidColour.Click, pbSolidColour.Click
 65
 66        If optSolidColour.Checked = False Then
 67            optSolidColour.Checked = True
 68        End If
 69
 70        dlgSelectColour.Color = pbSolidColour.BackColor
 71        If dlgSelectColour.ShowDialog = Windows.Forms.DialogResult.OK Then
 72            pbSolidColour.BackColor = dlgSelectColour.Color
 73        End If
 74
 75    End Sub
 76
 77    Private Sub UpdateBackground()
 78
 79        If optDefault.Checked Then
 80            FBackground = Nothing
 81        Else
 82
 83            If optSolidColour.Checked Then
 84                FBackground = New OverrideBackground(EBackgroundType.SolidColour, pbSolidColour.BackColor)
 85            ElseIf optImage.Checked Then
 86                FBackground = New OverrideBackground(EBackgroundType.Image, txtBackgroundImage.Text)
 87            End If
 88
 89        End If
 90
 91    End Sub
 92
 93    Private Sub optImage_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optImage.CheckedChanged
 94
 95        If optImage.Checked AndAlso txtBackgroundImage.Text = "" Then
 96            btnSelectImage_Click(sender, e)
 97        End If
 98
 99    End Sub
100
101End Class