Usando o frame, botão de opções e shape. 1. Objetos pertencentes ou não ao frame 2. Tipos de...

Post on 17-Apr-2015

104 views 1 download

Transcript of Usando o frame, botão de opções e shape. 1. Objetos pertencentes ou não ao frame 2. Tipos de...

Usando o frame, botão de opções e shape

1. Objetos pertencentes ou não ao frame

2. Tipos de shape

Valor Descrição0 Rectângulo1 Quadrado2 Oval3 Círculo4 Retângulo arredondado5 Quadrado arredondado

Shape1.shape = valor

3. Aplicação- Projeto4

Aplicativo que calcula a área e o perímetro de um quadrado ou de um círculo

Private Sub Option1_Click(Index As Integer)Rem *** inicialização ***Text1.Text = ""Label2.Caption = "Área = "Label3.Caption = "Perímetro = "

Rem ***seleção da figura *****Select Case IndexCase 0 Shape1.Shape = 1 Label1.Caption = "Lado"Case 1 Shape1.Shape = 3 Label1.Caption = "Raio"End SelectEnd Sub

Private Sub Command1_Click()pi = 3.1415a$ = Text1.Textr = Val(a$)If Option1(0).Value = True Then area = r * r perim = 4 * rElse area = pi * r * r perim = 2 * pi * rEnd IfLabel2.Caption = "Área = " + Str(area)Label3.Caption = "Perímetro = " + Str(perim)End Sub

4. Aplicação- Projeto5

Aplicativo que demonstrativo dos vários tipos de variáveis e constantes

DefInt ADefLng BDefSng CDefDbl DDefBool F

Private Sub Option1_Click(Index As Integer)Select Case IndexCase 0 a = Sqr(2) Label2.Caption = aCase 1 b = Sqr(2) Label2.Caption = bCase 2 c = Sqr(2) Label2.Caption = cCase 3 d = Sqr(2) Label2.Caption = dCase 4 Label2.Caption = "Sqr(2)"Case 5 f = True Label2.Caption = fCase 6 Label2.Caption = DateCase 7 Label2.Caption = TimeEnd Select

Usando o list e combo

1.1 Adicionando itens

object.AddItem item

For i = 1 To 10 List1.AddItem i Combo1.AddItem iNext i

1.2 Inicializando

object.AddItem clear

Combo1.ClearList1.Clear

1.3 Ordenando - propriedade

Combo1.sorted= trueList1.sorted =true

1.4 Associando valores

Combo1.itemData(Combo1.newIndex) = valorList1. itemData(List1.newIndex) = valor

1. Métodos importantes aplicados aos combos e listbox

1.5 Identificando o item selecionado

Item = combo1.ListIndexOs itens variam de 0 a nValor = -1 significa que nenhum item foi selecionado

1.6 Quantidade de itens em um combo

quant = Combo1.ListCount

1.7 Valor e descrição do item selecionado

valor = Combo1.ItemData(Item)nome$ = Combo1.List(Item)

1.8 Texto da caixa de entrada do combo

texto$ = Combo1.Text

2. Aplicação Projeto6

Private Sub Combo1_Click()Item = Combo1.ListIndex + 1 Label2.Caption = Itemquant = Combo1.ListCount Label3.Caption = quantdado = Combo1.ItemData(Item - 1) Label4.Caption = dadonome$ = Combo1.List(Item - 1) Label5.Caption = nome$texto$ = Combo1.Text Label6.Caption = texto$End Sub

Private Sub Form_Load()Rem lembrar que: Combo1.Sorted = TrueCombo1.ClearCombo1.AddItem "Milho": Combo1.ItemData(Combo1.NewIndex) = 20Combo1.AddItem "Ervilha": Combo1.ItemData(Combo1.NewIndex) = 14Combo1.AddItem "Drosófila": Combo1.ItemData(Combo1.NewIndex) = 8Combo1.AddItem "Esp. Humana": Combo1.ItemData(Combo1.NewIndex) = 46Combo1.AddItem "Cavalo": Combo1.ItemData(Combo1.NewIndex) = 64End Sub

3. Aplicação Projeto7

