Vous êtes sur la page 1sur 8

http://www.homeandlearn.co.uk/net/nets4p15.

html
http://www.java2s.com/Code/VB/GUI/CheckBo.htm
TO OPEN A NEW WEB FORM
Right click on the project name in the solution explorer ->in the menu select add-
>new item->in the dialog box which opens select windows form and click add
to move from one form to another on click of button
Dim F2 As New Form2()
F2.Show()
Me.hide()
Button, label, textbox
Public Class Form1
Private Sub Button1_Clic(B!"al sen#er As S!stem.$b%ect& B!"al e As
S!stem.'ventAr(s) )an#les Button1.Clic
Dim a As *nte(er
Dim b As *nte(er
Dim c As *nte(er
+e.BacColor , Color.Blue
a , "al(-e.tBo.1.-e.t)
b , "al(-e.tBo.2.-e.t)
c , a / b
0abel2.-e.t , c.-oStrin(
'n# Sub
'n# Class
Check box election !"rou# box
Public Class Form2
Dim str As Strin(
Private Sub Button1_Clic(B!"al sen#er As S!stem.$b%ect& B!"al e As
S!stem.'ventAr(s) )an#les Button1.Clic
str , 1 1
*2 ChecBo.1.ChecState , 1 -hen
str , str / ChecBo.1.-e.t
+s(Bo.(1Chece# 11)
'n# *2
*2 ChecBo.2.ChecState , 1 -hen
str , str / ChecBo.2.-e.t
+s(Bo.(1Chece# 21)
'n# *2
*2 ChecBo.3.ChecState , 1 -hen
str , str / ChecBo.3.-e.t
+s(Bo.(1Chece# 31)
'n# *2
0abel1.-e.t , str
'n# Sub
'n# Class
Ra$ioButton Control
Public Class Form2
Dim str As Strin(

Private Sub Button1_Clic(B!"al sen#er As S!stem.$b%ect& B!"al e As
S!stem.'ventAr(s) )an#les Button1.Clic
*2 4a#ioButton5.Chece# , -rue -hen
str , 4a#ioButton5.-e.t
'lse*2 4a#ioButton6.Chece# , -rue -hen
str , 4a#ioButton6.-e.t

'n# *2
0abel1.-e.t , str
'n# Sub
Private Sub Button2_Clic(B!"al sen#er As S!stem.$b%ect& B!"al e As
S!stem.'ventAr(s) )an#les Button2.Clic
*2 4a#ioButton1.Chece# , -rue -hen
BacColor , Color.4e#
str , 4a#ioButton1.-e.t
'lse*2 4a#ioButton2.Chece# , -rue -hen
BacColor , Color.7reen
str , 4a#ioButton2.-e.t
'lse*2 4a#ioButton3.Chece# , -rue -hen
BacColor , Color.Blue
str , 4a#ioButton3.-e.t

'n# *2
0abel2.-e.t , 1u selecte# 1 / vbNew0ine / str
'n# Sub
'n# Class
%ink %abel
O#en other form
Private Sub 0in0abel1_0inClice#(B!"al sen#er As S!stem.$b%ect& B!"al
e As S!stem.8in#ows.Forms.0in0abel0inClice#'ventAr(s) )an#les
0in0abel1.0inClice#
Dim F2 As New Form1()
F2.Show()
+e.)i#e()
'n# Sub
'n# Class
O#en &ebite
Private Sub 0in0abel1_0inClice#(B!"al sen#er As S!stem.$b%ect& B!"al
e As S!stem.8in#ows.Forms.0in0abel0inClice#'ventAr(s) )an#les
0in0abel1.0inClice#
S!stem.Dia(nostics.Process.Start(1www.(oo(le.com1)
'n# Sub
'n# Class
Combo Box'
Public Class Form3

Private Sub ComboBo.1_Selecte#*n#e.Chan(e#(B!"al sen#er As S!stem.$b%ect&
B!"al e As S!stem.'ventAr(s) )an#les ComboBo.1.Selecte#*n#e.Chan(e#
0abel1.-e.t , 19 Selecte# : : 1 / ComboBo.1.Selecte#*tem

'n# Sub
'n# Class
(ate time Picker'
Private Sub Date-imePicer1_"alueChan(e#(B!"al sen#er As S!stem.$b%ect& B!"al
e As S!stem.'ventAr(s) )an#les Date-imePicer1."alueChan(e#

0abel1.-e.t , Date-imePicer1.-e.t ; onl! #ate(2ormat,short)we can also
customise the 2ormat b! chan(in( 2ormat,customn set value in custom2ormat ,
value
-e.tBo.1.-e.t , Date-imePicer1."alue ;2ull #ate with time
'n# Sub
%itbox'

Button:
Private Sub Button1_Clic(B!"al sen#er As S!stem.$b%ect& B!"al e As
S!stem.'ventAr(s) )an#les Button1.Clic
Dim *tem As Strin(
<1)ere are the multi=le selecte# items: 1
For 'ach *tem *n 0istBo.1.Selecte#*tems
0istBo.2.*tems.A##(*tem.-oStrin(())
Ne.t
8hile 0istBo.1.Selecte#*tems.Count > ?
0istBo.1.*tems.4emove(0istBo.1.Selecte#*tem)
'n# 8hile

<sin(le selecte# item
*2 0istBo.1.Selecte#*n#e. @> A1 -hen
0istBo.2.*tems.A##(0istBo.1.Selecte#*tem.-oStrin(())
*2 0istBo.1.Selecte#*n#e. @> A1 -hen
0istBo.1.*tems.4emoveAt(0istBo.1.Selecte#*n#e.)
'n# *2
'n# *2
'n# Sub
On item click'
Private Sub 0istBo.1_Selecte#*n#e.Chan(e#(B!"al sen#er As S!stem.$b%ect& B!"al
e As S!stem.'ventAr(s) )an#les 0istBo.1.Selecte#*n#e.Chan(e#
<sin(le selecte#
*2 0istBo.1.Selecte#*n#e. @> A1 -hen
0istBo.2.*tems.A##(0istBo.1.Selecte#*tem.-oStrin(())
*2 0istBo.1.Selecte#*n#e. @> A1 -hen
0istBo.1.*tems.4emoveAt(0istBo.1.Selecte#*n#e.)
'n# *2
'n# *2
'n# Sub
Chan"in" #icture in #icture box uin" o#en)le $ialo" box'
Private Sub Button2_Clic(B!"al sen#er As S!stem.$b%ect& B!"al e As
S!stem.'ventAr(s) )an#les Button2.Clic
*2 $=enFileDialo(1.ShowDialo(() , Dialo(4esult.$B -hen
s , $=enFileDialo(1.FileName
-e.tBo.1.-e.t , s
PictureBo.1.*ma(e , *ma(e.FromFile(s)
'n# *2
'n# Sub
Workin" &ith $ialo" boxe'
*m=orts S!stem.*$
Public Class Form1
Private Sub Button1_Clic(B!"al sen#er As S!stem.$b%ect& B!"al e As
S!stem.'ventAr(s) )an#les Button1.Clic
4ich-e.tBo.1.-e.t , 1 1
<clears the te.t in richte.tbo.
'n# Sub
Private FileName As Strin(
<#eclarin( 2ilename that will be selecte#
Dim sr As Stream4ea#er
<streamrea#er is use# to rea# te.t
Private Sub $=en-oolStri=+enu*tem_Clic(B!"al sen#er As S!stem.$b%ect&
B!"al e As S!stem.'ventAr(s) )an#les $=en-oolStri=+enu*tem.Clic
-r!
8ith $=enFileDialo(1
<8ith statement is use# to e.ecute statements usin( a
=articular ob%ect& here&_
<$=enFileDialo(1
.Filter , 1-e.t 2iles (C.t.t)DC.t.tD1 E 1All 2ilesDC.C1
<settin( 2ilters so that -e.t 2iles an# All Files choice
a==ears in the Files o2 -!=e bo.
<in the #ialo(
*2 .ShowDialo(() , 8in#ows.Forms.Dialo(4esult.$B -hen
<showDialo( metho# maes the #ialo( bo. visible at run
time
FileName , .FileName
sr , New Stream4ea#er(.$=enFile)
<usin( streamrea#er to rea# the o=ene# te.t 2ile
4ich-e.tBo.1.-e.t , sr.4ea#-o'n#()
<#is=la!in( te.t 2rom streamrea#er in richte.tbo.
'n# *2
'n# 8ith
Catch es As '.ce=tion
+essa(eBo..Show(es.+essa(e)
Finall!
*2 Not (sr *s Nothin() -hen
sr.Close()
'n# *2
'n# -r!
'n# Sub
Private Sub Save-oolStri=+enu*tem_Clic(B!"al sen#er As S!stem.$b%ect&
B!"al e As S!stem.'ventAr(s) )an#les Save-oolStri=+enu*tem.Clic
Dim sw As Stream8riter
<streamwriter is use# to write te.t
-r!
8ith SaveFileDialo(1
.FileName , FileName
.Filter , 1-e.t 2iles (C.t.t)DC.t.tD1 E 1All 2ilesDC.C1
*2 .ShowDialo(() , 8in#ows.Forms.Dialo(4esult.$B -hen
FileName , .FileName
sw , New Stream8riter(FileName)
<usin( streamwriter to write te.t 2rom richte.tbo. an#
savin( it
sw.8rite(4ich-e.tBo.1.-e.t)
'n# *2
'n# 8ith
Catch es As '.ce=tion
+essa(eBo..Show(es.+essa(e)
Finall!
*2 Not (sw *s Nothin() -hen
sw.Close()
'n# *2
'n# -r!
'n# Sub
Private Sub Font-oolStri=+enu*tem_Clic(B!"al sen#er As S!stem.$b%ect&
B!"al e As S!stem.'ventAr(s) )an#les Font-oolStri=+enu*tem.Clic
-r!
8ith FontDialo(1
.Font , 4ich-e.tBo.1.Font
<initialiFin( the #ialo( bo. to match the 2ont use# in the
richte.tbo.
.Color , 4ich-e.tBo.1.ForeColor
<#e2ault color is Blac
*2 .ShowDialo( , 8in#ows.Forms.Dialo(4esult.$B -hen
setFont()
<callin( a metho# setFont() to set the selecte# 2ont an#
color
'n# *2
'n# 8ith
Catch es As '.ce=tion
+essa(eBo..Show(es.+essa(e)
'n# -r!
'n# Sub
Private Sub setFont()
-r!
8ith FontDialo(1
4ich-e.tBo.1.Font , .Font
*2 .ShowColor -hen
4ich-e.tBo.1.ForeColor , .Color
<settin( the color
'n# *2
'n# 8ith
Catch e. As '.ce=tion
+essa(eBo..Show(e..+essa(e)
'n# -r!
'n# Sub
Private Sub Color-oolStri=+enu*tem_Clic(B!"al sen#er As S!stem.$b%ect&
B!"al e As S!stem.'ventAr(s) )an#les Color-oolStri=+enu*tem.Clic
Static CustomColors() As *nte(er , G47B(266& ?& ?)& 47B(?& 266& ?)&
47B(?& ?& 266)H
<initialiFin( CustomColors with an arra! o2 inte(ers an# =uttin( 4e#&
7reen&
<an# Blue in the custom colors section
-r!
8ith ColorDialo(1
.Color , 4ich-e.tBo.1.ForeColor
<initialiFin( the selecte# color to match the color currentl!
use#
<b! the richte.tbo.<s 2ore(roun# color
.CustomColors , CustomColors
<2illin( custom colors on the #ialo( bo. with the arra!
#eclare# above
*2 .ShowDialo(() , 8in#ows.Forms.Dialo(4esult.$B -hen
4ich-e.tBo.1.ForeColor , .Color
CustomColors , .CustomColors
<Storin( the custom colors to use a(ain
'n# *2
ColorDialo(1.4eset()
<resettin( all colors in the #ialo( bo.
'n# 8ith
Catch es As '.ce=tion
+essa(eBo..Show(es.+essa(e)
'n# -r!
'n# Sub
Private Sub Form1_0oa#(B!"al sen#er As S!stem.$b%ect& B!"al e As
S!stem.'ventAr(s) )an#les +!Base.0oa#
'n# Sub
'n# Class
Pro"re bar' (using timer)
Dim 22 As New Form2
Private Sub Form3_0oa#(B!"al sen#er As S!stem.$b%ect& B!"al e As
S!stem.'ventAr(s) )an#les +!Base.0oa#

Pro(ressBar1.Ste= , 21
Pro(ressBar1."alue , ?
Button5.'nable# , False
-imer1.'nable# , -rue
'n# Sub
Private Sub -imer1_-ic(B!"al sen#er As S!stem.$b%ect& B!"al e As
S!stem.'ventAr(s) )an#les -imer1.-ic

Pro(ressBar1.Per2ormSte=()
*2 Pro(ressBar1."alue >, Pro(ressBar1.+a.imum -hen
-imer1.'nable# , False
Button5.'nable# , -rue
22.Show()
+e.)i#e()
'n# *2
'n# Sub

Vous aimerez peut-être aussi