首次使用請先拉取GoVCL的代碼。
獲取GoVCL代碼
go get -u github.com/ying32/govcl
編寫代碼
- 1、通過UI設計器或者res2go工具生成GUI
此種方法是通過UI設計器或者res2go工具生成GUI。
UI設計的獲取請加入QQ羣中獲取。
package main
import (
"github.com/ying32/govcl/vcl"
// 如果你使用自定義的syso文件則不要引用此包
_ "github.com/ying32/govcl/pkgs/winappres"
)
type TMainForm struct {
*vcl.TForm
Btn1 *vcl.TButton
}
type TAboutForm struct {
*vcl.TForm
Btn1 *vcl.TButton
}
var (
mainForm *TMainForm
aboutForm *TAboutForm
)
func main() {
vcl.Application.Initialize()
vcl.Application.SetMainFormOnTaskBar(true)
vcl.Application.CreateForm(&mainForm)
vcl.Application.CreateForm(&aboutForm)
vcl.Application.Run()
}
// -- TMainForm
func (f *TMainForm) OnFormCreate(sender vcl.IObject) {
}
func (f *TMainForm) OnBtn1Click(sender vcl.IObject) {
vcl.ShowMessage("Hello!")
}
// -- TAboutForm
func (f *TAboutForm) OnFormCreate(sender vcl.IObject) {
}
func (f *TAboutForm) OnBtn1Click(sender vcl.IObject) {
vcl.ShowMessage("Hello!")
}
- 2、通過純代碼編寫
package main
import (
"github.com/ying32/govcl/vcl"
// 如果你使用自定義的syso文件則不要引用此包
_ "github.com/ying32/govcl/pkgs/winappres"
)
type TMainForm struct {
*vcl.TForm
Btn1 *vcl.TButton
}
type TAboutForm struct {
*vcl.TForm
Btn1 *vcl.TButton
}
var (
mainForm *TMainForm
aboutForm *TAboutForm
)
func main() {
vcl.Application.Initialize()
vcl.Application.SetMainFormOnTaskBar(true)
vcl.Application.CreateForm(&mainForm)
// 創建完後關聯子組件事件
vcl.Application.CreateForm(&aboutForm, true)
vcl.Application.Run()
}
// -- TMainForm
func (f *TMainForm) OnFormCreate(sender vcl.IObject) {
f.SetCaption("Hello")
f.Btn1 = vcl.NewButton(f)
f.Btn1.SetParent(f)
f.Btn1.SetBounds(10, 10, 88, 28)
f.Btn1.SetCaption("Button1")
f.Btn1.SetOnClick(f.OnButtonClick)
}
func (f *TMainForm) OnButtonClick(sender vcl.IObject) {
vcl.ShowMessage("Hello!")
}
// -- TAboutForm
func (f *TAboutForm) OnFormCreate(sender vcl.IObject) {
f.SetCaption("Hello")
f.Btn1 = vcl.NewButton(f)
//f.Btn1.SetName("Btn1")
f.Btn1.SetParent(f)
f.Btn1.SetBounds(10, 10, 88, 28)
f.Btn1.SetCaption("Button1")
}
func (f *TAboutForm) OnBtn1Click(sender vcl.IObject) {
vcl.ShowMessage("Hello!")
}
下載預編譯GUI支持庫。
GUI支持庫可以通過三種方式下載:
- 1、項目主頁和官網。
- 2、加入QQ羣內,在羣文件中獲取。
- 3、自行根據GUI源碼目錄UILibSources中的說明自行編譯。
複製GUI庫到
-
Windows: 根據編譯的二進制是32還是64位的,複製對應的"libvcl.dll"或者"libvclx64.dll"或者“liblcl.dll”到當前exe目錄或系統環境路徑下。
- Go環境變量:
GOARCH = amd64 386
GOOS = windows
CGO_ENABLED=0
- Go環境變量:
-
Linux: 複製"liblcl.so"可執行文件目錄下(也可複製liblcl.so到
/usr/lib/
(32位liblcl)或者/usr/lib/x86_64-linux-gnu/
(64位liblcl)目錄中,作爲公共庫使用)。- Go環境變量:
GOARCH = amd64
GOOS = linux
CGO_ENABLED=1
- Go環境變量:
-
MacOS: 複製"liblcl.dylib"可執行文件目錄下(MacOS下注意:需要自行創建info.plist文件),或者參考:MacOS上應用打包
- Go環境變量:
GOARCH = amd64
GOOS = darwin
CGO_ENABLED=1
- Go環境變量: