2017-03-02 6 views
0
public partial class QuestionDragAndDropList : Form 
{ 
    private List<ListQuestions> Questions = new List<ListQuestions>(); 
    private int i = 0; 


    public QuestionDragAndDropList() 
    { 
     InitializeComponent(); 
     NextQuestion(); 
    } 

    private void QuestionList() 
    { 
     Questions.Add(new ListQuestions("Question 1", new[] {//Answers}, 0)); 
     Questions.Add(new ListQuestions("Question 2", new[] {//^}, 0)); 
     Questions.Add(new ListQuestions("Question 3", new[] {//^}, 0)); 
     Questions.Add(new ListQuestions("Question 4", new[] {//^}, 0)); 
    } 

    private void NextQuestion() 
    { 

     if (i != 2) 
     { 
      lblQuestion.Text = Questions[i].GetQuestion(); 
      string[] Ans = Questions[i].GetAns(); 
      BtnA1.Text = Ans[0]; 
      BtnA2.Text = Ans[1]; 
      BtnA3.Text = Ans[2]; 
      BtnA4.Text = Ans[3]; 
     } 
     else 
     { 
      Questions[i].GetQuestion(); 
      BitMap[] Ans = Questions[i].GetAnswers(); 
     } 
    } 

    private void AnsCheck(int Answer) 
    { 
     if (Answer < Questions.Count) 
     { 
      WelcomeYear11.Userfiling.IncreaseS(); 
     } 
     i++; 
     if (i != Questions.Count) 
     { 
      NextQuestion(); 
     } 
     else 
     { 
      do something. 
     } 
    } 

    private void GrabLabel(object sender, MouseEventArgs e) 
    { 
     Label selectedLbl = (Label)sender; 
     selectedLbl.DoDragDrop(selectedLbl.Text, DragDropEffects.Copy); 
    } 
    private void AllowDragDrop(object sender, DragEventArgs e) 
    { 
     e.Effect = DragDropEffects.Copy; 
    } 

    private void PBox1DragDrop(object sender, DragEventArgs e) 
    { 
     string result = e.Data.GetData(DataFormats.Text).ToString(); 
     if (result == "9") 
     { 
      lblA1.Visible = false; 
      PboxA1.Visible = false; 
     } 
    } 

    private void PBox2DragDrop(object sender, DragEventArgs e) 
    { 
     string result = e.Data.GetData(DataFormats.Text).ToString(); 
     if (result == "30") 
     { 
      LblA2.Visible = false; 
      PBoxA2.Visible = false; 
     } 
    } 

    private void PBox3DragDrop(object sender, DragEventArgs e) 
    { 
     string result = e.Data.GetData(DataFormats.Text).ToString(); 
     if (result == "5") 
     { 
      LblA3.Visible = false; 
      PBoxA3.Visible = false; 
     } 
    } 

    private void PBox4DragDrop(object sender, DragEventArgs e) 
    { 
     string result = e.Data.GetData(DataFormats.Text).ToString(); 
     if (result == "18") 
     { 
      LblA3.Visible = false; 
      PBoxA3.Visible = false; 
     } 
    } 
} 

だから、このコードを使用して、どのようにそれだけがボタンの質問でフォームを生成するように設定してもしていないことが、私はできる午前を保存するリストを取得するにはどうすればよいまた、ドラッグ/ドロップ、チェックボックス付き、等...サンプルで使用 ListClassは次のとおりです。私は様々なスタイルIEボタン、ドラッグ&ドロップなど

class ListQuestions 
{ 

    private string Questions; 
    private Bitmap[] Answers; private string[] Ans; //First is for Picbox questions. Second is for button questions. 
    private int PosOfAns; 

    public ListQuestions(string questions, Bitmap[] answers, int posOfAns) 
    { 
     Questions = questions; 
     Answers = answers; 
     PosOfAns = posOfAns; 
    } 
    public ListQuestions(string questions, string[] ans, int posOfAns) 
    { 
     Questions = questions; 
     Ans = ans; 
     PosOfAns = posOfAns; 
    } 

    public string GetQuestion() 
    { 
     return Questions; 
    } 
    public string[] GetAns() 
    { 
     return Ans; 
    } 

    public Bitmap[] GetAnswers() 
    { 
     return Answers; 
    } 

    public int GetPosOfAns() 
    { 
     return PosOfAns; 
    } 
} 

すべてのヘルプははるかに高く評価される:)。

答えて

0

は、私は基本的にこの

using System.Collections.Generic; 

    Bitmap[] bm = { new Bitmap(1, 1) };//just had to make one to use in the ListQuestions method overload 
    List<ListQuestions> thelist = new List<ListQuestions>(); 
    thelist.Add(new ListQuestions("", bm, 1)); 

は、あなたがあなたのクラスを作成した後、あなたは次に

List<ListQuestions> thelist = new List<ListQuestions>(); 

あなたがあなたのリストを操作することができ、あなたのクラスのリストを作成し、あなたがいると思う

thelist.Add(new ListQuestions("", bm, 1)); 

あなたのクラスのプロパティはすべてprivateであるため、アクセス可能なものはありませんあなたのクラスのde。だからあなたのリスト<>にアイテムを追加した後、本当にそれらのアイテムにアクセスすることはできません。たとえば、プロパティがパブリックになるまで、これは機能しません。

string question = thelist[0].Questions; 

ここでの作業サンプル

using System.Collections.Generic; 
using System.Windows.Forms; 

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
      List<myclass> mylist = new List<myclass>(); 
      mylist = Fillmylist(mylist); 
      this.Controls.Add(mylist[0].chckbx_Recurse); 
      this.Controls.Add(mylist[0].txtbx_pwd); 
      this.Controls.Add(mylist[0].txtbx_usrname); 
     } 

     private List<myclass> Fillmylist(List<myclass> incominglist) 
     { 
      TextBox tb = new TextBox(); 
      tb.Name = "txtbx_usr"; 
      tb.SetBounds(20, 20, 50, 10); 
      TextBox tbp = new TextBox(); 
      tbp.Name = "txtbx_pwd"; 
      tbp.SetBounds(20,50, 50, 10); 
      CheckBox cb = new CheckBox(); 
      cb.Name = "chkbx_recurse"; 
      cb.SetBounds(20, 80, 20, 20); 
      incominglist.Add(new myclass { txtbx_usrname = tb, txtbx_pwd = tbp, chckbx_Recurse = cb }); 
      return incominglist; 
     } 
    } 



    class myclass 
    { 
     public TextBox txtbx_usrname { get; set; } 
     public TextBox txtbx_pwd { get; set; } 
     public CheckBox chckbx_Recurse { get; set; } 

    } 
} 
です
関連する問題