Selecionando itens numa caixa listbox

Private Sub Form_Load()List1.ClearList2.ClearList1.AddItem "Macaco": List1.ItemData(List1.NewIndex) = 1List1.AddItem "Alface": List1.ItemData(List1.NewIndex) = 2List1.AddItem "Rato": List1.ItemData(List1.NewIndex) = 1List1.AddItem "Cavalo": List1.ItemData(List1.NewIndex) = 1List1.AddItem "Tomate": List1.ItemData(List1.NewIndex) = 2List1.AddItem "Couve": List1.ItemData(List1.NewIndex) = 2List1.AddItem "Porco": List1.ItemData(List1.NewIndex) = 1List1.AddItem "Galinha": List1.ItemData(List1.NewIndex) = 1List1.AddItem "Beterraba": List1.ItemData(List1.NewIndex) = 2List1.AddItem "Pato": List1.ItemData(List1.NewIndex) = 1End Sub

Private Sub List1_Click()Item = List1.ListIndex + 1 Label2.Caption = Itemquant = List1.ListCount Label3.Caption = quant - 1: Rem um item será excluídodado = List1.ItemData(Item - 1) Label4.Caption = dadonome$ = List1.List(Item - 1) Label5.Caption = nome$texto$ = List1.Text Label6.Caption = texto$ If dado = 2 Then List2.AddItem List1.List(Item - 1) List1.RemoveItem Item - 1Else r$ = MsgBox("Você errou!")End If

End Sub Private Sub List2_Click() Item = List2.ListIndex + 1 List1.AddItem List2.List(Item - 1): List1.ItemData(List1.NewIndex) = 2 List2.RemoveItem Item - 1End Sub

Usando timer, picturebox e image

1. Timer – Controla intervalos de tempo determinados pelo programador.

1.1. Propriedades:Timer1.enabled = 1 (true)Timer1.enabled = 0 (false)Timer1.interval = 100 retona o próximo evento em n milesecundos

1.2. Aplicação

Private Sub Form_Load()Timer1.Enabled = 1Timer1.Interval = 100

End Sub

Private Sub Timer1_Timer() Label1.Caption = TimeEnd Sub

2. Picturebox: Recebe figuras e possibilita inclusão de gráficos, textos e desenhos

Picture1.cls : Limpa o gráfico ou texto gerado em tempo de execução em um Form ou PictureBox. Picture1.AutoRedraw : true: define gráfico persistente

false: retorna ao modográfico

Private Sub Command1_Click() Picture1.ClsEnd Sub

Private Sub Command2_Click() Picture1.ForeColor = RGB(255, 0, 0) For I = 5 To 95 Step 10 ' Draw lines. Picture1.Line (I, 0)-(I, 100) NextEnd Sub

Private Sub Form_Load() Picture1.ScaleHeight = 100 Picture1.ScaleWidth = 100 Picture1.ScaleMode = 3 Picture1.AutoRedraw = True Picture1.ForeColor = 0 Picture1.FillColor = QBColor(9) Picture1.FillStyle = 0 Picture1.Circle (50, 50), 30 Picture1.AutoRedraw = FalseEnd Sub

2.1. Propriedades

2.2. Aplicação

Picture1.ScaleMode Define a unidade de medida das coordenadas gráficas

VbTwips 1 (Default) Twip (1440 twips per logical inch; 567 twips per logical centimeter).VbPoints2 Point (72 points per logical inch).VbPixels3 Pixel (smallest unit of monitor or printer resolution).vbCharacters 4 Character (horizontal = 120 twips per unit; vertical = 240 twips per unit).VbInches 5 Inch.VbMillimeters 6 Millimeter.VbCentimeters 7 Centimeter.

Picture1.Scale (x1, y1)-(x2, y2) : Define as amplitudes de coordenadas do objeto

Picture1.BackColor = RGB(255, 255, 255): Define a cor de fundo do picturebox

Picture1.ForeColor = RGB(0, 0, 0) : define a cor de frente do picturebox

Picture1.CurrentX = 1000 Posiciona o texto na coordenada X do picturebox

Picture1.CurrentY = 1000 Posiciona o texto na coordenada Y do picture box

