2016-03-03 46 views
0

我有以下FlowDirectionPanelhttp://prntscr.com/aao6lt你可以看到這些是撲克遊戲的成就。當你獲得新的成就時,彈出一個yes/no messageBox,並詢問你是否想要如果您按是,我可以自動導航到FlowDirectionPanel中包含的新解鎖成就,如上圖所示。另外,每個成就都包含在另一個面板中,如果您仔細觀察,可以看到它們具有一些輪廓邊框,這是FlowPanel的子面板。我動態創建並添加面板,但它們的名稱可以幫助我導航到所需的面板。這是我如何創建它們:WinForms如何顯示來自FlowDirectionPanel的特定面板

 public void PanelForAchievements(Form currentForm, FlowLayoutPanel flp, AchivementRequirements achivement) 
    { 
     FlowLayoutPanel retFlp = flp; 
     string pGetAchivementName = @"pGet" + achivement.Name; 
     string lbAchivementName = @"lb" + achivement.Name; 
     string lbAchivementRewardName = @"lb" + achivement.Name + @"Reward"; 
     string cbGetAchivementName = @"cbGet" + achivement.Name; 
     string pbAchivementName = @"pb" + achivement.Name; 
     var pGetAchivement = new Panel 
     { 
      Name = pGetAchivementName, 
      Size = new Size(retFlp.Width, 100), 
      BorderStyle = BorderStyle.FixedSingle, 
     }; 
     currentForm.Controls.Add(pGetAchivement); 

     var lbAchivement = new Label 
     { 
      Name = lbAchivementName, 
      Location = new Point(pGetAchivement.Location.X, pGetAchivement.Location.Y), 
      Size = new Size(135, 30), 
      AutoSize = false, 
      BorderStyle = BorderStyle.FixedSingle, 
      Font = new Font("Microsoft Sans Serif", 10F, FontStyle.Regular, GraphicsUnit.Point, (byte)0), 
      Text = achivement.TitleText, 
     }; 

     var lbAchivementReward = new Label 
     { 
      Name = lbAchivementRewardName, 
      AutoSize = true, 
      Top = (pGetAchivement.Height - pGetAchivement.Height)/2, 
      Text = achivement.RewardLabelText, 
      TabIndex = 2, 
      BorderStyle = BorderStyle.FixedSingle, 
      Location = new Point(lbAchivement.Location.X, lbAchivement.Location.Y + lbAchivement.Height + 5) 
     }; 

     var cbGetAchivement = new CheckBox 
     { 
      Name = cbGetAchivementName, 
      AutoCheck = false, 
      AutoSize = true, 
      Location = new Point(lbAchivement.Location.X + lbAchivement.Width + 10, lbAchivement.Location.Y), 
      TabIndex = 1, 
      UseVisualStyleBackColor = true 
     }; 
     achivement.IsUnlocked(MainPoker.AllAchievements[achivement.EnumCasted], achivement.Requirement,cbGetAchivement); 

     var pbAchivement = new PictureBox 
     { 
      BorderStyle = BorderStyle.Fixed3D, 
      Name = pbAchivementName, 
      Dock = DockStyle.Right, 
      BackgroundImageLayout = achivement.PictureBoxImageLayout, 
      //Location = new Point(pGetAchivement.Right, pGetAchivement.Location.Y), 
      Size = new Size(145, 90), 
      SizeMode = PictureBoxSizeMode.Zoom, 
      TabIndex = 9, 
      TabStop = false, 
      Image = achivement.PackPreview, 
     }; 

     pGetAchivement.Controls.Add(lbAchivement); 
     pGetAchivement.Controls.Add(lbAchivementReward); 
     pGetAchivement.Controls.Add(cbGetAchivement); 
     pGetAchivement.Controls.Add(pbAchivement); 

     retFlp.Controls.Add(pGetAchivement); 

     achivement.Title = lbAchivement; 
     achivement.RewardLabel = lbAchivementReward; 
     achivement.Unlocked = cbGetAchivement; 
     achivement.Preview = pbAchivement; 
    } 

這只是簡單的代碼,這是我如何對它們進行初始化:

public static RoyalFlush RoyalFlush = new RoyalFlush(1, new Tuple<string, int?>("Royal Card Pack", 100000)); 
    private readonly CreatePanels _createAchivementPanels = new CreatePanels(); 
    foreach (var achi in AchivementRequirements.AchivementList) 
    { 
        _createAchivementPanels.PanelForAchievements(this, pAchievementsCards, achi); 
//im also doing other stuff here.. 
//pAchivementsCards is the name of the FlowDirectionPanel 
    } 

現在的時間是/否消息框顯示我已經知道哪些成就解鎖和我的成就也有類如上所示public static RoyalFlush RoyalFlush和這些類具有屬性 - Name其中明顯包含成就名稱使用此名稱創建各自控制我創建從public static RoyalFlush RoyalFlush各自的名稱例如:

string pGetAchivementName = @"pGet" + achivement.Name; 

p代表panel,我只是使用屬性achivement.Name獲取當前成就名稱,我們最終得到了如下結果:pRoyalFlush作爲我們面板的名稱。現在我知道面板的名稱和正在解鎖的成就,我需要瀏覽我的FlowDirectionPanel並找到特定面板並將焦點留在那裏。我不知道該怎麼做,我將展示與圖片的例子我想,如果現在還不清楚現在:

  • 首先我們開啓了新的成就,我們得到的是/否MBOX:http://prnt.sc/aaodyr

  • 現在我們按下「是」按鈕,它會將我們重定向到我的新表單並向我們展示成就FlowDirectionPanel:http:/./。prntscr.com/aaofft在這裏該程序看到的是Full House的成就已完成並且應該在屏幕中間顯示它,就像這樣:http:././ prntscr.com/aaoh40

我沒有聲望發佈超過2個鏈接,所以我不得不在他們的一些點.. 這是我的第一個問題,我的母語不是英語,所以請原諒我的任何錯誤。

回答

0

您可以製作一些foreahc循環,您可以在這裏比較名稱,然後在找到所需的控件時,將您的flowlayout面板向上滾動。例如,我的FlowLayoutPanel的有4個按鈕,其中只有2個是可見的,我想滾動到將Button4:

 foreach (Control c in flowLayoutPanel1.Controls) 
     { 
      if ((c as Button).Name == "button4") 
      { 
       (c as Button).Focus(); 
       flowLayoutPanel1.ScrollControlIntoView(c); 
       break; 
      } 
     } 

希望我andrestand你的問題正確。

+0

任何想法如何在面板周圍添加邊框?我是否需要添加其他控件才能使其工作或面板具有此類屬性? – KOPEUE

+0

看看這個[鏈接](http://stackoverflow.com/questions/1852829/i-want-to-make-a-panel-have-a-thick-border-can-i-set-this-不知何故) – VDN

+0

也有任何理由你爲什麼安全鑄造而不是指定控制? – KOPEUE