董偉建代碼編程_第1頁
董偉建代碼編程_第2頁
董偉建代碼編程_第3頁
董偉建代碼編程_第4頁
董偉建代碼編程_第5頁
已閱讀5頁,還剩10頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、 private void button1_Click(object sender, EventArgs e) Bitmap p1 OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "ImageFiles(*.bmp,*.jpg)|*.bmp;*.jpg|所有文件|*.*" openFileDialog1.ShowDialog(); p1 = new Bitmap(openFileDialog1.FileName) pictureBox1.Image = p1; p

2、rivate void timer1_Tick(object sender, EventArgs e) textBox1.Text = DateTime.Now.ToString("h:mm:ss"); private void Form1_Load(object sender, EventArgs e) textBox1.Text = DateTime.Now.ToString("hh:mm:ss"); timer1.Enabled = true; timer1.Interval = 1000; 9-14 private void Form1_Pain

3、t(object sender, PaintEventArgs e) Graphics g= this.CreateGraphics(); HatchBrush brush=new HatchBrush (HatchStyle.Cross ,Color .Red,Color .Blue ); Font font1 = new Font("隸書",45, FontStyle.Bold | FontStyle.Italic); g.DrawString ("繪制文字!",font1,brush ,new Point (50,50); Bitmap pic=n

4、ew Bitmap ("D:第9章Chap9-14dark.jpg"); TextureBrush brush2=new TextureBrush (pic); Font font2 = new Font("姚體",50, FontStyle.Bold | FontStyle.Italic); g.DrawString("測控三班",font2,brush2 ,new PointF (70,150); 9-16 private void button1_Click(object sender, EventArgs e) Color n

5、c = new Color(); Bitmap bitmap = new Bitmap(pictureBox1.Image); Bitmap bitmap1 = new Bitmap(pictureBox1.Image); int r, g, b, avgColor; for (int i = 0; i < pictureBox2.Width ; i+) for (int j = 0; j < pictureBox2.Height ; j+) nc = bitmap.GetPixel(i, j); r = nc.R; g = nc.G; b = nc.B; avgColor = (

6、int)(r + g + b) / 3); /求顏色的平均值 if (avgColor < 0) avgColor = 0; if (avgColor > 255) avgColor = 255; Color c1 = Color.FromArgb(avgColor, avgColor, avgColor);/使用FromArgb方法把顏色的平均值賦給三種顏色,并轉(zhuǎn)換成顏色值 bitmap1.SetPixel(i, j, c1); pictureBox2.Refresh(); /刷新 pictureBox2.Image = bitmap1;/bitmap1賦給圖片框2 System

7、.Threading.Thread.Sleep(1); 10-7private void button1_Click(object sender, EventArgs e) OpenFileDialog myDlg = new OpenFileDialog(); myDlg.Filter = "所有文件*.*|*.*|文本文件*.txt|*.txt" myDlg.InitialDirectory = "D:" myDlg.FilterIndex = 1; if (myDlg.ShowDialog() = DialogResult.OK) textBox1

8、.Text = myDlg.FileName; private void button2_Click(object sender, EventArgs e) string path = textBox1.Text; if (File.Exists(path) File.Delete(path); MessageBox.Show("文件已經(jīng)成功刪除!"); else MessageBox.Show("文件不存在!"); 9-13 9-5 前兩個數(shù)改大 private void Form1_Paint(object sender, PaintEventArg

9、s e) Graphics g = this.CreateGraphics(); LinearGradientBrush brush1=new LinearGradientBrush( new Point(100,100),new Point (200,200),Color.White ,Color .Blue ); g.FillEllipse (brush1 ,300,300,150,150); GraphicsPath path=new GraphicsPath (); path.AddRectangle(new Rectangle(200, 300, 200, 200); PathGra

10、dientBrush brush2=new PathGradientBrush (path ); brush2.CenterPoint = new Point(280, 100); brush2.CenterColor = Color.Red; brush2.SurroundColors = new Color Color.Orange, Color.Gold, Color.GreenYellow ; g.FillRectangle(brush2, new Rectangle(200, 500, 160, 150); private void Form1_Load(object sender,

11、 EventArgs e) private void Form1_Paint(object sender, PaintEventArgs e) Graphics g = this.CreateGraphics(); Pen myPen = new Pen(Color.Green, 3); Rectangle rect = new Rectangle(300, 300, 200, 150); Brush myBrush = new SolidBrush(Color.Plum); g.DrawRectangle(myPen, rect); g.FillRectangle(myBrush, 600,

12、 600, 130, 90); private void Form1_Load(object sender, EventArgs e) 8-8void Button1Click(object sender, EventArgs e) comboBox1.Items.Add(textBox1.Text); /"添加100條到組合框"按鈕的單擊事件處理程序void Button3Click(object sender, EventArgs e)comboBox1.BeginUpdate(); for (int i = 0; i < 100; i+) comboBox1.I

13、tems.Add("Bucm No:" + i.ToString(); comboBox1.EndUpdate(); /"查找"按鈕的單擊事件處理程序void Button2Click(object sender, EventArgs e)int index = comboBox1.FindString(textBox2.Text); comboBox1.SelectedIndex = index; /"當(dāng)前組合框選中項"按鈕的單擊事件處理程序 private void button4_Click(object sender, Eve

14、ntArgs e) MessageBox.Show("當(dāng)前選擇項是: " +comboBox1.SelectedItem + "n" + "索引號: " + comboBox1.SelectedIndex); 8-510-1(8-4) private void button1_Click(object sender, EventArgs e) FileStream fs = new FileStream("D:file.txt", FileMode.OpenOrCreate, FileAccess.Write);

15、byte b = new byte40; char ch=new char 40; ch = this.textBox2.Text.ToCharArray();/將textBox2中的Text屬性賦給ch數(shù)組 for (int i = 0; i < ch.Length ; i+)/遍歷所有的字符 bi = (byte)chi;/把該字符數(shù)組轉(zhuǎn)換成字節(jié)數(shù)組 fs.Write(b, 0, ch.Length);/把該字節(jié)寫到文件中去 ch = this.textBox3.Text.ToCharArray(); ; for (int i = 0; i < ch.Length; i+)/遍

16、歷所有的字符 bi = (byte)chi;/把該字符數(shù)組轉(zhuǎn)換成字節(jié)數(shù)組 fs.Write(b, 0, ch.Length); ch = this.textBox4.Text.ToCharArray(); ; for (int i = 0; i < ch.Length; i+)/遍歷所有的字符 bi = (byte)chi;/把該字符數(shù)組轉(zhuǎn)換成字節(jié)數(shù)組 fs.Write(b, 0, ch.Length); fs.Flush();/刷新文件 fs.Close();/關(guān)閉文件 private void button2_Click(object sender, EventArgs e) Fil

17、eStream fs = new FileStream("D:file.txt", FileMode.OpenOrCreate, FileAccess.Read); int a = 0; string str = ""/ string ch; a = fs.ReadByte();/從文件中讀取一個字節(jié) while (a > 0) /如果不是文件的結(jié)尾 ch = (char)a).ToString();/把讀取的字節(jié)轉(zhuǎn)換為字符串型 str = str + ch;/把該字符串連接到結(jié)果字符串的末尾 a = fs.ReadByte();/再讀一個字節(jié) t

18、extBox1.Text = str; fs.Close();/關(guān)閉文件 8-6 private void SetValue() richTextBox1.Clear(); /根據(jù)復(fù)選框狀態(tài)設(shè)置RichTextBox控件中的顯示內(nèi)容 if (checkBox1.Checked = true) richTextBox1.Text = richTextBox1.Text + checkBox1.Text + " " if (checkBox2.Checked = true) richTextBox1.Text = richTextBox1.Text + checkBox2.Te

19、xt + " " if (checkBox3.Checked = true) richTextBox1.Text = richTextBox1.Text + checkBox3.Text + " " /根據(jù)單選按鈕狀態(tài)設(shè)置RichTextBox控件的字體 if (radioButton1.Checked = true) richTextBox1.Font =new Font( radioButton1.Text,richTextBox1.Font.Size); if (radioButton2.Checked = true) richTextBox1.F

20、ont = new Font(radioButton2.Text, richTextBox1.Font.Size); if (radioButton3.Checked = true) richTextBox1.Font = new Font(radioButton3.Text, richTextBox1.Font.Size); /根據(jù)單選按鈕狀態(tài)設(shè)置RichTextBox控件的前景色,即文字顏色 if(radioButton5.Checked=true) richTextBox1.ForeColor=Color.Red ; if (radioButton6.Checked = true) richTextBox1.ForeColor = Color.Green ; if (radioButton7.Checked = true) richTextBox1.ForeColor = Color.Blue; /根據(jù)單選按鈕狀態(tài)設(shè)置RichTextBox控件字號 if (radioButton9.Checked = true) richTextBox1.Font = new Font(richTextBox1.Font.FontFamily , 16); if (radioButton10.Checked = tr

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論