zoukankan      html  css  js  c++  java
  • Go入门笔记46 Go Walk ListBox使用

    Walk是Go的一个开发窗口程序的库,下面以ListBox使用方法做说明
    原始代码太长,不利于理解,精简一下

    // Copyright 2012 The Walk Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style
    // license that can be found in the LICENSE file.
    
    package main
    
    import (
    	"log"
    
    	"github.com/lxn/walk"
    
    	. "github.com/lxn/walk/declarative"
    )
    
    func main() {
    	mw := &MyMainWindow{model: NewEnvModel()}
    
    	if _, err := (MainWindow{
    		AssignTo: &mw.MainWindow,
    		Title:    "Walk ListBox Example",
    		MinSize:  Size{240, 320},
    		Size:     Size{300, 400},
    		Layout:   VBox{MarginsZero: true},
    		Children: []Widget{
    			ListBox{
    				AssignTo: &mw.lb,
    				Model:    mw.model,
    			},
    		},
    	}.Run()); err != nil {
    		log.Fatal(err)
    	}
    }
    
    type MyMainWindow struct {
    	*walk.MainWindow
    	model *EnvModel
    	lb    *walk.ListBox
    }
    
    type EnvItem struct {
    	name  string
    	value string
    }
    
    type EnvModel struct {
    	walk.ListModelBase
    	items []EnvItem
    }
    
    func NewEnvModel() *EnvModel {
    	m := &EnvModel{items: make([]EnvItem, 3)}
    
    	m.items[0] = EnvItem{"name", "value"}
    	m.items[1] = EnvItem{"name", "value"}
    	m.items[2] = EnvItem{"name", "value"}
    	return m
    }
    
    func (m *EnvModel) ItemCount() int {
    	return len(m.items)
    }
    
    func (m *EnvModel) Value(index int) interface{} {
    	return m.items[index].name
    }
    
    

    EnvMode定义
    image

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
        <assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="SomeFunkyNameHere" type="win32"/>
        <dependency>
            <dependentAssembly>
                <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
            </dependentAssembly>
        </dependency>
        <asmv3:application>
            <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
                <dpiAware>true</dpiAware>
            </asmv3:windowsSettings>
        </asmv3:application>
    </assembly>
    
    

    rsrc -manifest test.manifest -o rsrc.syso
    go mod init test
    go mod tidy
    go build
    运行

    image

    本博客是个人工作中记录,遇到问题可以互相探讨,没有遇到的问题可能没有时间去特意研究,勿扰。
    另外建了几个QQ技术群:
    2、全栈技术群:616945527,加群口令abc123
    2、硬件嵌入式开发: 75764412
    3、Go语言交流群:9924600

    闲置域名www.nsxz.com出售(等宽等高字符四字域名)。
  • 相关阅读:
    NYOJ 625 笨蛋的难题(二)
    NYOJ 102 次方求模
    ZJU Least Common Multiple
    ZJUOJ 1073 Round and Round We Go
    NYOJ 709 异形卵
    HDU 1279 验证角谷猜想
    BNUOJ 1015 信息战(一)——加密程序
    HDU 1202 The calculation of GPA
    "蓝桥杯“基础练习:字母图形
    "蓝桥杯“基础练习:数列特征
  • 原文地址:https://www.cnblogs.com/zhaogaojian/p/15631491.html
Copyright © 2011-2022 走看看