2013-02-24 2 views
2

나는 프로그래밍 방식으로 만든 컨트롤이 Form입니다. 그 중 하나는 captcha 이미지를 표시하는 WebBrowser입니다. 그런 다음 사용자가 텍스트 상자에 보안 문자를 입력하고 양식이 잘못된 경우 새 보안 문자 이미지로 새로 고침해야합니다. 나는 다시 DisplayCaptcha()를 호출 Form.Refresh()을 시도했지만 작동하지 않았다 그래서 나는이 (간체) 코드에서처럼 그것을 해결 :WebBrowser 컨트롤 및 양식 새로 고침 또는 새로 고침

public partial class Form3 : Form 
{ 

    public Form3() 
    { 
     InitializeComponent(); 
     DisplayCaptchas(); 
    } 

    private void DisplayCaptcha() 
    { 
     string captcha = "<style>html, body{{padding:0; margin:0 }}</style>" + 
      "<img src=\"http://www.reddit.com/captcha/{0}.png\"></img>"; 


      WebBrowser webBrowserNofap = new WebBrowser(); 
      webBrowserNofap.DocumentText = String.Format(captcha, iden); 
      ......//rest of the code 


    } 


    private void button1_Click(object sender, EventArgs e) 
    { 

     if (wrongCaptcha) 
     { 
      this.Close(); 
      Form3 form3 = new Form3(); //this is how I solved the refreshing 
      form3.Show(); 
     } 
     else 
     { 
      Form4 form4 = new Form4(); 
      this.Close(); 
      form4.Show(); 
     } 
    } 
} 

그것은 작동하지만,이 실제 상쾌하지 않습니다. 나는 그때 다시 DisplayCaptcha() 컨트롤을 제거하려고 생각했지만, 어떻게 해야할지 모르겠다. 간단히 말하면, 닫기 옆에 다른 해결책이 있습니까? Form을 다시로드 하시겠습니까?

+0

WebBrowser 컨트롤에서 새로 고침 메서드를 호출 할 수 없습니다? – rene

+0

어디? DisplayCaptcha()에서 id를 호출하면; 작동하지 않습니다. – cikatomo

답변

2

이 시도 :

using System; 
using System.Windows.Forms; 

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
      webBrowser1.Navigate("about:blank"); 
      webBrowser1.Document.Write("<html><head><style>html, body{{padding:0; margin:0 }}</style></head><body><div id='divMain'>&nbsp;</div></body></html>"); 
     } 


     private void button1_Click(object sender, EventArgs e) 
     { 
      Random r = new Random(); 
      int number = 0; 
      number = r.Next(0, 999999); 
      string captcha = "<img src=\"http://www.reddit.com/captcha/{0}.png\"></img>"; 

      webBrowser1.Document.GetElementById("divMain").InnerHtml = string.Format(captcha, number); 
     } 
    } 
} 

매번 버튼을 클릭, 당신은 새로운 이미지를 얻을 것이다. 새로 고칠 곳을 넣을 수 있습니다.

+0

내 DisplayCaptchas() 메서드에서 구현하려고 할 때 공백 만 표시되지만 일반적으로 작동합니다. 나는 당신이 자바 스크립트처럼 그것을 사용할 수 있는지 몰랐다. – cikatomo