DotNetWebTutor.com                                                    Link to Us

Color
All controls have backcolor and forecolor
Ways to make color:

  • ARBG(alpha, red, green, blue) (0-255)
  • Predefined .net color name
  • Html color name
  • OLE color name
  • Win32 color code
  • Choose name from systemcolors class

Argb Example
Dim alpha as integer=255, red as integer=0
Dim green as integer=255, blue as integer=0
Control.forecolor=color.fromArgb(alpha, red, green, blue)

Color from environment setting:
Control.backcolor=system.color.highlighttext

.net name:
control.backcolor=color.blue

html name:
control.backcolor=colorTranslator.fromHTML(“red”)

Forecolor and backcolor of controls are ambient properties
If not set they inherit from their parent container
Font and cursor are also ambient properties

.net controls alphablending

Alphablending
Alpha is transparency from 0-255

Example (first number in fromARGB is alpha number)
Label1.backcolor=color.fromargb(0,label1,backcolor)

Basic .net controls do not handle transparency well
visual basic fonts and text
Fonts and text
Font property determines the Font of a control’s text

Controlname.font=new font(“verdana”,10,fontstyle.bold)

Font family is set with a string
If font is not installed, it reverts to Microsoft’s san serif font
You should check the font first

Example:

  • Start a new project
  • Add a listbox
  • Add this code to the form_load event:

Dim fonts As New System.Drawing.Text.InstalledFontCollection()
For Each fontName As FontFamily In fonts.families
ListBox1.Items.Add(fontName.Name)
Nextvb accesskeys on controls
AccessKeys
Buttons and menus allow a character in the text to be highlighted as an access key

Placing an ampersand (&) in front of a letter underlines that letter and makes it an access key

The user can press ALT and the key to activate it
tab sequence and focus in visual basic
Tab Sequence and Focus
One control at a time has the focus
A focused control gets the user’s key presses

A user clicks another control with the mouse or the tab key to move the focus to another control

The tab should move the focus in a predictable way
Most controls have a tabStop property
If true that control can receive the focus

Tabindex property lets you set the tab order
Tabindex of 0 gets the focus first

From the menu select View | tab order
Then you can assign tab order by clicking the controls in order you want them.

Example:

  • Start a new project:
  • Add 8 button controls
  • Mix them up so they tab order is wrong

buttons for tab

  • Click the View menu and select tab order

menu taborder

  • Click them in the order you want them:

buttons with taborder

  • Click View and tab order again to exit it

hide controls
Hide controls
Set the visible property
disable control
Disable a control
Set the enabled property
taborder in visual basic