Controls









How do I use Controls
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: PhotonViewInspector.cs Copy
21     public override void OnInspectorGUI()
22     {
23         #if UNITY_3_5
24         EditorGUIUtility.LookLikeInspector();
25         #endif
26         //EditorGUI.indentLevel = 1;
27
28         m_Target = (PhotonView)this.target;
29         bool isProjectPrefab = EditorUtility.IsPersistent(m_Target.gameObject);
30
31         if( m_Target.ObservedComponents == null )
32         {
33             m_Target.ObservedComponents = new System.Collections.Generic.List();
34         }
35
36         if( m_Target.ObservedComponents.Count == 0 )
37         {
38             m_Target.ObservedComponents.Add( null );
39         }
40
41         EditorGUILayout.BeginHorizontal();
42         // Owner
43         if (isProjectPrefab)
44         {
45             EditorGUILayout.LabelField("Owner:", "Set at runtime");
46         }
47         else if (m_Target.isSceneView)
48         {
49             EditorGUILayout.LabelField("Owner", "Scene");
50         }
51         else
52         {
53             PhotonPlayer owner = m_Target.owner;
54             string ownerInfo = (owner != null) ? owner.name : "";
55
56             if (string.IsNullOrEmpty(ownerInfo))
57             {
58                 ownerInfo = "";
59             }
60
61             EditorGUILayout.LabelField("Owner", "[" + m_Target.ownerId + "] " + ownerInfo);
62         }
63
64         // ownership requests
65         EditorGUI.BeginDisabledGroup(Application.isPlaying);
66         m_Target.ownershipTransfer = (OwnershipOption)EditorGUILayout.EnumPopup(m_Target.ownershipTransfer, GUILayout.Width(100));
67         EditorGUI.EndDisabledGroup();
68
69         EditorGUILayout.EndHorizontal();
70
71
72         // View ID
73         if (isProjectPrefab)
74         {
75             EditorGUILayout.LabelField("View ID", "Set at runtime");
76         }
77         else if (EditorApplication.isPlaying)
78         {
79             EditorGUILayout.LabelField("View ID", m_Target.viewID.ToString());
80         }
81         else
82         {
83             int idValue = EditorGUILayout.IntField("View ID [1.."+(PhotonNetwork.MAX_VIEW_IDS-1)+"]", m_Target.viewID);
84             m_Target.viewID = idValue;
85         }
86
87
88
89         // Locally Controlled
90         if (EditorApplication.isPlaying)
91         {
92             string masterClientHint = PhotonNetwork.isMasterClient ? "(master)" : "";
93             EditorGUILayout.Toggle("Controlled locally: " + masterClientHint, m_Target.isMine);
94         }
95
96
97
98         //DrawOldObservedItem();
99         ConvertOldObservedItemToObservedList();
100
101
102         // ViewSynchronization (reliability)
103         if (m_Target.synchronization == ViewSynchronization.Off)
104         {
105             GUI.color = Color.grey;
106         }
107
108         EditorGUILayout.PropertyField( serializedObject.FindProperty( "synchronization" ), new GUIContent( "Observe option:" ) );
109
110         if( m_Target.synchronization != ViewSynchronization.Off &&
111             m_Target.ObservedComponents.FindAll( item => item != null ).Count == 0 )
112         {
113             GUILayout.BeginVertical( GUI.skin.box );
114             GUILayout.Label( "Warning", EditorStyles.boldLabel );
115             GUILayout.Label( "Setting the synchronization option only makes sense if you observe something." );
116             GUILayout.EndVertical();
117         }
118
119         /*ViewSynchronization vsValue = (ViewSynchronization)EditorGUILayout.EnumPopup("Observe option:", m_Target.synchronization);
120         if (vsValue != m_Target.synchronization)
121         {
122             m_Target.synchronization = vsValue;
123             if (m_Target.synchronization != ViewSynchronization.Off && m_Target.observed == null)
124             {
125                 EditorUtility.DisplayDialog("Warning", "Setting the synchronization option only makes sense if you observe something.", "OK, I will fix it.");
126             }
127         }*/
128
129         DrawSpecificTypeSerializationOptions();
130
131         GUI.color = Color.white;
132         DrawObservedComponentsList();
133
134         // Cleanup: save and fix look
135         if (GUI.changed)
136         {
137             EditorUtility.SetDirty(m_Target);
138             PhotonViewHandler.HierarchyChange(); // TODO: check if needed
139         }
140
141         GUI.color = Color.white;
142         EditorGUIUtility.LookLikeControls();
143     }
File name: PlayerControl.cs Copy
39     void Update()
40     {
41         ShootOrPauseControls();
42     }
File name: PlayerControl.cs Copy
44     void FixedUpdate()
45     {
46         MovementControls();
47     }
File name: PlayerControl.cs Copy
49     void ShootOrPauseControls()
50     {
51         if (!SystemScr.paused)
52         {
53             if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space))
54             {
55                 GameObject p_bullet = pools.GetPoolableObject("p_bullet");
56
57                 if (p_bullet != null && maxBulletsOnScreen > 0)
58                 {
59                     sounds.PlaySoundsPlayer(0);
60                     p_bullet.SetActive(true);
61                     p_bullet.GetComponent().ShootMe(transform.position);
62                 }
63             }
64         }
65         if (Input.GetKeyDown(KeyCode.Escape))
66         {
67             ui.Pause_btn();
68         }
69     }
File name: PlayerControl.cs Copy
71     void MovementControls()
72     {
73         float screenSpeed = 0;
74         float horizontalInput = 0;
75         float verticalInput = 0;
76
77         screenSpeed = CameraMotor.speedScreen;
78
79         //moving right
80         if (Input.GetKey(KeyCode.D))
81             horizontalInput = speedCurrent;
82
83         //moving left
84         if (Input.GetKey(KeyCode.A))
85             horizontalInput = -speedCurrent;
86
87         //moving up
88         if (Input.GetKey(KeyCode.W))
89             verticalInput = speedCurrent;
90
91         //moving down
92         if (Input.GetKey(KeyCode.S))
93             verticalInput = -speedCurrent;
94
95
96         //result velocity
97         rb.velocity = new Vector3(horizontalInput, 0, screenSpeed + verticalInput);
98     }
File name: ScrollSnapBase.cs Copy
115         void Awake()
116   {
117    _scroll_rect = gameObject.GetComponent();
118
119    if (_scroll_rect.horizontalScrollbar || _scroll_rect.verticalScrollbar)
120    {
121     Debug.LogWarning("Warning, using scrollbars with the Scroll Snap controls is not advised as it causes unpredictable results");
122    }
123
124    if (StartingScreen < 0)
125    {
126     StartingScreen = 0;
127    }
128
129    _screensContainer = _scroll_rect.content;
130    if (ChildObjects != null && ChildObjects.Length > 0)
131    {
132     if (_screensContainer.transform.childCount > 0)
133     {
134      Debug.LogError("ScrollRect Content has children, this is not supported when using managed Child Objects\n Either remove the ScrollRect Content children or clear the ChildObjects array");
135      return;
136     }
137
138     InitialiseChildObjectsFromArray();
139    }
140    else
141    {
142     InitialiseChildObjectsFromScene();
143    }
144
145    if (NextButton)
146     NextButton.GetComponent
File name: usableFunction.cs Copy
13         public void clearTxt(Control container)
14         {
15             try
16             {
17                 //'for each txt as control in this(object).control
18                 foreach (Control txt in container.Controls)
19                 {
20                     //conditioning the txt as control by getting it's type.
21                     //the type of txt as control must be textbox.
22                     if (txt is TextBox)
23                     {
24                         //if the object(textbox) is present. The result is, the textbox will be cleared.
25                         txt.Text = "";
26                     }
27                     if (txt is RichTextBox)
28                     {
29                         txt.Text = "";
30                     }
31                 }
32
33
34             }
35             catch (Exception ex)
36             {
37                 MessageBox.Show(ex.Message);
38             }
39         }
File name: frmItems.cs Copy
86         private void btnsave_Click(object sender, EventArgs e)
87         {
88
89             foreach(Control obj in pnl_stockmaster.Controls)
90             {
91                 if(obj is TextBox)
92                 {
93                     if(obj.Text == "")
94                     {
95                         MessageBox.Show("Action connot be perform. All fields are required to be fill up.", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
96                         return;
97                     }
98                 }
99             }
100
101
102
103             sql = "INSERT INTO `tblstock_in_out` (`ITEMID`, `QTY`,`TRANSACTIONDATE`, `TOTALPRICE`, `REMARKS`)" +
104               " VALUES ('" + txtitemid.Text + "','" + txtqty.Text + "','" + DateTime.Now.ToString("yyyy-MM-dd") + "','" + txtprice.Text +
105               "','StockIn')";
106            config.Execute_Query(sql);
107
108
109             sql = "SELECT ITEMID FROM tblitems WHERE ITEMID='" + txtitemid.Text + "'";
110             config.singleResult(sql);
111             if(config.dt.Rows.Count > 0)
112             {
113                 sql = "UPDATE tblitems SET qty =qty + '" + txtqty.Text + "' WHERE ITEMID ='" + txtitemid.Text + "'";
114                 config.Execute_Query(sql);
115             }
116             else
117             {
118                 sql = "insert into tblitems (ITEMID,`NAME`, `DESCRIPTION`, `TYPE`, `PRICE`, `QTY`,UNIT)" +
119                    "VALUES ('" + txtitemid.Text + "','" + txtname.Text + "','" + txtdescription.Text + "','" + cbotype.Text
120                    + "','" + txtprice.Text + "','" + txtqty.Text + "','" + cbounit.Text + "' )";
121                 config.Execute_CUD(sql, "No data saved.", "Data has been saved in the database.");
122
123                 config.update_Autonumber(cbotype.Text);
124             }
125
126             btnnew_Click(sender, e);
127
128         }
File name: frmColor.cs Copy
86   private void InitializeComponent()
87   {
88             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ColorInput));
89             this.Blue = new System.Windows.Forms.TextBox();
90             this.label4 = new System.Windows.Forms.Label();
91             this.Green = new System.Windows.Forms.TextBox();
92             this.label3 = new System.Windows.Forms.Label();
93             this.Red = new System.Windows.Forms.TextBox();
94            this.label2 = new System.Windows.Forms.Label();
95             this.label1 = new System.Windows.Forms.Label();
96             this.Cancel = new System.Windows.Forms.Button();
97             this.OK = new System.Windows.Forms.Button();
98             this.SuspendLayout();
99             //
100             // Blue
101             //
102             this.Blue.Location = new System.Drawing.Point(103, 112);
103             this.Blue.Name = "Blue";
104             this.Blue.Size = new System.Drawing.Size(100, 20);
105             this.Blue.TabIndex = 17;
106             ////
107             // label4
108             //
109             this.label4.ForeColor = System.Drawing.Color.Blue;
110             this.label4.Location = new System.Drawing.Point(32, 112);
111             this.label4.Name = "label4";
112             this.label4.Size = new System.Drawing.Size(32, 16);
113             this.label4.TabIndex = 16;
114             this.label4.Text = "Blue";
115            // //
116            // // Green
117            // //
118             this.Green.Location = new System.Drawing.Point(103, 80);
119             this.Green.Name = "Green";
120             this.Green.Size = new System.Drawing.Size(100, 20);
121             this.Green.TabIndex = 15;
122             //
123            // // label3
124            // //
125             this.label3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
126             this.label3.Location = new System.Drawing.Point(32, 80);
127             this.label3.Name = "label3";
128             this.label3.Size = new System.Drawing.Size(32, 16);
129             this.label3.TabIndex = 14;
130             this.label3.Text = "Green";
131             //
132            // // Red
133            // //
134             this.Red.Location = new System.Drawing.Point(103, 48);
135             this.Red.Name = "Red";
136             this.Red.Size = new System.Drawing.Size(100, 20);
137             this.Red.TabIndex = 13;
138            // //
139            // // label2
140            // //
141             this.label2.ForeColor = System.Drawing.Color.Red;
142             this.label2.Location = new System.Drawing.Point(32, 48);
143             this.label2.Name = "label2";
144             this.label2.Size = new System.Drawing.Size(32, 16);
145             this.label2.TabIndex = 12;
146             this.label2.Text = "Red";
147             //
148            // // label1
149            // //
150             this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
151             this.label1.ForeColor = System.Drawing.Color.Blue;
152             this.label1.Location = new System.Drawing.Point(16, 16);
153             this.label1.Name = "label1";
154             this.label1.Size = new System.Drawing.Size(281, 24);
155             this.label1.TabIndex = 11;
156             this.label1.Text = "Nhập các giá trị màu từ -255 đến 255";
157             // this.label1.Click += new System.EventHandler(this.label1_Click);
158            // //
159            // // Cancel
160            // //
161             this.Cancel.Location = new System.Drawing.Point(176, 178);
162             this.Cancel.Name = "Cancel";
163             this.Cancel.Size = new System.Drawing.Size(75, 23);
164             this.Cancel.TabIndex = 9;
165             this.Cancel.Text = "Bỏ qua";
166             //
167            // // OK
168            // //
169             this.OK.Location = new System.Drawing.Point(19, 178);
170             this.OK.Name = "OK";
171             this.OK.Size = new System.Drawing.Size(75, 23);
172             this.OK.TabIndex = 10;
173             this.OK.Text = "Đồng ý";
174            // this.OK.Click += new System.EventHandler(this.OK_Click);
175             //
176             // ColorInput
177             //
178             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
179             this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
180             this.ClientSize = new System.Drawing.Size(309, 226);
181             this.Controls.Add(this.Blue);
182             this.Controls.Add(this.label4);
183             this.Controls.Add(this.Green);
184             this.Controls.Add(this.label3);
185             this.Controls.Add(this.Red);
186             this.Controls.Add(this.label2);
187             this.Controls.Add(this.label1);
188             this.Controls.Add(this.OK);
189             this.Controls.Add(this.Cancel);
190             this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
191             this.Name = "ColorInput";
192             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
193             this.Text = "CHON MAU";
194             //this.Load += new System.EventHandler(this.ColorInput_Load);
195             this.ResumeLayout(false);
196             this.PerformLayout();
197
198   }
File name: frmQlMuonSach.cs Copy
128         private void btnclear_Click(object sender, EventArgs e)
129         {
130             foreach (Control ctr in groupBox1.Controls)
131             {
132                 if (ctr is TextBox || ctr is ComboBox)
133                 {
134                     ctr.Text = "";
135                     cbxTenSach.Focus();
136                     txtMuon.Text = date.ToString("dd/MM/yyyy");
137                     txtTra.Text = date.AddDays(7).ToString("dd/MM/yyyy");
138                 }
139             }
140         }

Download file with original file name:Controls

Controls 137 lượt xem

Gõ tìm kiếm nhanh...