บทความ

การทำ highlight กับข้อความใน Gridview

เริ่มจาก add css ก่อนเลยครับ style type ="text/css"> .highlight { text-decoration : none ; font-weight : bold ; color : black ; background : yellow ;} style > หลังจากนั้น ก็เข้าไปดูในส่วนของ Code behide ส่วนของ gridview_RowDataBound ให้ add โค้ดนี้ครับ if (e.Row.RowType == DataControlRowType .DataRow) { TableCell cell = e.Row.Cells[1]; //เลือก Column ที่ ต้องการ string cellText = cell.Text; int leftIndex = cellText.IndexOf(Textbox1.Text, StringComparison .OrdinalIgnoreCase); //เปรียบเทียบคำระหว่างTextbox1.Text กับcellText if (leftIndex >= 0) { int rightIndex = leftIndex + txtEmpName.Text.Length; StringBuilder builder = new StringBuilder (); builder.Append(cellText, 0, leftIndex); builder.Append( " " ); builder.Append(cellText, leftIndex, rightIndex - leftIndex); builder.Append( " " ); builder.Append(cellText, rightIndex, cellText.Length - rightIndex); cell.Text = builder.ToString(); } ปล.เราสามา...

substr

รูปแบบของการ substr substr ( 'abcdef' , 1 ); // bcdef substr ( 'abcdef' , 1 , 3 ); // bcd substr ( 'abcdef' , 0 , 4 ); // abcd substr ( 'abcdef' , 0 , 8 ); // abcdef substr ( 'abcdef' , - 1 , 1 ); // f

คำนวณอายุ

age = DateDiff(DateInterval.Year, CDate(birthday), Now.Date, Microsoft.VisualBasic.FirstDayOfWeek.Monday, FirstWeekOfYear.Jan1)

split คือ คำสั่งตัดคำ

Dim splitfilename As String Dim DocumentNamesplit As String splitfilename = DocumentName.Split(CChar("\")) 'คำสั่งที่ใช้ในการตัดชื่อ part "\" คือสิ่งที่ต้องการที่จะตัด DocumentNamesplit = splitfilename(splitfilename.Length - 1) 'ส่วนนี้เป็นส่วนที่เหลือแต่ชื่อหลังจากการตัด Part แล้ว
การใช้ OpenFileDialog Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click OpenFileDialog1.Filter = "Image (*.jpeg;*.gif;*.bmp;*.png)*.jpg;*.gif;*.bmp;*.png)" OpenFileDialog1.FileName = "" OpenFileDialog1.ShowDialog() If currentfile Nothing Then picAsset.Image = Image.FromFile(currentfile) End If End Sub Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk If e.Cancel = True Then Exit Sub currentfile = OpenFileDialog1.FileName End Sub
Code Copy File ใช้ File.Copy ครับ ใน namespace System.IO เช่น: File.Copy(sourceFileName, DistributionFileName) หรือตรวจสอบนิดนึ่งว่ามีไฟล์ต้นทางใหม มีจึง Copy If File.Exists(sourceFileName) = True Then File.Copy(sourceFileName, DistributionFileName) End If
ควบคุมปิดหน้าต่าง ตรงกดปุ่มกากบาท private void frmMain_FormClosing(object sender, FormClosingEventArgs e) { if (MessageBox.Show("คุณต้องการออกจากโปรแกรม ใช่หรือไม่...", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { e.Cancel = false; // ปิดไปเลย}else{ e.Cancel = true; //มันจะยังไม่ปิด } } เพิ่มเติมที่ปุ่ม Exit private void btExit_Exit_Click(object sender, EventArgs e) { this.Close();//มันจะวิ่งไปที่ FormClosing }