Buchempfehlung
Mikrocomputertechnik mit Controllern der Atmel AVR-RISC-Familie
Mikrocomputertechnik mit Controllern der Atmel AVR-RISC-Familie
Umfassend, aber leicht verständlich führt dieses Buch in die Programmierung von ATMEL AVR Mikrocontrollern ein. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

Beispiel1

Uploader:Mitgliedhansholger
Datum/Zeit:25.03.2014 19:08:22

#Include "FBForms.bi"           ' FBForms.bi immer zuerst - weil :
#Include "FBControls.bi"        ' bindet andere Freebasic .bi ein


Dim Shared As FForm form1
Dim Shared As FPanel panel1,panel2,panel3,panel4
Dim Shared As FButton btn1,btn2
Dim Shared As FBmpLabel bmp1
Dim Shared As FHScrollbar HScroll,HScroll1,HScroll2

Dim Shared As FListbox Listbox1
Dim Shared As FComboBox Combo1
Dim Shared As FEdit Edit1
Dim Shared As FRichEdit Edit2
Dim Shared As FCheckbox check1


'Verwendung der Dialogbox
'------------------------
Dim Shared As FDialogBox PTR pDlgBox1
Dim Shared As FPanel PTR pDlgPanel1
Dim Shared As FButton PTR pDlgButton1

Sub Button_onClick
    pDlgBox1->Close(0) ' Wert wird von pDlgBox1->Create zurückgegeben
End Sub

Sub dlg1_OnInitdialog(ByVal hWnd As HWND)
    ' alle Control müssen hier erstellt werden
    pDlgPanel1  = New FPanel
    pDlgButton1 = New FButton

    pDlgPanel1->Create(hWnd,10,10,276,140)

    pDlgPanel1->Caption =Chr(13,10)+ " Dialogbox mit FDialogBox " +Chr(13,10)+" hat kein Menü und hat immer ein Dialog-Rahmen"
    pDlgPanel1->Border=1
    pDlgPanel1->TextAlign=4 ' mehrzeilig mitte

    pDlgButton1->Create(hWnd,"OK",100,180,100,26)
    pDlgButton1->onClick = @Button_onClick

End Sub

Sub menu_About

    Dim As Integer retVal
    pDlgBox1        = New FDialogBox

    pDlgBox1->Color = &Hefcb90                           ' Anders wie bei normaler Form
    pDlgBox1->OnInitdialog=@dlg1_OnInitdialog        ' Eigenschaften vor!! Create

    retVal = pDlgBox1->Create(Form1.Handle,"Info",300,250)

    Delete pDlgBox1  ' Speicher bereinigen
    Delete pDlgPanel1
    Delete pDlgButton1

End Sub

' ------------------- Event - Sub ----------------------------------
Sub menu_neu

    panel1.Color = &HFFFFFF
    panel2.Color = &H9F9F9F
    btn2.Color = &HdFdFdF
    btn1.Color = &HFFFFFF

End Sub

Sub menu_Exit
    form1.FormClose
End Sub

Sub Form1_onSize(ByVal w As Integer, ByVal h As Integer,ByVal flag As Integer)

    panel3.Top = h - 22
    panel3.Width = w

    panel1.Height = h - 63
    panel1.Width = w - 101

    panel2.Height = h - 63
    panel2.Width = w - 101

    panel4.Left = (w-500)/2 ' Überschrift immer Zentriert

    HScroll.Width = panel2.ClientWidth-120
    HScroll1.Width = panel2.ClientWidth-120
    HScroll2.Width = panel2.ClientWidth-120
End Sub

Sub btn1_onClick
    panel1.Visible = TRUE
    panel2.Visible = FALSE
    panel3.Caption = "Panel 1 ist aktiv"
End Sub
Sub btn2_onClick
    panel2.Visible = TRUE
    panel1.Visible = FALSE
    panel3.Caption = "Panel 2 ist aktiv"
End Sub
Sub Check1_onClick
    If Check1.Check Then
        Edit1.Password = 1
    Else
        Edit1.Password = 0
    EndIf
End Sub
Sub HScroll_Change(ByVal nPos As Integer )
    panel2.Color = rgba(HScroll2.position,HScroll1.position,HScroll.position,0)
    panel2.Invalidate
End Sub
Sub HScroll1_Change(ByVal nPos As Integer )
    panel2.Color = rgba(HScroll2.position,HScroll1.position,HScroll.position,0)
    panel2.Invalidate
End Sub
Sub HScroll2_Change(ByVal nPos As Integer )
    panel2.Color = rgba(HScroll2.position,HScroll1.position,HScroll.position,0)
    panel2.Invalidate
End Sub

'--------------------------------------------------------------------
'                  Form
'--------------------------------------------------------------------
form1.Create("Testform",0,0,870,720)
Form1.Center
Form1.Color = &Hefcb90
Form1.onSize = @Form1_onSize

'---------------  Menu ----------------------------------------------
Dim As FMenuItem mnNeu,mnSper,mnExit,mnAbout    ' Die Menu-Item

form1.menu.Create(form1.Handle)         ' Das Menu
form1.menu.CreateSubMenu("Datei")       ' Das erste Popup

mnNeu.EventSub =@menu_neu                   ' Event-Sub
form1.menu.AddItem(@mnNeu,"Neue Farben")    ' Zeiger auf das Item , Item Text

