2014-01-11 3 views

답변

5

하는의 InitializeComponent (후 처리기 을 연결해야합니다)와 로드 이벤트

public Form1() 
{ 
    InitializeComponent(); 
    Load += Form1_Shown; 
} 

private void Form1_Shown(Object sender, EventArgs e) 
{ 
    btnFacebookLogin.PerformClick(); 
} 
+0

입니다. 고맙습니다! SO 타이머로 인해 5 분 안에 수락 ... – PriceCheaperton

2

당신이 할 수있는 윈폼에게 C# .NET을 사용하고 있습니다 :

public void Form1_Load(object s, EventArgs e){ 
    btnFacebookLogin.PerformClick(); 
} 

을 그리고 다음 이벤트 처리기가 코드 뒤에 있어야한다고 생각해보십시오.

private void button1_Click(object sender, EventArgs e) 
    { 
     MessageBox.Show("hi"); 
    } 
+0

슬프게도이 나던 작품. 나는 심지어 MessageBox.Show ("test")를 넣는 것을 시도했다; – PriceCheaperton

+0

게시 한 것은 무엇입니까 : Form1_Shown 및 Form1_Load로 변경해야합니다. 절대적으로 작동합니다. – Karamafrooz

3

실제로 버튼을 클릭해야하는 특별한 이유가 있습니까?

나는 click 이벤트의 코드를 함수로 옮긴 다음 load 이벤트와 click 이벤트에서이 함수를 호출한다.

private void Form1_Shown(Object sender, EventArgs e) 
{ 
    DoFacebookLogin(); 
} 

private void btnFacebookLogin_Click(Object sender, EventArgs e) 
{ 
    DoFacebookLogin(); 
} 

private void DoFacebookLogin() 
{ 
    //Do Work here 
} 
+1

여기에서 유일한 좋은 대답은 –

0

@PriceCheaperton에 : 그것은 예를 들어 click()

를 호출 할 필요가 주위에 얻을 것이다 : 가장 간단한 예가 여기에있는 다른 이벤트에서 이벤트를 호출 할 수 있습니다.

C 번호 :

public partial class WebForm1 : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     Button1_Click(sender, e); 
    } 

    protected void Button1_Click(object sender, EventArgs e) 
    { 
     Response.Write("Calling event from an event..."); 
    } 
} 

ASPX :

<body> 
<form id="form1" runat="server"> 
<div> 
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> 
</div> 
</form> 

출력 : 나를 위해 enter image description here

+0

왜 Windows 양식에 대한 HTML 마크 업을 게시하고 있습니까? –

+0

@ Sergey Berezovskiy : 'PriceCheaperton'에서 언급 한 시나리오에서 구현이 동일합니다. 웹 기술에 관한 것입니다. 웹 양식에 솔루션을 게시했습니다. 그리고 C# 코드 변경없이 윈도우 폼에서도 구현할 수 있습니다. –

+1

질문에 * winforms * 태그가 붙습니다. 또한 브라우저의 스크린 샷이 어떻게 도움이되는지 이해하지 못합니다. –

관련 문제