1 / 28

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

Usando o frame, botão de opções e shape. 1. Objetos pertencentes ou não ao frame. 2. Tipos de shape. Shape1.shape = valor. Valor Descrição 0 Rectângulo 1 Quadrado 2 Oval 3 Círculo 4 Retângulo arredondado 5 Quadrado arredondado. 3. Aplicação- Projeto4.

onan
Télécharger la présentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 1. Objetos pertencentes ou não ao frame 2. Tipos de shape Shape1.shape = valor Valor Descrição 0 Rectângulo 1 Quadrado 2 Oval 3 Círculo 4 Retângulo arredondado 5 Quadrado arredondado

  3. 3. Aplicação- Projeto4 Aplicativo que calcula a área e o perímetro de um quadrado ou de um círculo Private Sub Command1_Click() pi = 3.1415 a$ = Text1.Text r = Val(a$) If Option1(0).Value = True Then area = r * r perim = 4 * r Else area = pi * r * r perim = 2 * pi * r End If Label2.Caption = "Área = " + Str(area) Label3.Caption = "Perímetro = " + Str(perim) End Sub 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 Index Case 0 Shape1.Shape = 1 Label1.Caption = "Lado" Case 1 Shape1.Shape = 3 Label1.Caption = "Raio" End Select End Sub

  4. 4. Aplicação- Projeto5 Aplicativo que demonstrativo dos vários tipos de variáveis e constantes DefInt A DefLng B DefSng C DefDbl D DefBool F Private Sub Option1_Click(Index As Integer) Select Case Index Case 0 a = Sqr(2) Label2.Caption = a Case 1 b = Sqr(2) Label2.Caption = b Case 2 c = Sqr(2) Label2.Caption = c Case 3 d = Sqr(2) Label2.Caption = d Case 4 Label2.Caption = "Sqr(2)" Case 5 f = True Label2.Caption = f Case 6 Label2.Caption = Date Case 7 Label2.Caption = Time End Select

  5. Usando o list e combo

  6. 1. Métodos importantes aplicados aos combos e listbox 1.1 Adicionando itens object.AddItem item For i = 1 To 10 List1.AddItem i Combo1.AddItem i Next i 1.2 Inicializando object.AddItem clear Combo1.Clear List1.Clear 1.3 Ordenando - propriedade Combo1.sorted= true List1.sorted =true 1.4 Associando valores Combo1.itemData(Combo1.newIndex) = valor List1. itemData(List1.newIndex) = valor

  7. 1.5 Identificando o item selecionado Item = combo1.ListIndex Os itens variam de 0 a n Valor = -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

  8. Private Sub Form_Load() Rem lembrar que: Combo1.Sorted = True Combo1.Clear Combo1.AddItem "Milho": Combo1.ItemData(Combo1.NewIndex) = 20 Combo1.AddItem "Ervilha": Combo1.ItemData(Combo1.NewIndex) = 14 Combo1.AddItem "Drosófila": Combo1.ItemData(Combo1.NewIndex) = 8 Combo1.AddItem "Esp. Humana": Combo1.ItemData(Combo1.NewIndex) = 46 Combo1.AddItem "Cavalo": Combo1.ItemData(Combo1.NewIndex) = 64 End Sub 2. Aplicação Projeto6 Private Sub Combo1_Click() Item = Combo1.ListIndex + 1 Label2.Caption = Item quant = Combo1.ListCount Label3.Caption = quant dado = Combo1.ItemData(Item - 1) Label4.Caption = dado nome$ = Combo1.List(Item - 1) Label5.Caption = nome$ texto$ = Combo1.Text Label6.Caption = texto$ End Sub

  9. 3. Aplicação Projeto7 Selecionando itens numa caixa listbox

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

  11. Private Sub List1_Click() Item = List1.ListIndex + 1 Label2.Caption = Item quant = List1.ListCount Label3.Caption = quant - 1: Rem um item será excluído dado = List1.ItemData(Item - 1) Label4.Caption = dado nome$ = 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 - 1 Else 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 - 1 End Sub

  12. Usando timer, picturebox e image

  13. 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 = 1 Timer1.Interval = 100 End Sub Private Sub Timer1_Timer() Label1.Caption = Time End Sub

  14. 2. Picturebox: Recebe figuras e possibilita inclusão de gráficos, textos e desenhos 2.1. Propriedades 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 2.2. Aplicação 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 = False End Sub Private Sub Command1_Click() Picture1.Cls End 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) Next End Sub

  15. 2.3. Propriedades importantes 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). VbPoints 2 Point (72 points per logical inch). VbPixels 3 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.BackColor = RGB(255, 255, 255): Define a cor de fundo do picturebox Picture1.Scale (x1, y1)-(x2, y2) : Define as amplitudes de coordenadas do objeto 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

  16. 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.picture = Picture2.picture : Copia a figura da Picture2 para a Picture1. 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

  17. 2.4 Aplicação Private Sub Form_Load() Rem Picture1.Picture = LoadPicture("C:\vbcurso\figuras\imagem1.bmp") Picture1.Cls Picture1.AutoRedraw = True Picture1.ScaleMode = 3 Picture1.Scale (100, 100)-(2000, 2000) Picture1.BackColor = RGB(255, 255, 255) INICIOX = 200: INICIOY = 200: FIMX = 1800: FIMY = 1800 Rem *** texto Picture1.CurrentX = 1000 Picture1.CurrentY = 1000 Picture1.Print "Teste" Rem *** pontos Picture1.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 y Picture1.Line (200, 200)-(200, 1800), RGB(0, 0, 255) Rem *** eixo x Picture1.Line (200, 1800)-(1800, 1800), RGB(0, 0, 255) Rem *** círculo Picture1.Circle (1500, 1500), 50, RGB(0, 255, 255) Rem *** box Picture1.Line (400, 400)-(1600, 1600), RGB(0, 0, 255), B Rem *** quadrado Picture1.Line (1300, 1300)-(1350, 1350), RGB(0, 0, 255), BF End Sub

  18. 3. Imagem: Carrega um figura 3.1 Propriedade Image1.picture = LoadPicture(“nome da figura”) : Carrega uma figura Image1.picture = image2.picture : Copia a figura da image2 para a image1. 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

  19. 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 If End 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 If End Sub

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

  21. 1.DriveListBox: Retorna o drive de acesso do aplicativo Private Sub Drive1_Change() Dir1.Path = Drive1.Drive End 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.Path End 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ível File1.filename : nome do arquivo selecionado File1.Pattern = "*.dat;*.txt;*.*“ : extensões dos arquivos listados numarq = File1.ListCount : número de arquivos listados

  22. 4. Aplicação: Projeto 13 Private Sub Drive1_Change() Dir1.Path = Drive1.Drive End 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

  23. 5. Barra de Rolagem 5.1 Propriedades 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

  24. 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 = 100 End Sub Private Sub HScroll1_Change() Timer1.Interval = HScroll1.Max - HScroll1.Value End 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).Picture End Sub

  25. 6. Usando CommonDialog 6.1 Finalidades • Abrir arquivos • Salvar como • Imprimir • Colorir • Formatar 6.2 Abrir arquivos 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

  26. 6.3 Salvar como 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.filename End Sub 6.4 Imprimir Private Sub Command3_Click() On Error Resume Next With CommonDialog1 .CancelError = True .DialogTitle = "Imprimir" .Flags = cdlPDReturnDC + cdlPDNoPageNums .ShowPrinter End With End Sub

  27. 6.5. Colorir Private Sub Command4_Click() On Error Resume Next With CommonDialog1 .CancelError = True .DialogTitle = "Cor" .ShowColor End With Label3.ForeColor = CommonDialog1.Color End Sub 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

  28. 6.7. Aplicação – projeto 15

More Related