form1.menu.Seperator                            ' Seperator

mnExit.EventSub =@menu_Exit             ' Event-Sub
mnExit.addAccel(FCONTROL,Asc("X"),"X")  ' Accel dazu,  STRG
form1.menu.AddItem(@mnExit,"Exit")      ' Zeiger auf das Item , Item Text

form1.menu.CreateSubMenu("Info")            ' Das zweite Popup
mnAbout.EventSub =@menu_About               ' Event-Sub
mnAbout.addAccel(NULL,112,"F1")         ' Accel dazu,  F1 ohne Control,Alt oder Shift
form1.menu.AddItem(@mnAbout,"About")    ' Zeiger auf das Item , Item Text

'-------------------------- Nur Bild----------------------------------
bmp1.Create(Form1.Handle,"bild1.bmp",20,40)

'-------------------------- Panel 1 ----------------------------------
panel1.Create(form1.Handle,100,40,860,550)
panel1.Color = RGBA(150,180,210,0)
panel1.Border = 1
Panel1.TextAlign = 4 ' mehrzeilig zentriert
Panel1.Caption = Chr(13,10)+"Panel kann als "+Chr(13,10)+" Container oder als Label "+Chr(13,10)+" einzeilig oder mehrzeilig verwendet werden"


Listbox1.Create(panel1.Handle,10,200,120,120)
Listbox1.TextColor = &HFF

Combo1.Create(panel1.Handle,150,200,120,120)

Edit2.Create(panel1.Handle,440,200,300,326)
Edit2.Border = 1
Edit2.Color = &HFFD0A0
Edit2.TextColor = &HFF0000
Edit2.Text = "Multiline Edit/Richedit-Control"
Edit2.ScrollBars = FALSE
Edit1.Create(panel1.Handle,320,250,100,26)


check1.Create(panel1.Handle, "Password",320,200,100,26)
check1.Color = RGBA(150,180,210,0)
Check1.onClick = @Check1_onClick
'-------------------------- Panel 2 ----------------------------------
panel2.Create(form1.Handle,100,40,860,550)
panel2.Color = RGBA(250,190,210,0)

panel2.Border = 1
Panel2.TextAlign = 4 ' mehrzeilig zentriert
Panel2.Caption = Chr(13,10)+"Panel kann Text "+Chr(13,10)+" einzeilig oder mehrzeilig darstellen"

HScroll.Create(panel2.Handle, 50,450,750 ,26 )
HScroll.Color = &HFF
HScroll.Range(0, 255)
HScroll.onChange = @HScroll_Change

HScroll1.Create(panel2.Handle, 50,420,750 ,26 )
HScroll1.Color = &HFF00
HScroll1.Range(0, 255)
HScroll1.onChange = @HScroll1_Change

HScroll2.Create(panel2.Handle, 50,390,750 ,26 )
HScroll2.Color = &HFF0000
HScroll2.Range(0, 255)
HScroll2.onChange = @HScroll2_Change

' Farbe entspr. Position wie panel2.Color = RGBA(250,190,210,0)

HScroll2.position = 250
HScroll1.position = 190
HScroll.position    = 210

'-------------------------- Button links ----------------------------------
btn1.Create(form1.Handle,"Panel1",5,160,90,36)
btn1.Color = RGBA(150,180,210,0)
btn1.Tip = "Schaltet auf Panel 1"
btn1.onClick = @btn1_onClick

btn2.Create(form1.Handle,"Panel2",5,196,90,36)
btn2.Color = RGBA(250,190,210,0)
btn2.Tip = "Schaltet auf Panel 2"
btn2.onClick = @btn2_onClick

'-------------------- Statusbar - Nachbildung ------------------------
panel3.Create(form1.Handle,0,690,866,22)
panel3.Color = RGBA(210,210,210,0)
panel3.Border = 1
panel3.Caption = "Das könnte eine einfache Statusbar sein"

'------------------------    Überschrift   ---------------------------
panel4.Create(form1.Handle,100,4,500,32)
panel4.Color = &Hefcb90
Panel4.TextColor = &HFF
Panel4.SetFont("Arial",14,1,0,0)
panel4.Caption = "Irgend eine Überschrift"

'---------------------------------------------------------------------
' Initialisierungen Var, array usw. hier
panel2.Visible = FALSE

Listbox1.AddString("Item 1")
Listbox1.AddString("Item 2")
Listbox1.AddString("Item 3")

Combo1.AddString("Item 1")
Combo1.AddString("Item 2")
Combo1.AddString("Item 3")

'--------------------Hintergrundfarbe der MenuBar ändern -------------
#DEFINE MIM_BACKGROUND &H00000002
#DEFINE MNS_AUTODISMISS &H10000000

Dim As MENUINFO mi

mi.cbSize = SizeOf(mi)
mi.hbrBack = CreateSolidBrush(&Hefcb90)
mi.fMask = MIM_BACKGROUND
mi.dwStyle = MNS_AUTODISMISS
If(IsMenu(form1.menu.Handle)) Then
    SetMenuInfo(form1.menu.Handle, @mi)
End If
'-----------------------------------------

'------ Show entält MessageLoop - muss immer am Ende sein ------------
form1.Show
End