Color Dialog: Changing the background and text colors of a form : Color « 2D « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » 2D » ColorScreenshots 
Color Dialog: Changing the background and text colors of a form
Color Dialog: Changing the background and text colors of a form

Imports System
Imports System.Drawing
Imports System.Windows.Forms

Public Class MainClass

   Shared Sub Main()
        Dim myform As Form = New FrmColorDialogTest()
        Application.Run(myform)
   End Sub ' Main

End Class


Public Class FrmColorDialogTest
   Inherits System.Windows.Forms.Form

   Friend WithEvents cmdBackgroundButton As Button
   Friend WithEvents cmdTextButton As Button

#Region " Windows Form Designer generated code "

   Public Sub New()
      MyBase.New()

      'This call is required by the Windows Form Designer.
      InitializeComponent()

      'Add any initialization after the InitializeComponent() call

   End Sub

   'Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      If disposing Then
         If Not (components Is NothingThen
            components.Dispose()
         End If
      End If
      MyBase.Dispose(disposing)
   End Sub

   'Required by the Windows Form Designer
   Private components As System.ComponentModel.Container

   'NOTE: The following procedure is required by the Windows Form Designer
   'It can be modified using the Windows Form Designer.  
   'Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
      Me.cmdBackgroundButton = New System.Windows.Forms.Button()
      Me.cmdTextButton = New System.Windows.Forms.Button()
      Me.SuspendLayout()
      '
      'cmdBackgroundButton
      '
      Me.cmdBackgroundButton.Location = New System.Drawing.Point(1616)
      Me.cmdBackgroundButton.Name = "cmdBackgroundButton"
      Me.cmdBackgroundButton.Size = New System.Drawing.Size(16024)
      Me.cmdBackgroundButton.TabIndex = 0
      Me.cmdBackgroundButton.Text = "Change Background Color"
      '
      'cmdTextButton
      '
      Me.cmdTextButton.Location = New System.Drawing.Point(1656)
      Me.cmdTextButton.Name = "cmdTextButton"
      Me.cmdTextButton.Size = New System.Drawing.Size(16024)
      Me.cmdTextButton.TabIndex = 1
      Me.cmdTextButton.Text = "Change Text Color"
      '
      'FrmColorDialogTest
      '
      Me.AutoScaleBaseSize = New System.Drawing.Size(513)
      Me.ClientSize = New System.Drawing.Size(19293)
      Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.cmdTextButton, Me.cmdBackgroundButton})
      Me.Name = "FrmColorDialogTest"
      Me.Text = "Using Color Dialogs"
      Me.ResumeLayout(False)

   End Sub

#End Region

   Private Sub cmdTextButton_Click(ByVal sender As System.Object, _
      ByVal e As System.EventArgsHandles cmdTextButton.Click

      Dim colorBox As ColorDialog = New ColorDialog()
      Dim result As DialogResult

      result = colorBox.ShowDialog()
      If result = DialogResult.Cancel Then
         Return
      End If

      cmdBackgroundButton.ForeColor = colorBox.Color
      cmdTextButton.ForeColor = colorBox.Color
   End Sub 

   Private Sub cmdBackgroundButton_Click_
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs_
      Handles cmdBackgroundButton.Click

      Dim colorBox As ColorDialog = New ColorDialog()
      Dim result As DialogResult

      colorBox.FullOpen = True
      result = colorBox.ShowDialog()

      If result = DialogResult.Cancel Then
         Return
      End If

      Me.BackColor = colorBox.Color
   End Sub  

End Class 
           
       
Related examples in the same category
1.Get all Known color and calcuate its Brightness and SaturationGet all Known color and calcuate its Brightness and Saturation
2.Track Form background ColorTrack Form background Color
3.Using different colors in Visual BasicUsing different colors in Visual Basic
4.Construct Color from R G B ValueConstruct Color from R G B Value
5.Use color dialog to set form backgroundUse color dialog to set form background
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.