委託載入圖片

世紀緣發表於2016-03-02
        public ChildrenWindow()
        {
            InitializeComponent();
            MainWindow win = new MainWindow();
            win.Show();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog()==null)//開啟對話方塊
            {
             return;
            }
            picBoxShow.Image = Image.FromFile(openFileDialog1.FileName); 
            MainWindow.OnPicSaved(picBoxShow.Image);
        }


        public delegate void ShowPicture(Image image);
        public static ShowPicture OnPicSaved;
        public MainWindow()
        {
            InitializeComponent();
            OnPicSaved = ShowIt;
        }
        private void ShowIt(Image image)
        {
            this.BackgroundImage = image;
        }


相關文章