2013-06-11 22 views
-1

我創建了我自己的按鈕。不是標準的,它是一個PictureBox裏面有兩張照片。我需要一個表單中的調用方法,它會將我的圖片留下(方法已完成,並且此圖片位於表格中的pictureBox)。我試過userControl1.Click,但沒有發生任何事。單擊我的UserControl時窗體上的調用方法

我認爲它必須是pictureBox在我自己UserControl的事件,但我不知道如何調用我的形式的方法。

回答

0

打開設計器,點擊按鈕。查看描述按鈕的屬性窗口。在頂部,應該有一個閃電般的圖標。點擊它,你就可以看到按鈕的事件。你需要一個方法,將按鈕鏈接到事件。要查看涉及的代碼,請打開設計器代碼並在添加代碼後找到您的圖片框。

要查看它是否工作,請嘗試在點擊函數中添加MessageBox.Show(「Test」)。

---哎呀,這並不適用於你,但可能是有用的information--

或者,如果你想不解釋太多的一小段路,雙擊在設計師的按鈕,它應該爲你創建Click()事件。

+0

我知道有關事件和事情,但是這是不同..謝謝你的評論 – Ludva

0

試試這個:

public class YourUserControl : UserControl { 
    public YourUserControl(){ 
     InitializeComponent();    
    }   
    private void pictureBox_Click(object sender, EventArgs e){ 
     //your code for pictureBox_Click 
     OnClick(e);//This is needed if you want to register some Click event handler from ouside your UserControl. 
    } 
}  

我覺得你並不需要在這裏使用一個UserControl,只需使用一個PictureBox這樣的:

public class MyButton : PictureBox { 
    public MyButton(){ 

    } 
    // 
    protected override void OnClick(EventArgs e){ 
     //Your code here 
     //base.OnClick(e); 
    } 
} 
+0

謝謝你,但它必須是UserControl,它是作業,我的老師想要UserControl ...但好主意,謝謝你 – Ludva

相關問題