Bài giảng C# 2010 - Chapter 2: Windows Form and Windows Forms Controls (Part 3)

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;

}

 

pptx20 trang | Chuyên mục: Visual C# | Chia sẻ: dkS00TYs | Lượt xem: 1931 | Lượt tải: 5download
Tóm tắt nội dung Bài giảng C# 2010 - Chapter 2: Windows Form and Windows Forms Controls (Part 3), để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level 13/05/2013 ‹#› ColorDialog How to use ColorDialog? pnColor btnColor 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; } If you want to set color by the RED, GREEN, BLUE. Please see figure below: pnColor trackBarRed txtRed trackBarBlue txtBlue trackBarGreen txtGreen For each trackbar, please set properties as the same figure 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); } Create Event or trackbar control private void processTrackBar (object sender, EventArgs e) { 	setColor(); } private void frmColorDialog_Load (object sender, EventArgs e) { trackBarBlue.Scroll += processTrackBar; trackBarGreen.Scroll += processTrackBar; trackBarRed.Scroll += processTrackBar; setColor(); } 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 Name Description LargeChange 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 FontDialog lblFont How to use FontDialog? btnFont 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; } } RichTextBox & StreamFile OpenFileDialog openDlg = new OpenFileDialog(); openDlg.Filter = "(*.txt)|*.txt|(All)|*.*"; if (openDlg.ShowDialog() == DialogResult.OK) { rtFile.LoadFile(openDlg.FileName, RichTextBoxStreamType.PlainText); } You could choose StreamType But We could use StreamFile to read Data. You should Know this 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(); } RichTextBox & StreamFile SaveFileDialog saveDlg = new SaveFileDialog(); saveDlg.Filter = "(*.txt)|*.txt|(All)|*.*"; if (saveDlg.ShowDialog() == DialogResult.OK) { rtFile.SaveFile(saveDlg.FileName,RichTextBoxStreamType.PlainText); } if (saveDlg.ShowDialog() == DialogResult.OK) { Stream stream = saveDlg.OpenFile();//Open to Write StreamWriter writer = new StreamWriter(stream); writer.WriteLine(rtFile.Text); writer.Close(); } Use StreamFile to Write Data. END 

File đính kèm:

  • pptxBài giảng C# 2010 - Chapter 2 Windows Form and Windows Forms Controls (Part 3).pptx