FontStyle
How do I use Font Style
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PhotonEditor.cs
Copy
420 protected virtual void OnGuiRegisterCloudApp()
421 {
422 GUI.skin.label.wordWrap = true;
423 if (!this.isSetupWizard)
424 {
425 GUILayout.BeginHorizontal();
426 GUILayout.FlexibleSpace();
427 if (GUILayout.Button(CurrentLang.MainMenuButton, GUILayout.ExpandWidth(false)))
428 {
429 this.SwitchMenuState(GUIState.Main);
430 }
431
432 GUILayout.EndHorizontal();
433
434 GUILayout.Space(15);
435 }
436
437 if (this.photonSetupState == PhotonSetupStates.RegisterForPhotonCloud)
438 {
439 GUI.skin.label.fontStyle = FontStyle.Bold;
440 GUILayout.Label(CurrentLang.ConnectButton);
441 EditorGUILayout.Separator();
442 GUI.skin.label.fontStyle = FontStyle.Normal;
443
444 GUILayout.Label(CurrentLang.UsePhotonLabel);
445 EditorGUILayout.Separator();
446 this.emailAddress = EditorGUILayout.TextField(CurrentLang.EmailLabel, this.emailAddress);
447
448 if (GUILayout.Button(CurrentLang.SendButton))
449 {
450 GUIUtility.keyboardControl = 0;
451 this.RegisterWithEmail(this.emailAddress);
452 }
453
454 GUILayout.Space(20);
455
456
457 GUILayout.Label(CurrentLang.SignedUpAlreadyLabel);
458 if (GUILayout.Button(CurrentLang.SetupButton))
459 {
460 this.photonSetupState = PhotonSetupStates.SetupPhotonCloud;
461 }
462 EditorGUILayout.Separator();
463
464
465 GUILayout.Label(CurrentLang.RegisterByWebsiteLabel);
466 if (GUILayout.Button(CurrentLang.AccountWebsiteButton))
467 {
468 EditorUtility.OpenWithDefaultApp(UrlAccountPage + Uri.EscapeUriString(this.emailAddress));
469 }
470
471 EditorGUILayout.Separator();
472
473 GUILayout.Label(CurrentLang.SelfHostLabel);
474
475 if (GUILayout.Button(CurrentLang.SelfHostSettingsButton))
476 {
477 this.photonSetupState = PhotonSetupStates.SetupSelfHosted;
478 }
479
480 GUILayout.FlexibleSpace();
481
482
483 if (!InternalEditorUtility.HasAdvancedLicenseOnBuildTarget(BuildTarget.Android) || !InternalEditorUtility.HasAdvancedLicenseOnBuildTarget(BuildTarget.iOS))
484 {
485 GUILayout.Label(CurrentLang.MobileExportNoteLabel);
486 }
487 EditorGUILayout.Separator();
488 }
489 else if (this.photonSetupState == PhotonSetupStates.EmailAlreadyRegistered)
490 {
491 GUI.skin.label.fontStyle = FontStyle.Bold;
492 GUILayout.Label(CurrentLang.OopsLabel);
493 GUI.skin.label.fontStyle = FontStyle.Normal;
494
495 GUILayout.Label(CurrentLang.EmailInUseLabel);
496
497 if (GUILayout.Button(CurrentLang.SeeMyAccountPageButton))
498 {
499 EditorUtility.OpenWithDefaultApp(UrlCloudDashboard + Uri.EscapeUriString(this.emailAddress));
500 }
501
502 EditorGUILayout.Separator();
503
504 GUILayout.Label(CurrentLang.KnownAppIdLabel);
505 GUILayout.BeginHorizontal();
506 if (GUILayout.Button(CurrentLang.CancelButton))
507 {
508 this.photonSetupState = PhotonSetupStates.RegisterForPhotonCloud;
509 }
510
511 if (GUILayout.Button(CurrentLang.SetupButton))
512 {
513 this.photonSetupState = PhotonSetupStates.SetupPhotonCloud;
514 }
515
516 GUILayout.EndHorizontal();
517 }
518 else if (this.photonSetupState == PhotonSetupStates.SetupPhotonCloud)
519 {
520 // cloud setup
521 GUI.skin.label.fontStyle = FontStyle.Bold;
522 GUILayout.Label(CurrentLang.PhotonCloudConnect);
523 GUI.skin.label.fontStyle = FontStyle.Normal;
524
525 EditorGUILayout.Separator();
526 this.OnGuiSetupCloudAppId();
527 this.OnGuiCompareAndHelpOptions();
528 }
529 else if (this.photonSetupState == PhotonSetupStates.SetupSelfHosted)
530 {
531 // self-hosting setup
532 GUI.skin.label.fontStyle = FontStyle.Bold;
533 GUILayout.Label(CurrentLang.SetupOwnHostLabel);
534 GUI.skin.label.fontStyle = FontStyle.Normal;
535
536 EditorGUILayout.Separator();
537
538 this.OnGuiSetupSelfhosting();
539 this.OnGuiCompareAndHelpOptions();
540 }
541 }
File name: PhotonGUI.cs
Copy
107 {
108 get
109 {
110 if( m_FoldoutBold == null )
111 {
112 m_FoldoutBold = new GUIStyle( EditorStyles.foldout );
113 m_FoldoutBold.fontStyle = FontStyle.Bold;
114 }
115
116 return m_FoldoutBold;
117 }
118 }
File name: MenuScript.cs
Copy
21 void OnGUI() {
22 if (this.gameScript.gameView == "menu") {
23 this.gameScript.mainCamera.transform.eulerAngles = new Vector3 (180, 23, 0);
24 this.gameScript.gameLight.intensity = 0;
25
26 //set the sizes appropriately
27 GUI.skin = this.gameScript.currentGUISkin;
28
29 GUIStyle playButtonStyle = new GUIStyle(currentGUISkin.GetStyle("Button"));
30 playButtonStyle.fontSize = Mathf.CeilToInt(Screen.height * 0.10F);
31 playButtonStyle.fontStyle = FontStyle.Italic;
32
33
34 GUIStyle menuButtonStyle = new GUIStyle(currentGUISkin.GetStyle("Button"));
35 menuButtonStyle.fontSize = Mathf.CeilToInt(Screen.height * 0.06F);
36
37
38 GUIStyle titleLabelStyle = new GUIStyle(currentGUISkin.GetStyle("TitleLabel"));
39 titleLabelStyle.fontSize = Mathf.CeilToInt(Screen.height * 0.13F);
40
41 GUI.Label (new Rect (0, 0, Screen.width, Screen.height * 0.06F), "2048 - 3D", titleLabelStyle);
42
43
44 GUI.Label (new Rect (0, Screen.height * 0.15F, Screen.width, Screen.height * 0.06F), "");
45
46
47 if (GUI.Button(new Rect(Screen.width * 0.20f, Screen.height * 0.25f, Screen.width * 0.60F, Screen.height * 0.10F),"Options", menuButtonStyle)) {
48 this.gameScript.gameView = "options";
49 }
50 if (GUI.Button(new Rect(Screen.width * 0.20f, Screen.height * 0.40f, Screen.width * 0.60F, Screen.height * 0.10F),"Instructions", menuButtonStyle)) {
51 this.gameScript.gameView = "instructions";
52 }
53 if (GUI.Button(new Rect(Screen.width * 0.20f, Screen.height * 0.55F, Screen.width * 0.60F, Screen.height * 0.10F),"Exit", menuButtonStyle)) {
54 Application.Quit();
55 }
56
57 if (GUI.Button(new Rect(Screen.width * .20f, Screen.height * 0.70F, Screen.width * 0.60F, Screen.height * 0.15F),"Play!",playButtonStyle)) {
58 this.gameScript.gameView = "game";
59 }
60
61 GUI.Label (new Rect (0, Screen.height * 0.94F, Screen.width, Screen.height * 0.06F), " 2018 - Brought To You By code-projects.org");
62
63 }
64 }
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: frmCustomerOrders.cs
Copy
28 private void Button7_Click(object sender, EventArgs e)
29 {
30 if (DataGridView3.DataSource == null)
31 {
32 MessageBox.Show("Sorry nothing to export into excel sheet..", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
33 return;
34 }
35 int rowsTotal = 0;
36 int colsTotal = 0;
37 int I = 0;
38 int j = 0;
39 int iC = 0;
40 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
41 Excel.Application xlApp = new Excel.Application();
42
43 try
44 {
45 Excel.Workbook excelBook = xlApp.Workbooks.Add();
46 Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelBook.Worksheets[1];
47 xlApp.Visible = true;
48
49 rowsTotal = DataGridView3.RowCount;
50 colsTotal = DataGridView3.Columns.Count - 1;
51 var _with1 = excelWorksheet;
52 _with1.Cells.Select();
53 _with1.Cells.Delete();
54 for (iC = 0; iC <= colsTotal; iC++)
55 {
56 _with1.Cells[1, iC + 1].Value = DataGridView3.Columns[iC].HeaderText;
57 }
58 for (I = 0; I <= rowsTotal - 1; I++)
59 {
60 for (j = 0; j <= colsTotal; j++)
61 {
62 _with1.Cells[I + 2, j + 1].value = DataGridView3.Rows[I].Cells[j].Value;
63 }
64 }
65 _with1.Rows["1:1"].Font.FontStyle = "Bold";
66 _with1.Rows["1:1"].Font.Size = 12;
67
68 _with1.Cells.Columns.AutoFit();
69 _with1.Cells.Select();
70 _with1.Cells.EntireColumn.AutoFit();
71 _with1.Cells[1, 1].Select();
72 }
73 catch (Exception ex)
74 {
75 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
76 }
77 finally
78 {
79 //RELEASE ALLOACTED RESOURCES
80 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
81 xlApp = null;
82 }
83 }
File name: frmCustomerOrders.cs
Copy
223 private void Button3_Click(object sender, EventArgs e)
224 {
225 if (DataGridView1.DataSource == null)
226 {
227 MessageBox.Show("Sorry nothing to export into excel sheet..", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
228 return;
229 }
230 int rowsTotal = 0;
231 int colsTotal = 0;
232 int I = 0;
233 int j = 0;
234 int iC = 0;
235 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
236 Excel.Application xlApp = new Excel.Application();
237
238 try
239 {
240 Excel.Workbook excelBook = xlApp.Workbooks.Add();
241 Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelBook.Worksheets[1];
242 xlApp.Visible = true;
243
244 rowsTotal = DataGridView1.RowCount;
245 colsTotal = DataGridView1.Columns.Count - 1;
246 var _with1 = excelWorksheet;
247 _with1.Cells.Select();
248 _with1.Cells.Delete();
249 for (iC = 0; iC <= colsTotal; iC++)
250 {
251 _with1.Cells[1, iC + 1].Value = DataGridView1.Columns[iC].HeaderText;
252 }
253 for (I = 0; I <= rowsTotal - 1; I++)
254 {
255 for (j = 0; j <= colsTotal; j++)
256 {
257 _with1.Cells[I + 2, j + 1].value = DataGridView1.Rows[I].Cells[j].Value;
258 }
259 }
260 _with1.Rows["1:1"].Font.FontStyle = "Bold";
261 _with1.Rows["1:1"].Font.Size = 12;
262
263 _with1.Cells.Columns.AutoFit();
264 _with1.Cells.Select();
265 _with1.Cells.EntireColumn.AutoFit();
266 _with1.Cells[1, 1].Select();
267 }
268 catch (Exception ex)
269 {
270 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
271 }
272 finally
273 {
274 //RELEASE ALLOACTED RESOURCES
275 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
276 xlApp = null;
277 }
278 }
File name: frmCustomersRecord.cs
Copy
85 private void Button3_Click(object sender, EventArgs e)
86 {
87 if (dataGridView1.DataSource == null)
88 {
89 MessageBox.Show("Sorry nothing to export into excel sheet..", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
90 return;
91 }
92 int rowsTotal = 0;
93 int colsTotal = 0;
94 int I = 0;
95 int j = 0;
96 int iC = 0;
97 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
98 Excel.Application xlApp = new Excel.Application();
99
100 try
101 {
102 Excel.Workbook excelBook = xlApp.Workbooks.Add();
103 Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelBook.Worksheets[1];
104 xlApp.Visible = true;
105
106 rowsTotal = dataGridView1.RowCount;
107 colsTotal = dataGridView1.Columns.Count - 1;
108 var _with1 = excelWorksheet;
109 _with1.Cells.Select();
110 _with1.Cells.Delete();
111 for (iC = 0; iC <= colsTotal; iC++)
112 {
113 _with1.Cells[1, iC + 1].Value = dataGridView1.Columns[iC].HeaderText;
114 }
115 for (I = 0; I <= rowsTotal - 1; I++)
116 {
117 for (j = 0; j <= colsTotal; j++)
118 {
119 _with1.Cells[I + 2, j + 1].value = dataGridView1.Rows[I].Cells[j].Value;
120 }
121 }
122 _with1.Rows["1:1"].Font.FontStyle = "Bold";
123 _with1.Rows["1:1"].Font.Size = 12;
124
125 _with1.Cells.Columns.AutoFit();
126 _with1.Cells.Select();
127 _with1.Cells.EntireColumn.AutoFit();
128 _with1.Cells[1, 1].Select();
129 }
130 catch (Exception ex)
131 {
132 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
133 }
134 finally
135 {
136 //RELEASE ALLOACTED RESOURCES
137 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
138 xlApp = null;
139 }
140 }
File name: frmCustomersRecord1.cs
Copy
103 private void Button3_Click(object sender, EventArgs e)
104 {
105 if (dataGridView1.DataSource == null)
106 {
107 MessageBox.Show("Sorry nothing to export into excel sheet..", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
108 return;
109 }
110 int rowsTotal = 0;
111 int colsTotal = 0;
112 int I = 0;
113 int j = 0;
114 int iC = 0;
115 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
116 Excel.Application xlApp = new Excel.Application();
117
118 try
119 {
120 Excel.Workbook excelBook = xlApp.Workbooks.Add();
121 Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelBook.Worksheets[1];
122 xlApp.Visible = true;
123
124 rowsTotal = dataGridView1.RowCount;
125 colsTotal = dataGridView1.Columns.Count - 1;
126 var _with1 = excelWorksheet;
127 _with1.Cells.Select();
128 _with1.Cells.Delete();
129 for (iC = 0; iC <= colsTotal; iC++)
130 {
131 _with1.Cells[1, iC + 1].Value = dataGridView1.Columns[iC].HeaderText;
132 }
133 for (I = 0; I <= rowsTotal - 1; I++)
134 {
135 for (j = 0; j <= colsTotal; j++)
136 {
137 _with1.Cells[I + 2, j + 1].value = dataGridView1.Rows[I].Cells[j].Value;
138 }
139 }
140 _with1.Rows["1:1"].Font.FontStyle = "Bold";
141 _with1.Rows["1:1"].Font.Size = 12;
142
143 _with1.Cells.Columns.AutoFit();
144 _with1.Cells.Select();
145 _with1.Cells.EntireColumn.AutoFit();
146 _with1.Cells[1, 1].Select();
147 }
148 catch (Exception ex)
149 {
150 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
151 }
152 finally
153 {
154 //RELEASE ALLOACTED RESOURCES
155 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
156 xlApp = null;
157 }
158 }
File name: frmCustomersRecord2.cs
Copy
110 private void Button3_Click(object sender, EventArgs e)
111 {
112 if (dataGridView1.DataSource == null)
113 {
114 MessageBox.Show("Sorry nothing to export into excel sheet..", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
115 return;
116 }
117 int rowsTotal = 0;
118 int colsTotal = 0;
119 int I = 0;
120 int j = 0;
121 int iC = 0;
122 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
123 Excel.Application xlApp = new Excel.Application();
124
125 try
126 {
127 Excel.Workbook excelBook = xlApp.Workbooks.Add();
128 Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelBook.Worksheets[1];
129 xlApp.Visible = true;
130
131 rowsTotal = dataGridView1.RowCount;
132 colsTotal = dataGridView1.Columns.Count - 1;
133 var _with1 = excelWorksheet;
134 _with1.Cells.Select();
135 _with1.Cells.Delete();
136 for (iC = 0; iC <= colsTotal; iC++)
137 {
138 _with1.Cells[1, iC + 1].Value = dataGridView1.Columns[iC].HeaderText;
139 }
140 for (I = 0; I <= rowsTotal - 1; I++)
141 {
142 for (j = 0; j <= colsTotal; j++)
143 {
144 _with1.Cells[I + 2, j + 1].value = dataGridView1.Rows[I].Cells[j].Value;
145 }
146 }
147 _with1.Rows["1:1"].Font.FontStyle = "Bold";
148 _with1.Rows["1:1"].Font.Size = 12;
149
150 _with1.Cells.Columns.AutoFit();
151 _with1.Cells.Select();
152 _with1.Cells.EntireColumn.AutoFit();
153 _with1.Cells[1, 1].Select();
154 }
155 catch (Exception ex)
156 {
157 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
158 }
159 finally
160 {
161 //RELEASE ALLOACTED RESOURCES
162 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
163 xlApp = null;
164 }
165 }
File name: frmMainMenu.cs
Copy
430 private void btnGetData_Click(object sender, EventArgs e)
431 {
432
433 int rowsTotal = 0;
434 int colsTotal = 0;
435 int I = 0;
436 int j = 0;
437 int iC = 0;
438 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
439 Excel.Application xlApp = new Excel.Application();
440
441 try
442 {
443 Excel.Workbook excelBook = xlApp.Workbooks.Add();
444 Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelBook.Worksheets[1];
445 xlApp.Visible = true;
446
447 rowsTotal = dataGridView1.RowCount;
448 colsTotal = dataGridView1.Columns.Count - 1;
449 var _with1 = excelWorksheet;
450 _with1.Cells.Select();
451 _with1.Cells.Delete();
452 for (iC = 0; iC <= colsTotal; iC++)
453 {
454 _with1.Cells[1, iC + 1].Value = dataGridView1.Columns[iC].HeaderText;
455 }
456 for (I = 0; I <= rowsTotal - 1; I++)
457 {
458 for (j = 0; j <= colsTotal; j++)
459 {
460 _with1.Cells[I + 2, j + 1].value = dataGridView1.Rows[I].Cells[j].Value;
461 }
462 }
463 _with1.Rows["1:1"].Font.FontStyle = "Bold";
464 _with1.Rows["1:1"].Font.Size = 12;
465
466 _with1.Cells.Columns.AutoFit();
467 _with1.Cells.Select();
468 _with1.Cells.EntireColumn.AutoFit();
469 _with1.Cells[1, 1].Select();
470 }
471 catch (Exception ex)
472 {
473 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
474 }
475 finally
476 {
477 //RELEASE ALLOACTED RESOURCES
478 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
479 xlApp = null;
480 }
481 }
Download file with original file name:FontStyle
FontStyle 149 lượt xem
Gõ tìm kiếm nhanh...