2.3. Propriedades importantes

Picture1.Print texto$ :Adiciona o texto na posição X,Y do picturebox

Picture1.PSet (x1,Y1), cor : plota um ponto, na cor especificada, na coordenada X1,Y1

Picture1.Line (x1,y1)-(x2,y2), cor: desenha uma reta ligando as coordenadas (x1,y1) a (x2,y2)

Picture1.Line (x1,x2)-(y1,y2),cor,B :desenha um box dentro das coordenadas (x1,y1)a (x2,y2)

Picture1.Line (x1,x2)-(y1,y2),cor,BF :desenha um quadrado dentro das coordenadas (x1,y1)a (x2,y2)

Picture1.Picture = Loadpicture(“local e nome da figura”) : Carrega uma figura

Picture1.move = Picture.left +k1,Picture.Top +k2 : Desloca a figura de sua posição original (X,Y) para a posição (X+k1, Y+k2).Picture1.Visible = True (ou False): Deixa a figura visível ou invisível

Picture1.picture = Picture2.picture : Copia a figura da Picture2 para a Picture1.

2.4 Aplicação

Private Sub Form_Load()Rem Picture1.Picture = LoadPicture("C:\vbcurso\figuras\imagem1.bmp")Picture1.ClsPicture1.AutoRedraw = TruePicture1.ScaleMode = 3Picture1.Scale (100, 100)-(2000, 2000)Picture1.BackColor = RGB(255, 255, 255)INICIOX = 200: INICIOY = 200: FIMX = 1800: FIMY = 1800Rem *** textoPicture1.CurrentX = 1000Picture1.CurrentY = 1000Picture1.Print "Teste"

Rem *** pontosPicture1.PSet (400, 200), RGB(0, 255, 0)Picture1.PSet (600, 200), RGB(0, 255, 255)Picture1.PSet (800, 200), RGB(255, 0, 255)Rem *** eixo yPicture1.Line (200, 200)-(200, 1800), RGB(0, 0, 255)Rem *** eixo xPicture1.Line (200, 1800)-(1800, 1800), RGB(0, 0, 255)Rem *** círculoPicture1.Circle (1500, 1500), 50, RGB(0, 255, 255)Rem *** boxPicture1.Line (400, 400)-(1600, 1600), RGB(0, 0, 255), BRem *** quadradoPicture1.Line (1300, 1300)-(1350, 1350), RGB(0, 0, 255), BFEnd Sub

Image1.picture = LoadPicture(“nome da figura”) : Carrega uma figura

Image1.DragMode= 1 (automatic): Habilita a condição de arraste da imagem

Image1.DragIcon : Atribui um ícone á imagem quando ela está sendo arrastada

Image1.Tag = string$: Atribui um valor à imagem, permitindo sua identificação

Image1.picture = image2.picture : Copia a figura da image2 para a image1.

3. Imagem: Carrega um figura

3.1 Propriedade

3.2 Aplicação – Projeto12- Utilização de imagens, com possibilidade de arraste e deslocamento

Private Sub Image1_DragDrop(Source As Control, X As Single, Y As Single) Source.Visible = False If Source.Tag = "Fogo" Then Image1.Picture = Image6.Picture Picture1.Visible = True Timer1.Enabled = True End IfEnd Sub

Private Sub Timer1_Timer() If Picture1.Top > 0 Then Picture1.Move Picture1.Left - 50, Picture1.Top - 75 Else Picture1.Visible = False Timer1.Enabled = False End IfEnd Sub

Usando DriverList, FileList, DirList, HScrollBar, VScrollBar e CommonDialog

1.DriveListBox: Retorna o drive de acesso do aplicativo

Private Sub Drive1_Change() Dir1.Path = Drive1.DriveEnd Sub

Dir1.Path = Drive1.Drive atribui ao objeto DirListBox o drive de acesso

2. DirListBox: Retorna o diretório de acesso do aplicativo

Private Sub Dir1_Change() File1.Path = Dir1.PathEnd Sub

File1.Path = Dir1.Path atribui ao objeto FileListBox o diretório de acesso

