首次使用请先拉取GoVCL的代码。
go get -u github.com/ying32/govcl
此种方法是通过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!")
}
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) {
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")
f.Btn1.SetOnClick(f.OnButtonClick)
}
func (f *TAboutForm) OnBtn1Click(sender vcl.IObject) {
vcl.ShowMessage("Hello!")
}
GUI支持库可以通过三种方式下载:
Windows: 根据编译的二进制是32还是64位的,复制对应的“liblcl.dll”到当前exe目录或系统环境路径下。
GOARCH = amd64 386
GOOS = windows
CGO_ENABLED=0
Linux: 复制"liblcl.so"可执行文件目录下(也可复制liblcl.so到/usr/lib/
(32位liblcl)或者/usr/lib/x86_64-linux-gnu/
(64位liblcl)目录中,作为公共库使用)。
GOARCH = amd64
GOOS = linux
CGO_ENABLED=1
MacOS: 复制"liblcl.dylib"可执行文件目录下(MacOS下注意:需要自行创建info.plist文件),或者参考:MacOS上应用打包
GOARCH = amd64
GOOS = darwin
CGO_ENABLED=1