intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Bài giảng Lập trình C# 2010: Chương 2.3 - ĐH Công nghệ Đồng Nai

Chia sẻ: Na Na | Ngày: | Loại File: PPTX | Số trang:21

101
lượt xem
19
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Bài giảng Lập trình C# 2010: Chương 2.3 trình bày cách thức thực hiện, câu lệnh, nút lệnh và tính năng của các nút lệnh cùng một số nội dung khác về Windows Forms and Windows Forms Controls.

Chủ đề:
Lưu

Nội dung Text: Bài giảng Lập trình C# 2010: Chương 2.3 - ĐH Công nghệ Đồng Nai

  1. DONG NAI UNIVERSITY OF TECHNOLOGY
  2. DONG NAI UNIVERSITY OF TECHNOLOGY ColorDial og pnColor How to use btnColo ColorDialog r ?
  3. DONG NAI UNIVERSITY OF TECHNOLOGY private void btnColor_Click (object sender, EventArgs e) { ColorDialog cldlg= new ColorDialog(); cldlg.Color = pnColor.BackColor; if(cldlg.ShowDialog()==DialogResult .OK) pnColor.BackColor = cldlg.Color; }
  4. DONG NAI UNIVERSITY OF TECHNOLOGY If you want to set color by the RED, GREEN, BLUE. Please see figure below: pnColo r trackBarRe d txtRed trackBarGre en txtGreen trackBarBlu e txtBlue
  5. DONG NAI UNIVERSITY OF TECHNOLOGY For each trackbar, please set properties as the same figure
  6. DONG NAI UNIVERSITY OF TECHNOLOGY private void setColor(){ int nRed = trackBarRed.Value; int nGreen = trackBarGreen.Value; int nBlue = trackBarBlue.Value; txtRed.Text = nRed+""; txtBlue.Text = nBlue + ""; txtGreen.Text = nGreen+""; pnColor.BackColor = Color.FromArgb(nRed, nGreen,nBlue);
  7. DONG NAI UNIVERSITY OF TECHNOLOGY Create Event or trackbar control private void processTrackBar (object sender, EventArgs e) { setColor(); }
  8. DONG NAI UNIVERSITY OF TECHNOLOGY private void frmColorDialog_Load (object sender, EventArgs e) { trackBarBlue.Scroll += processTrackBar; trackBarGreen.Scroll += processTrackBar; trackBarRed.Scroll += processTrackBar; setColor(); }
  9. DONG NAI UNIVERSITY OF TECHNOLOGY Name Description Maximum The Maximum property sets the value of the track bar when the slider is all the way to the right Minimum Gets or sets the lower limit of the range this TrackBar is working with. Value Gets or sets a numeric value that represents the current position of the scroll box on the track bar
  10. DONG NAI UNIVERSITY OF TECHNOLOGY Name Description LargeChang Sets how many positions to e move if the bar is clicked on either side of the slider SmallChang sets how many positions to e move if the keyboard arrows are used to move the slider TickFrequen Establishes how many positions cy are between each tick-mark
  11. DONG NAI UNIVERSITY OF TECHNOLOGY FontDialo g lblFon t How to use btnFont FontDialog ?
  12. private void btnFont_Click DONG NAI UNIVERSITY OF TECHNOLOGY (object sender, EventArgs e) { FontDialog ftDialog = new FontDialog(); ftDialog.Font = lblFont.Font; if (ftDialog.ShowDialog() == DialogResult.OK) { lblFont.Font = ftDialog.Font; }
  13. DONG NAI UNIVERSITY OF TECHNOLOGY RichTextBox & StreamFile
  14. DONG NAI UNIVERSITY OF TECHNOLOGY OpenFileDialog openDlg = new OpenFileDialog(); openDlg.Filter = "(*.txt)| *.txt|(All)|*.*"; if (openDlg.ShowDialog() == DialogResult.OK) { rtFile.LoadFile(openDlg.FileNam e, RichTextBoxStreamType.PlainText ); }
  15. DONG NAI UNIVERSITY OF TECHNOLOGY You could choose StreamType
  16. DONG NAI UNIVERSITY OF TECHNOLOGY But We could use StreamFile to read Data. You should Know this
  17. DONG NAI UNIVERSITY OF TECHNOLOGY Add this command at the top File using System.IO; if (openDlg.ShowDialog() == DialogResult.OK) { //Open to read Stream stream = openDlg.OpenFile(); StreamReader reader = new StreamReader(stream); richTxtFile.Text = reader.ReadToEnd(); reader.Close();
  18. DONG NAI UNIVERSITY OF TECHNOLOGY RichTextBox & StreamFile
  19. DONG NAI UNIVERSITY OF TECHNOLOGY SaveFileDialog saveDlg = new SaveFileDialog(); saveDlg.Filter = "(*.txt)| *.txt|(All)|*.*"; if (saveDlg.ShowDialog() == DialogResult.OK) { rtFile.SaveFile(saveDlg.FileNam e,RichTextBoxStreamType.PlainTe xt); }
  20. Use StreamFile to Write Data. DONG NAI UNIVERSITY OF TECHNOLOGY if (saveDlg.ShowDialog() == DialogResult.OK) { Stream stream = saveDlg.OpenFile();//Open to Write StreamWriter writer = new StreamWriter(stream); writer.WriteLine(rtFile.Text); writer.Close();
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2