Golang in Windows Walk window interface Design II

Source: Internet
Author: User
Tags deprecated qt designer
This is a creation in Article, where the information may have evolved or changed.

First look at the definition of window, this is clear, walk window is the structure of the definition of this

Type MainWindow struct {    assignto         **walk.  MainWindow//Association     name             string  //window name once Setup cannot be changed     enabled          property//disable     visible         &NB Sp  Property//Visualization     font             font//font     minsize          size//Minimize size     maxsize          size//maximize size  &NB Sp  contextmenuitems []menuitem//Window menu bar     onkeydown        walk. Keyeventhandler//Keyboard Press     onkeypress       walk. Keyeventhandler//Keyboard Press the previous event, do not return the result of the key to the computer.     onkeyup          walk. Keyeventhandler//keyboard lift     onmousedown      walk. mouseeventhandler//mouse click     onmousemove &nbsp    walk. MouseEventHandler//Mouse movement     onmouseup        walk. mouseeventhandler//Mouse lift     ondropfiles      walk. Dropfileseventhandler//Drag files to window     onsizechanged    walk. EventHandler//size change     title            string//window title      Size             size//window normalization size     databinder       DataBinder Data binding     layout           layout//window layout     children         []widget//child control Wiget, including containers, controls, etc.     menuitems        []menuitem//menu bar Settings    toolbaritems []menuitem// Deprecated, use ToolBar instead//toolbar is deprecated with toolbar    toolbar           ToolBar}

Look at the type and method a lot of, directly to get started, show a window first. Look at the code.

Import (   //"Github.com/lxn/walk")   . "Github.com/lxn/walk/declarative") func main () {mainwindow{Name: "Demo", Title: "I am Demo", Min SIZE:SIZE{300, 200},}. Run ()}

Operating effect:

Just a few lines of code generate a window,

Let's look at the definition of the Run method in walk first.

Func (MW MainWindow) Run () (int, error) {   var w *walk. MainWindow   if MW. Assignto = = Nil {      MW. Assignto = &w   }   If err: = MW. Create (); Err! = Nil {      return 0, Err   }   return (*MW. Assignto). Run (), nil}

You can see that this method has been called back to run (), which shows that the window is always drawn, if we call the MW inside. Create () method, the window is just a flash past.

Because window drawing involves complex things, including initialization, various window messages, subclasses, inheritance, and so on. Unable to finish, the study of the go language to draw the UI is our right path, otherwise a bit trifles, we are most seeking results, do not care about the underlying implementation, only the implementation is the correct choice.

A window does not work, you have to add a button, such as adding a button, we click the button, modify the button title.

Import (   "Syscall" "   unsafe" "     github.com/lxn/walk"   . "Github.com/lxn/walk/declarative") func main () {   var w *walk. MainWindow   var a *walk. Pushbutton   mainwindow{      assignto: &w,      Name:     "OK",      Title:    "I am Demo",      MinSize:  size{300,      Layout:   vbox{},//Layouts      children: []widget{//Do not add controls dynamically, the UI file is designed in this layout or QT designer and then loaded.         pushbutton{            Text:     "Click I Modify button title",            Assignto: &a,            Onclicked:func () {               //update (a) Method 1. Or a as a global variable, without passing a. or directly define a struct, add a method.          a.sendmessage (uintptr (0), uintptr (unsafe. Pointer (Syscall. Stringtoutf16ptr ("Hello"))))//Method 2           },},}         ,}   . Run ()}func update (a *walk. pushbutton) {   a.settext ("Hello")}

There are several methods that can be set up, and I'll show you a couple of ways to do it no more.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.