3. FileListBox: Retorna o arquivo de acesso do aplicativo

File1.Visible = False Torna o objeto invisívelFile1.filename : nome do arquivo selecionado

File1.Pattern = "*.dat;*.txt;*.*“ : extensões dos arquivos listados

numarq = File1.ListCount : número de arquivos listados

4. Aplicação: Projeto 13

Private Sub Drive1_Change() Dir1.Path = Drive1.DriveEnd Sub

Private Sub Dir1_Change() File1.Pattern = "*.bmp" File1.Path = Dir1.Path numarq = File1.ListCount Label1.Caption = "Total de arquivos: " + Str(numarq)End Sub

Private Sub File1_Click() ArquivoSelecionado = File1.Path & "\" & File1.filename Image1.Picture = LoadPicture(ArquivoSelecionado)End Sub

HScroll1.Min : especifica o valor mínimo da barra de rolagem

HScroll1.Max: especifica o valor máximo da barra de rolagem

Valor =HScroll1.value : especifica o valor atual da barra de rolagem

5. Barra de Rolagem

5.1 Propriedades

5.2 Aplicação – Projeto 14

Private Sub Form_Load() 'posição inicial da imagem de animação picAnimate.Left = 0 - picAnimate.Width picAnimate.Top = 500 HScroll1.Min = 1 HScroll1.Max = 300 HScroll1.Value = 100End Sub

Private Sub HScroll1_Change() Timer1.Interval = HScroll1.Max - HScroll1.ValueEnd Sub

Private Sub Timer1_Timer()Static numpic If numpic = 7 Then numpic = -1 numpic = numpic + 1 picAnimate.Left = picAnimate.Left + 400'determina se a imagem está fora da figura If (picAnimate.Left) > ScaleWidth Then picAnimate.Left = -3600 picAnimate.Picture = imgLeopard(numpic).PictureEnd Sub

6. Usando CommonDialog

Abrir arquivosSalvar comoImprimirColorirFormatar

Private Sub Command1_Click() On Error Resume Next With CommonDialog1 .CancelError = True .DialogTitle = "Abrir" .DefaultExt = "rtf" .Filter = "textos (*.txt, *.dat) |*.txt; *.dat| todos (*.*)|*.*|" .FilterIndex = 1 .Flags = cdlOFNFileMustExist + cdlOFNExplorer + cdlOFNLongNames .ShowOpen End With

Label1.Caption = CommonDialog1.filename

End Sub

6.2 Abrir arquivos

6.1 Finalidades

6.4 Imprimir

Private Sub Command2_Click() On Error Resume Next With CommonDialog1 .CancelError = True .DialogTitle = "Salvar como" .DefaultExt = "rtf" .Filter = "textos (*.txt, *.dat) |*.txt; *.dat| todos (*.*)|*.*|" .FilterIndex = 1 .Flags = cdlOFNFileMustExist + cdlOFNExplorer + cdlOFNLongNames .ShowSave End With

Label2.Caption = CommonDialog1.filenameEnd Sub

Private Sub Command3_Click()On Error Resume Next With CommonDialog1 .CancelError = True .DialogTitle = "Imprimir" .Flags = cdlPDReturnDC + cdlPDNoPageNums .ShowPrinter End WithEnd Sub

6.3 Salvar como

Private Sub Command4_Click()On Error Resume Next With CommonDialog1 .CancelError = True .DialogTitle = "Cor" .ShowColor End With Label3.ForeColor = CommonDialog1.ColorEnd Sub

6.5. Colorir

6.6. Formatar fonte Private Sub Command5_Click()On Error Resume Next With CommonDialog1 .CancelError = True .DialogTitle = "Fonte" .Flags = cdlCFBoth + cdlCFEffects .ShowFont End With With Label4 .FontName = CommonDialog1.FontName .FontSize = CommonDialog1.FontSize .FontBold = CommonDialog1.FontBold .FontItalic = CommonDialog1.FontItalic .FontStrikethru = CommonDialog1.FontStrikethru .FontUnderline = CommonDialog1.FontUnderline .ForeColor = CommonDialog1.Color End With End Sub

6.7. Aplicação – projeto 15