1. Trang chủ
  2. » Công Nghệ Thông Tin

Bài giảng lập trình c 2010 chương 2 3 đh công nghệ đồng nai

21 268 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 21
Dung lượng 1,13 MB

Nội dung

DONG NAI UNIVERSITY OF TECHNOLOGY DONG NAI UNIVERSITY OF TECHNOLOGY ColorDialog pnColor btnColor How to use ColorDialog? 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; } DONG NAI UNIVERSITY OF TECHNOLOGY If you want to set color by the RED, GREEN, BLUE Please see figure below: pnColor trackBarRed txtRed trackBarGreen txtGreen trackBarBlue txtBlue DONG NAI UNIVERSITY OF TECHNOLOGY For each trackbar, please set properties as the same figure 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); } DONG NAI UNIVERSITY OF TECHNOLOGY Create Event or trackbar control private void processTrackBar (object sender, EventArgs e) { setColor(); } DONG NAI UNIVERSITY OF TECHNOLOGY private void frmColorDialog_Load (object sender, EventArgs e) { trackBarBlue.Scroll += processTrackBar; trackBarGreen.Scroll += processTrackBar; trackBarRed.Scroll += processTrackBar; setColor(); } DONG NAI UNIVERSITY OF TECHNOLOGY Name Maximum Minimum Value Description The Maximum property sets the value of the track bar when the slider is all the way to the right Gets or sets the lower limit of the range this TrackBar is working with Gets or sets a numeric value that represents the current position of the scroll box on the track bar DONG NAI UNIVERSITY OF TECHNOLOGY Name LargeChange Description Sets how many positions to move if the bar is clicked on either side of the slider SmallChange sets how many positions to move if the keyboard arrows are used to move the slider TickFrequency Establishes how many positions are between each tick-mark DONG NAI UNIVERSITY OF TECHNOLOGY FontDialog lblFont btnFont How to use FontDialog? private void btnFont_Click (object sender, EventArgs e) { FontDialog ftDialog = new FontDialog(); ftDialog.Font = lblFont.Font; if (ftDialog.ShowDialog() == DialogResult.OK) { lblFont.Font = ftDialog.Font; } } DONG NAI UNIVERSITY OF TECHNOLOGY DONG NAI UNIVERSITY OF TECHNOLOGY RichTextBox & StreamFile DONG NAI UNIVERSITY OF TECHNOLOGY OpenFileDialog openDlg = new OpenFileDialog(); openDlg.Filter = "(*.txt)|*.txt| (All)|*.*"; if (openDlg.ShowDialog() == DialogResult.OK) { rtFile.LoadFile(openDlg.FileName, RichTextBoxStreamType.PlainText); } DONG NAI UNIVERSITY OF TECHNOLOGY You could choose StreamType DONG NAI UNIVERSITY OF TECHNOLOGY But We could use StreamFile to read Data You should Know this 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(); } DONG NAI UNIVERSITY OF TECHNOLOGY RichTextBox & StreamFile DONG NAI UNIVERSITY OF TECHNOLOGY SaveFileDialog saveDlg = new SaveFileDialog(); saveDlg.Filter = "(*.txt)|*.txt| (All)|*.*"; if (saveDlg.ShowDialog() == DialogResult.OK) { rtFile.SaveFile(saveDlg.FileName, RichTextBoxStreamType.PlainText); } 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(); } DONG NAI UNIVERSITY OF TECHNOLOGY END [...]...DONG NAI UNIVERSITY OF TECHNOLOGY FontDialog lblFont btnFont How to use FontDialog? private void btnFont_Click (object sender, EventArgs e) { FontDialog ftDialog = new FontDialog(); ftDialog.Font = lblFont.Font; if (ftDialog.ShowDialog() == DialogResult.OK) { lblFont.Font = ftDialog.Font; } } DONG NAI UNIVERSITY OF TECHNOLOGY DONG NAI UNIVERSITY OF TECHNOLOGY RichTextBox & StreamFile DONG NAI UNIVERSITY... UNIVERSITY OF TECHNOLOGY OpenFileDialog openDlg = new OpenFileDialog(); openDlg.Filter = "(*.txt)|*.txt| (All)|*.*"; if (openDlg.ShowDialog() == DialogResult.OK) { rtFile.LoadFile(openDlg.FileName, RichTextBoxStreamType.PlainText); } DONG NAI UNIVERSITY OF TECHNOLOGY You could choose StreamType DONG NAI UNIVERSITY OF TECHNOLOGY But We could use StreamFile to read Data You should Know this DONG NAI UNIVERSITY... this 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(); } DONG NAI UNIVERSITY OF TECHNOLOGY RichTextBox & StreamFile DONG NAI UNIVERSITY OF TECHNOLOGY SaveFileDialog saveDlg... DialogResult.OK) { rtFile.SaveFile(saveDlg.FileName, RichTextBoxStreamType.PlainText); } 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(); } DONG NAI UNIVERSITY OF TECHNOLOGY END ... cldlg= new ColorDialog(); cldlg.Color = pnColor.BackColor; if(cldlg.ShowDialog()==DialogResult.OK) pnColor.BackColor = cldlg.Color; } DONG NAI UNIVERSITY OF TECHNOLOGY If you want to set color by...DONG NAI UNIVERSITY OF TECHNOLOGY ColorDialog pnColor btnColor How to use ColorDialog? DONG NAI UNIVERSITY OF TECHNOLOGY private void btnColor_Click (object sender, EventArgs e) { ColorDialog cldlg=... DONG NAI UNIVERSITY OF TECHNOLOGY private void frmColorDialog_Load (object sender, EventArgs e) { trackBarBlue.Scroll += processTrackBar; trackBarGreen.Scroll += processTrackBar; trackBarRed.Scroll

Ngày đăng: 03/12/2015, 18:31

TỪ KHÓA LIÊN QUAN