บทความ

กำลังแสดงโพสต์จาก ตุลาคม, 2008
การใช้ 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 }
การส่งค่าจากฟอร์มให้แสดงที่ Crystal Report โดยใช้ ParameterFields ParameterFields pfs1 = new ParameterFields(); ParameterFields pfs2 = new ParameterFields(); ParameterFields pfs3 = new ParameterFields(); ParameterField pf1 = new ParameterField(); ParameterField pf2 = new ParameterField(); ParameterField pf3 = new ParameterField(); ParameterDiscreteValue pdv1 = new ParameterDiscreteValue(); ParameterDiscreteValue pdv2 = new ParameterDiscreteValue(); ParameterDiscreteValue pdv3 = new ParameterDiscreteValue(); pf1.Name = "CompanyName"; pdv1.Value = strComName; pf2.Name = "FromDateTime"; pdv2.Value = strfromdatetime; pf3.Name = "ToDateTime"; pdv3.Value = strtodatetime; pf1.CurrentValues.Add(pdv1); pfs1.Add(pf1); pf2.CurrentValues.Add(pdv2); pfs2.Add(pf2); pf3.CurrentValues.Add(pdv3); pfs...
ใส่ Format วันที่-เวลา ให้กับ Cell ของ DataGrid private void dgvShow_CellFormatting(object sender, taGridViewCellFormattingEventArgs e) { if (dgvShow.Columns[e.ColumnIndex].Name == "dtInDate") { e.CellStyle.Format = "dd/MM/yyyy HH:mm:ss"; e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft; FormatdgvShow(); } if (dgvShow.Columns[e.ColumnIndex].Name == "dtOutDate") { e.CellStyle.Format = "dd/MM/yyyy HH:mm:ss"; e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft; FormatdgvShow(); } }
การสร้าง Textbox ที่ฟอร์ม (createTextboxOnForm) public frmPaySlip() { InitializeComponent(); TextBox tb = new TextBox(); this.Controls.Add(tb); tb.KeyPress += new KeyPressEventHandler(keypressed); }
ดึงข้อมูลจาก Database มาโชว์ใน DropDownList strsqlLoad = "SELECT DISTINCT(iCompany),Company_Name FROM Company_Trns"; DBdsLoad = objConn.Execute2Table(strsqlLoad, 1); ddlCompany.DataSource = DBdsLoad; ddlCompany.DataTextField = "Company_Name"; ddlCompany.DataValueField = "iCompany"; ddlCompany.DataBind(); foreach (DataRow dr in DBdsLoad.Tables[0].Rows) { ListItem Litemcompany = new ListItem(); Litemcompany.Text = dr["company_name"].ToString().Trim(); Litemcompany.Value = dr["icompany"].ToString(); ddlCompany.Items.Add(Litemcompany); ddlCompany.DataSource = DBdsLoad; }
การ Add Data โดยใช้ Datarow If ds.Tables.Contains("AddData") Then ds.Tables("Adddata").Clear() Dim daAdd As New OleDbDataAdapter("Select * From TimeTStu ", cn) daAdd.Fill(ds, "AddData") Dim AutoID As Integer Dim CountRow As Integer CountRow = ds.Tables("AddData").Rows.Count If CountRow = 0 Then AutoID = 1 Else CountRow = ds.Tables("AddData").Rows.Count - 1 AutoID = ds.Tables("AddData").Rows(CountRow).Item("RecNo") + 1 End If Dim drAdd As DataRow = ds.Tables("AddData").NewRow drAdd("RecNo") = AutoID drAdd("AcadYear") = ddlAcadYear.SelectedValue drAdd("SubjectID") = SubjectID drAdd("Grade") = GradeID drAdd("Days") = ddlDays.SelectedValue drAdd("StartTime") = ddlHStart.SelectedValue & ":" & ddlMStart.SelectedValue ' & ":" & คือการรวม ddl 2 ตัว มารวมกันใน textbox เดียว drAdd("EndTime") = ddlH...
Fomat Money in Grid Private Sub dgvAsset_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgvAsset.CellFormatting If dgvAsset.Columns(e.ColumnIndex).Name = "Price"Then e.CellStyle.Format = "#,##0.00" e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight End If End Sub Fomat Money in Textbox Textbox1.Text = Format(CDec(ds.Tables("Asset").Rows(0).Item(4)), "#,###.00")
Send Email Dim Message As New MailMessage() Dim AT As New Attachment(txtTHAtt.Text) Message.From = New MailAddress( register @ master.com ) Message.To.Add("Test Send Message") Message.Subject = txtTHSubject.Text.Replace("'", "''")&txtTHNo.Text Message.Attachments.Add(AT) Message.Body = txtTHMessage.Text.Replace("'", "''") Message.BodyEncoding = System.Text.Encoding.GetEncoding("windows-874") Dim mailClient As New SmtpClient("mail.trinity.ac.th") mailClient.DeliveryMethod = SmtpDeliveryMethod.Network 'เป็นการปลดล็อก ต่างๆให้ผ่านได้ตลอด mailClient.UseDefaultCredentials = True mailClient.Send(Message)
Remove Cell DataGrid Dim i As Integer For i = 0 To ds.Tables("violation").Rows.Count - 1 If CInt(ds.Tables("violation").Rows(i).Item("violationcode")) = Violationid Then ds.Tables("violation").Rows.RemoveAt(i) ds.Tables("violation").AcceptChanges() Violationid = Nothing Exit For End IF Next With gridViolation For p = 0 To gridViolation.Rows.Count - 1 If .Rows(p).Selected = True Then .CurrentCell = .Item(2, p) CurrentCell = CStr(gridViolation.Rows(p).Cells(1).Value) Violationid = CInt(gridViolation.Rows(p).Cells(0).Value) CurrentProjectName = CurrentCell Exit For End If Next End With