Alignment
How do I use Alignment
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: FormXemDiem.cs
Copy
85 private void btnXuatRaExcel_Click(object sender, EventArgs e)
86 {
87 try
88 {
89
90 Excel.Application objExcelApp = new Excel.Application();
91 Excel.Workbook objExcelWorkbook = objExcelApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
92 Excel.Worksheet objSheet = (Excel.Worksheet)objExcelWorkbook.Worksheets[1];
93 //objSheet.Cells.Interior.Color.ToString() = 'blue';
94 objSheet = (Excel.Worksheet)objExcelWorkbook.Sheets[1];
95 objSheet.Cells.HorizontalAlignment = Excel.Constants.xlCenter;
96 objSheet.Cells[2, 5] = "BẢNG ĐIỂM CỦA SINH VIÊN";
97 objSheet.Cells[5, 3] = "Mã Học Phần";
98 objSheet.Cells[5, 4] = "Mã Nhóm Học Phần";
99 objSheet.Cells[5, 5] = "Tên Học Phần";
100 objSheet.Cells[5, 6] = "Điểm Thi";
101 objSheet.Cells[5, 7] = "Điểm Quá Trình";
102 objSheet.Cells[5, 8] = "Điểm Xếp Loại";
103 objSheet.Cells[3, 3] = "Mã Học Kỳ : "+cmbMaHK.SelectedValue.ToString()+"";
104 objSheet.Cells[4, 3] = "Mã SV : " + txtMaSV.Text + "";
105 objSheet.Cells[9,10] = "ĐIỂM TỔNG KẾT";
106 objSheet.Cells[10,10] = "Hệ 10 : "+txtHe10.Text+"";
107 objSheet.Cells[11,10] = "Hệ 4 : "+txtHe4.Text+"";
108 for (int i = 0; i < dgvKetQua.Rows.Count ; i++)
109 {
110 for (int j = 0; j < dgvKetQua.Columns.GetColumnCount(DataGridViewElementStates.Displayed); j++)
111 {
112 objSheet.Cells[i + 6, j + 3] = dgvKetQua.Rows[i].Cells[j].Value.ToString();
113 objSheet.Columns.AutoFit();
114 }
115 }
116 objExcelApp.Visible = true;
117 }
118 catch (Exception ex)
119 {
120 MessageBox.Show(ex.Message);
121 }
122 }
File name: FormXemDiemLop.cs
Copy
77 private void btnXuatRaExcel_Click(object sender, EventArgs e)
78 {
79 try
80 {
81
82 Excel.Application objExcelApp = new Excel.Application();
83 Excel.Workbook objExcelWorkbook = objExcelApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
84 Excel.Worksheet objSheet = (Excel.Worksheet)objExcelWorkbook.Worksheets[1];
85 //objSheet.Cells.Interior.Color.ToString() = 'blue';
86 objSheet = (Excel.Worksheet)objExcelWorkbook.Sheets[1];
87 objSheet.Cells.HorizontalAlignment = Excel.Constants.xlCenter;
88 objSheet.Cells[2, 5] = "BẢNG ĐIỂM CỦA LỚP";
89 objSheet.Cells[3, 3] = "Mã Học Kỳ : "+cmbMaHK.SelectedValue.ToString()+"";
90 objSheet.Cells[4, 3] = "Mã Lớp : " + cmbMaLop.SelectedValue.ToString() + "";
91 objSheet.Cells[5, 4] = "Mã Sinh Viên";
92 objSheet.Cells[5, 5] = "Tên Sinh Viên";
93 objSheet.Cells[5, 6] = "Điểm Trung Bình";
94 //select sv.MaSV,TenSV,TrungBinhCuoiKyHe10
95
96 for (int i = 0; i < dgvKetQua.Rows.Count ; i++)
97 {
98 for (int j = 0; j < dgvKetQua.Columns.GetColumnCount(DataGridViewElementStates.Displayed); j++)
99 {
100 objSheet.Cells[i + 6, j + 4] = dgvKetQua.Rows[i].Cells[j].Value.ToString();
101 objSheet.Columns.AutoFit();
102 }
103 }
104 objExcelApp.Visible = true;
105 }
106 catch (Exception ex)
107 {
108 MessageBox.Show(ex.Message);
109 }
110 }
File name: DemoMecanimGUI.cs
Copy
61 public void OnGUI()
62 {
63 GUI.skin = Skin;
64
65 string[] synchronizeTypeContent = new string[] { "Disabled", "Discrete", "Continuous" };
66
67 GUILayout.BeginArea( new Rect( Screen.width - 200 * m_FoundPlayerSlideIn - 400 * m_SlideIn, 0, 600, Screen.height ), GUI.skin.box );
68 {
69 GUILayout.Label( "Mecanim Demo", GUI.skin.customStyles[ 0 ] );
70
71 GUI.color = Color.white;
72 string label = "Settings";
73
74 if( m_IsOpen == true )
75 {
76 label = "Close";
77 }
78
79 if( GUILayout.Button( label, GUILayout.Width( 110 ) ) )
80 {
81 m_IsOpen = !m_IsOpen;
82 }
83
84 string parameters = "";
85
86 if( m_AnimatorView != null )
87 {
88 parameters += "Send Values:\n";
89
90 for( int i = 0; i < m_AnimatorView.GetSynchronizedParameters().Count; ++i )
91 {
92 PhotonAnimatorView.SynchronizedParameter parameter = m_AnimatorView.GetSynchronizedParameters()[ i ];
93
94 try
95 {
96 switch( parameter.Type )
97 {
98 case PhotonAnimatorView.ParameterType.Bool:
99 parameters += parameter.Name + " (" + ( m_AnimatorView.GetComponent
100 break;
101 case PhotonAnimatorView.ParameterType.Int:
102 parameters += parameter.Name + " (" + m_AnimatorView.GetComponent
103 break;
104 case PhotonAnimatorView.ParameterType.Float:
105 parameters += parameter.Name + " (" + m_AnimatorView.GetComponent
106 break;
107 }
108 }
109 catch
110 {
111 Debug.Log( "derrrr for " + parameter.Name );
112 }
113 }
114 }
115
116 if( m_RemoteAnimator != null )
117 {
118 parameters += "\nReceived Values:\n";
119
120 for( int i = 0; i < m_AnimatorView.GetSynchronizedParameters().Count; ++i )
121 {
122 PhotonAnimatorView.SynchronizedParameter parameter = m_AnimatorView.GetSynchronizedParameters()[ i ];
123
124 try
125 {
126 switch( parameter.Type )
127 {
128 case PhotonAnimatorView.ParameterType.Bool:
129 parameters += parameter.Name + " (" + ( m_RemoteAnimator.GetBool( parameter.Name ) ? "True" : "False" ) + ")\n";
130 break;
131 case PhotonAnimatorView.ParameterType.Int:
132 parameters += parameter.Name + " (" + m_RemoteAnimator.GetInteger( parameter.Name ) + ")\n";
133 break;
134 case PhotonAnimatorView.ParameterType.Float:
135 parameters += parameter.Name + " (" + m_RemoteAnimator.GetFloat( parameter.Name ).ToString( "0.00" ) + ")\n";
136 break;
137 }
138 }
139 catch
140 {
141 Debug.Log( "derrrr for " + parameter.Name );
142 }
143 }
144 }
145
146 GUIStyle style = new GUIStyle( GUI.skin.label );
147 style.alignment = TextAnchor.UpperLeft;
148
149 GUI.color = new Color( 1f, 1f, 1f, 1 - m_SlideIn );
150 GUI.Label( new Rect( 10, 100, 600, Screen.height ), parameters, style );
151
152 if( m_AnimatorView != null )
153 {
154 GUI.color = new Color( 1f, 1f, 1f, m_SlideIn );
155
156 GUILayout.Space( 20 );
157 GUILayout.Label( "Synchronize Parameters" );
158
159 for( int i = 0; i < m_AnimatorView.GetSynchronizedParameters().Count; ++i )
160 {
161 GUILayout.BeginHorizontal();
162 {
163 PhotonAnimatorView.SynchronizedParameter parameter = m_AnimatorView.GetSynchronizedParameters()[ i ];
164
165 GUILayout.Label( parameter.Name, GUILayout.Width( 100 ), GUILayout.Height( 36 ) );
166
167 int selectedValue = (int)parameter.SynchronizeType;
168 int newValue = GUILayout.Toolbar( selectedValue, synchronizeTypeContent );
169
170 if( newValue != selectedValue )
171 {
172 m_AnimatorView.SetParameterSynchronized( parameter.Name, parameter.Type, (PhotonAnimatorView.SynchronizeType)newValue );
173 }
174 }
175 GUILayout.EndHorizontal();
176 }
177 }
178 }
179 GUILayout.EndArea();
180 }
File name: PhotonGUI.cs
Copy
11 {
12 get
13 {
14 if( m_DefaultTitleStyle == null )
15 {
16 m_DefaultTitleStyle = new GUIStyle();
17 m_DefaultTitleStyle.border = new RectOffset( 2, 2, 2, 1 );
18 m_DefaultTitleStyle.margin = new RectOffset( 5, 5, 5, 0 );
19 m_DefaultTitleStyle.padding = new RectOffset( 5, 5, 0, 0 );
20 m_DefaultTitleStyle.alignment = TextAnchor.MiddleLeft;
21 m_DefaultTitleStyle.normal.background = ReorderableListResources.texTitleBackground;
22 m_DefaultTitleStyle.normal.textColor = EditorGUIUtility.isProSkin
23 ? new Color( 0.8f, 0.8f, 0.8f )
24 : new Color( 0.2f, 0.2f, 0.2f );
25 }
26
27 return m_DefaultTitleStyle;
28 }
29 }
File name: PhotonGUI.cs
Copy
69 {
70 get
71 {
72 if( m_DefaultRemoveButtonStyle == null )
73 {
74 m_DefaultRemoveButtonStyle = new GUIStyle();
75 m_DefaultRemoveButtonStyle.fixedWidth = 30;
76 m_DefaultRemoveButtonStyle.fixedHeight = 20;
77 m_DefaultRemoveButtonStyle.active.background = ReorderableListResources.CreatePixelTexture( "Dark Pixel (List GUI)", new Color32( 18, 18, 18, 255 ) );
78 m_DefaultRemoveButtonStyle.imagePosition = ImagePosition.ImageOnly;
79 m_DefaultRemoveButtonStyle.alignment = TextAnchor.MiddleCenter;
80 }
81
82 return m_DefaultRemoveButtonStyle;
83 }
84 }
File name: InstructionsScript.cs
Copy
27 void OnGUI() {
28 if (this.gameScript.gameView == "instructions") {
29 GUI.skin = currentGUISkin;
30
31 this.gameScript.mainCamera.transform.eulerAngles = new Vector3 (120, 23, 0);
32
33 GUIStyle labelStyle = new GUIStyle(currentGUISkin.label);
34 labelStyle.alignment = TextAnchor.UpperLeft;
35 GUILayout.Label ("Instructions", "BigLabel");
36
37
38 scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(Screen.width), GUILayout.Height(Mathf.Ceil(Screen.height * .80f)));
39
40 GUILayout.Label ("Object", "Subheader");
41
42 GUILayout.Label (@"The object of 2048-3D is to"
43 + " slide numbered blocks in such a way"
44 + " so that blocks with the same numbers collide"
45 + " and combine into a new block that is twice"
46 + " as much as the originals until"
47 + " the number 2048 is reached.", labelStyle);
48
49 GUILayout.Label ("Moving the Blocks", "Subheader");
50
51 GUILayout.Label (@"You cannot move blocks individually, but must"
52 + " move all blocks simultaneously in the same direction."
53 + " Blocks can move forward, backward, up, down, left"
54 + " and right along the green connectors."
55 + " Simply swipe any part of the screen to move up,"
56 + " down, left or right (keyboard: arrow keys). To move the"
57 + " blocks forward and backward use the"
58 + " big red arrow keys at the bottom of the screen (keyboard: a and z keys)."
59 + " When moving, all blocks that can slide in the chosen direction will move."
60 + " Any block moving toward another block with the same number will collide "
61 + " and form a single block with twice the number as the originals", labelStyle);
62
63
64 GUILayout.Label ("New Blocks", "Subheader");
65
66 GUILayout.Label (@"After each move is"
67 + " made a new block will appear randomly in an empty position."
68 + " This block will have a number of either 2 or 4."
69 + " For an extra challenge, there is a game option you can"
70 + " set so that zeros can also be assinged to a new block."
71 + " Zeros act like any other number in that they can"
72 + " collide with other zeros to make a block twice as much "
73 + " (which is still zero).", labelStyle);
74
75
76
77 GUILayout.Label ("Scoring and Finishing", "Subheader");
78
79 GUILayout.Label(@"For every block collision that occurs you receive"
80 + " the number of points of the newly"
81 + " created block. If after making a move"
82 + " all positions are filled and no new"
83 + " moves are possible, the game ends."
84 + " A separate high score / highest block is kept for each"
85 + " distinct combination of game options", labelStyle);
86
87
88 GUILayout.Label ("Game Layout Options", "Subheader");
89
90 GUILayout.Label (@"When I first made this game there"
91 + " was only one game layout, a 3x3x3 cube."
92 + " After testing it a bit, it was way to easy"
93 + " so the zero option was added."
94 + " It was still way to easy "
95 + " (e.g. you could swipe without even looking and get pretty far)."
96 + " Therefore there are now several diffent game layouts that"
97 + " make the game more challenging and fun.", labelStyle);
98
99 GUILayout.Label ("Game Timer Option", "Subheader");
100
101 GUILayout.Label (@"To give yourself even more of a challenge"
102 + " you can set game options to include a timer."
103 + " If a timer is chosen you have a specific"
104 + " amount of time to combined blocks to make the 64 block."
105 + " If you run out of time the game is over."
106 + " If you reach your target before the timer runs down you will"
107 + " receive additional time to reach the next target."
108 + " The time you received is as follows: \n"
109 + " 64: option time + 5 seconds (because the first one is the hardest!)\n"
110 + " 128: option time\n"
111 + " 256: 2X option time\n"
112 + " 512: 4X option time \n"
113 + " 1024: 8X option time \n"
114 + " you get the idea.", labelStyle);
115
116
117 GUILayout.Label ("Acknowledgements \nand Confessions", "Subheader");
118
119 GUILayout.Label (@"2048-3D is based upon the original" +
120 " 2048 game designed by Gabriele Cirulli " +
121 " \n\n" +
122 " Sound effects by freeSFX http://www.freesfx.co.uk.\n\n" +
123 " This game was designed using the Unity3D game engine.\n\n" +
124 " FOR MORE PROJECTS VISIT:" +
125 " https://code-projects.org/", labelStyle);
126
127
128 foreach (Touch touch in Input.touches) {
129 if (touch.phase == TouchPhase.Moved)
130 {
131 // dragging
132 this.scrollPosition.y += touch.deltaPosition.y;
133 }
134 }
135 GUILayout.EndScrollView();
136
137 if (GUILayout.Button ("Return to Menu")) {
138 this.gameScript.gameView = "menu";
139 }
140 }
141 }
File name: CurvedLayout.cs
Copy
48 void CalculateRadial() {
49 m_Tracker.Clear();
50 if (transform.childCount == 0)
51 return;
52
53 //one liner for figuring out the desired pivot (should be moved into a utility function)
54 Vector2 pivot = new Vector2(((int)childAlignment % 3) * 0.5f, ((int)childAlignment / 3) * 0.5f);
55
56 //this seems to work ok-ish
57 Vector3 lastPos = new Vector3(
58 GetStartOffset(0, GetTotalPreferredSize(0)),
59 GetStartOffset(1, GetTotalPreferredSize(1)),
60 0f
61 );
62
63 // 0 = first, 1 = last child
64 float lerp = 0;
65 //no need to catch divide by 0 as childCount > 0
66 float step = 1f / transform.childCount;
67
68 //normalize and create a distance between items
69 var dist = itemAxis.normalized * itemSize;
70
71 for (int i = 0; i < transform.childCount; i++) {
72 RectTransform child = (RectTransform)transform.GetChild(i);
73 if (child != null) {
74 //stop the user from altering certain values in the editor
75 m_Tracker.Add(this, child,
76 DrivenTransformProperties.Anchors |
77 DrivenTransformProperties.AnchoredPosition |
78 DrivenTransformProperties.Pivot);
79 Vector3 vPos = lastPos + dist;
80
81 child.localPosition = lastPos = vPos + (lerp - centerpoint) * CurveOffset;
82
83 child.pivot = pivot;
84 //child anchors are not yet calculated, each child should set it's own size for now
85 child.anchorMin = child.anchorMax = new Vector2(0.5f, 0.5f);
86 lerp += step;
87 }
88 }
89
90 }
File name: FlowLayoutGroup.cs
Copy
53 {
54 get
55 {
56 return childAlignment == TextAnchor.LowerCenter || childAlignment == TextAnchor.MiddleCenter ||
57 childAlignment == TextAnchor.UpperCenter;
58 }
59 }
File name: FlowLayoutGroup.cs
Copy
62 {
63 get
64 {
65 return childAlignment == TextAnchor.LowerRight || childAlignment == TextAnchor.MiddleRight ||
66 childAlignment == TextAnchor.UpperRight;
67 }
68 }
File name: FlowLayoutGroup.cs
Copy
71 {
72 get
73 {
74 return childAlignment == TextAnchor.MiddleLeft || childAlignment == TextAnchor.MiddleRight ||
75 childAlignment == TextAnchor.MiddleCenter;
76 }
77 }
Alignment 143 lượt xem
Gõ tìm kiếm nhanh...