GUI Control Learning 1 (C #),

Source: Internet
Author: User

GUI Control Learning 1 (C #),

Code snippet:

Using UnityEngine; using System. collections; public class SkinTest: MonoBehaviour {public Texture imgbtn; private string textContent = "Textfield"; private string passwordToEdit = "PasswordField "; private string textAreaToEdit = "Hello world \ n I'm textArea"; public Texture toggleImgTexture; private bool toggleTxt; private bool toggleImg; private int toolInt = 0; private string [] toolNameArr = {"Toolbar1", "Toolbar2", "Toolbar3"}; private float hSlideValue = 0; private float vSlideValue = 0; private float hSbarValue; private float vSbarValue; private Vector2 scrollPosition = Vector2.zero; private Rect windowbox = new Rect (400,250,220,100); // Use this for initialization void Start () {}// Update is called once per frame void Update () {} void OnGUI () {// Label control GUI. label (new Rect (10, 10,), "Label"); // Button control if (GUI. button (new Rect (,), "Button") {print ("press the Button. ");} if (imgbtn) {if (GUI. button (new Rect (10, 60, imgbtn. width, imgbtn. height), imgbtn) {print ("push button. ") ;}} // RepeatButton control if (GUI. repeatButton (new Rect (10,130,100, 20), "RepeatButton") {print ("Press RepeatButton. ");} // TextField control textContent = GUI. textField (new Rect (10,160,120, 20), textContent); // PasswordField control passwordToEdit = GUI. passwordField (new Rect (10,190,120, 20), passwordToEdit, "*" [0], 25); // textArea control textAreaToEdit = GUI. textArea (new Rect (10,220,120,100), textAreaToEdit); // Toggle control toggleTxt = GUI. toggle (new Rect (10,350,100, 20), toggleTxt, "toggle text"); if (toggleImgTexture) {toggleImg = GUI. toggle (new Rect (10,380, 50, 50), toggleImg, toggleImgTexture);} // ToolBar Control toolInt = GUI. toolbar (new Rect (10,430,200, 30), toolInt, toolNameArr); // Slide control hSlideValue = GUI. horizontalSlider (new Rect (,), hSlideValue,); vSlideValue = GUI. verticalSlider (new Rect (30,100,), vSlideValue,); // Scrollbar control hSbarValue = GUI. horizontalScrollbar (new Rect (220,160,100, 30), hSbarValue, 10); vSbarValue = GUI. verticalScrollbar (new Rect (220,200, 30,100), vSbarValue, 10); // scrollView control scrollPosition = GUI. beginScrollView (new Rect (records, 40, 200,200), scrollPosition, new Rect (550,650,); GUI. button (new Rect (,), "top-left"); GUI. button (new Rect (,), "top-right"); GUI. button (new Rect (420,630,100, 20), "bottom-left"); GUI. button (new Rect (680,630,100, 20), "bottom-right"); GUI. endScrollView (); // end the rolling view // window windowbox = GUI. window (0, windowbox, windowFun, "my window");} void windowFun (int windowID) {GUI. button (new Rect (60,50, 100,20), "window Button"); GUI. dragWindow (new Rect ));}}

Effect

 


How to Write GUI software in C Language

C language is an intermediate language. It inherits the feature that the assembly language can directly operate on the address, which is not available in other advanced languages such as java, so it reflects the powerful C language operation function.

VC6.0 is a very powerful tool. What you mentioned and used may be only 1% of the software. VC supports graphical programming, but it is generally not used in universities, converting DOS to a WINDOWS interface can be implemented using WIN32 projects, but it is unnecessary if it is only a course design, because it takes a long time to learn WIN32, it can be said that it is also a C language code, and you will find that you do not understand it, even if it is a simple program that outputs Hello, this is the effect of encapsulation. For example, the main function is main in the C Project, but you cannot see main in the WIN32 project, and the logic used is completely different. You can create a WIN32 project and check it with VC.

If you are interested in graphical programming, you will be able to lay the foundation of WIN32 and learn to use MFC. These tools can all be used as VC tools.

C language learning problems

Haha .... after several years, will some diligent and curious children in the programming area ask this question: "How to Use C/C ++ to write programs with buttons and interfaces?"

The following is my personal experience, and I hope it will be useful to the landlord.

I did not mention the number of people upstairs. It is easy for beginners to be misled when they come into contact with this problem, I hope that the landlord can learn from the basic principles and then access AFrm such as MFC.

I was also troubled by this problem for a long time when I was in my sophomore year. I was looking forward to learning programming from the computer system, but I found out that the library of the language that the teacher talked about was just started, the compiled program is basically different from the program that uses buttons, text boxes, and images on the computer at ordinary times. The compiled program is a Black Box program like DOS, and it feels cheated.

So I started to explore just like you now. Unfortunately, Baidu didn't know anything at that time, and I couldn't start searching. Then I finally pieced together some knowledge from various materials, originally, the program with buttons and dialog boxes that I want to write is a GUI-based program.

GUI-Graphic User Interface-graphical User Interface, which is completely different from the interactive mode of console programs with only the main function. Console Program-that is, the black window you mentioned, interacts with the user completely through the output character and input character, while GUI, various graphical controls are used to accept input and output, including buttons, text boxes, input boxes, and even images, videos, and sounds.

So how can we use the familiar C language to really write such a GUI-based program? Sorry, the C language itself, that is, the syntax elements and standard library of the C language, does not provide GUI support, that is to say, you cannot use the C language and stdio or stdlib to write a program with a "dialog box... as for why C does not provide GUI, many reasons also make sense. I will not elaborate on it here. To write a GUI program, you must have a library provided by a third party.

Fortunately, the common Windows operating system provides us with a GUI library, which can simply include <windows. h>. The code of this library is stored in the most important file of Windows: user32.dll (so this is a dynamic link library ), not only can we use this ready-made GUI library, but in fact, the vast majority of programs running in Windows use user32.dll, including Microsoft's own visual stdio.

When talking about User32.dll, you have to mention another important concept: API, Application Programming Interface, which is an Interface provided to programmers by the operating system or other programs, you can use this interface to "command" the operating system to do something. For example, in Windows, if you want to view a file through the resource manager, you can use the File API provided by Windows. If you want to draw a graph on the screen, in Windows, I use the graphical API (that is, Microsoft's GDI). Now I want to write a program with "window, dialog box, And button? Of course there are APIs for generating controls such as window and dialog box ready for use.

The specific WindowsAPI can be easily found, but the total number is very large (you can think about how many functions need to be provided to describe the functions of a large operating system such as Windows) here is the W32API Manual: www.eshuba.com/soft/795.htm

If you want to start the window program written in your first WindowsAPI, here is an example suitable for beginners: ...... The Rest Of The full text>

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.