線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1842
推到 Plurk!
推到 Facebook!

請教Form以及Graphics的問題?

尚未結案
marsking
一般會員


發表:6
回覆:6
積分:2
註冊:2004-06-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-06-08 04:07:23 IP:203.73.xxx.xxx 未訂閱
最近想自己做小畫家試試看~ 可是不知道為何我想用MouseMove來當作筆一樣可以畫畫 但是在picturebox或是panel上都無法作用 是否只能在Form上畫呢? 還有 請問如果只能在Form上畫的話~ 請問又如何在Form裡加Form? 又~Form怎麼載入圖片跟save影像呢? 我只會用picture開啟跟save...    順便請問一下~有自己寫過小畫家的前輩~可以建議我用啥當畫布嗎?    再請問一個問題: 如果我一個專題裡有兩個Form~ 我想讓主要的Form觸發另一個Form讓他可以跳出來讓我輸入資料 請問我該怎麼作?一直找不到該用合指令呢?    感謝前輩指教嚕~    ps抱歉~小弟好像都問了些蠢問題 發表人 -
qoo1234
版主


發表:256
回覆:1167
積分:659
註冊:2003-02-24

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-06-16 02:43:43 IP:220.131.xxx.xxx 未訂閱
Paint.NET  http://www.eecs.wsu.edu/paint.net/    or My Sample:
 
using System;
using System.Drawing;
using System.Drawing.Drawing2D; 
using System.Drawing.Imaging;
using System.Windows.Forms;
 
namespace Demo 
{
 public class MainForm : Form 
 {
  private Panel  panel1;
  private PictureBox picBox;
  private Button button1,button2;
  public MainForm() 
  {
   this.panel1 = new Panel();
   this.picBox = new PictureBox();
   this.button1 = new Button(); 
   this.button2 = new Button(); 
   
   //
   //panel1
   //     
   this.panel1.Location = new System.Drawing.Point(3, 80); 
   this.panel1.Name = "panel1"; 
   this.panel1.Size = new System.Drawing.Size(400, 380);
   this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
   this.panel1.TabIndex = 0;  
   //
   //picBox
   //   
   this.picBox.Name = "picBox"; 
   this.picBox.Dock = System.Windows.Forms.DockStyle.Fill;
   this.picBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
   this.picBox.BackColor=Color.White; 
   this.picBox.TabIndex = 0;
   this.picBox.MouseMove =new System.Windows.Forms.MouseEventHandler(this.picBox_MouseMove); 
   //
   //button1
   //
   this.button1.Location = new System.Drawing.Point(8, 8);
   this.button1.Name = "button1";
   this.button1.Size = new System.Drawing.Size(112, 48);
   this.button1.TabIndex = 1;
   this.button1.Text = "清除畫布";
   this.button1.Click  = new System.EventHandler(this.Button1_Click); 
   //
   //button2
   //
   this.button2.Location = new System.Drawing.Point(126, 8);
   this.button2.Name = "button2";
   this.button2.Size = new System.Drawing.Size(112, 48);
   this.button2.TabIndex = 2;
   this.button2.Text = "儲存";
   this.button2.Click  = new System.EventHandler(this.Button2_Click); 
   //
   //MainForm
   //   
   this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
   this.ClientSize = new System.Drawing.Size(408, 494);  
   this.Name = "MainForm";  
   this.Text = "MainForm"; 
   this.StartPosition =FormStartPosition.CenterScreen;
   this.FormBorderStyle = FormBorderStyle.FixedSingle;
   this.MaximizeBox=false; 
   this.Controls.Add(this.panel1); 
   this.Controls.Add(this.button1);
   this.Controls.Add(this.button2);
   this.panel1.Controls.Add(picBox);
   this.Load  = new System.EventHandler(this.MainForm_Load);
  }
  
  private Bitmap TmpBMP;
  private Graphics G;
  private int LstX, LstY;
  
  public void setBmpSize(int bmpWidth,int bmpHeight)
  {
   TmpBMP = new Bitmap(bmpWidth,bmpHeight,PixelFormat.Format32bppArgb);
  }
  
  private void MainForm_Load(object sender, System.EventArgs e)
  {
   setBmpSize(picBox.Width, picBox.Height);
   G = System.Drawing.Graphics.FromImage(TmpBMP);
   picBox.Image = TmpBMP; 
   
   SolidBrush Brushs = new SolidBrush(Color.Cornsilk);
   G.FillRectangle(Brushs, picBox.Left, picBox.Top, picBox.Width, picBox.Height); 
  }  
  
  private void picBox_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
  {
   Pen Pens = new Pen(Color.DarkBlue,2);
   if (e.Button == MouseButtons.Left) {
    G.DrawLine(Pens, LstX, LstY, e.X, e.Y);  
    picBox.Refresh();
   } 
    LstX = e.X;
    LstY = e.Y;  
  }  
  
  private void Button1_Click(object sender, System.EventArgs e)
  {
   G.Clear(Color.Cornsilk);
   picBox.Refresh();
  } 
  
  private void Button2_Click(object sender, System.EventArgs e)
  {
   SolidBrush B = new SolidBrush(Color.MediumPurple);
   Font F=new Font("標楷體",20F);
   G.DrawString("[Delphi K.Top討論區]",F,B, picBox.Width/2-150, picBox.Height/2 120);
   picBox.Refresh();
   TmpBMP.Save("test.jpg", ImageFormat.Jpeg);
   MessageBox.Show("儲存完成","提示");
  }    
 
  [STAThread]
  public static int Main(string[] args)
  {
     Application.Run(new MainForm());
     return 0;
  }
        
 }
}
網海無涯,唯學是岸!
系統時間:2024-05-06 7:07:57
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!