SHARE
TWEET

Victory!

a guest Jun 19th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private void AddCharityToList(Classes.Charity charity)
  2.         {
  3.             const int pboxWidth = 100, pboxHeight = 100, pboxRightMargin = 20;
  4.  
  5.             var lblName = new Label()
  6.             {
  7.                 Margin = new Padding(10),
  8.                 Dock = DockStyle.Fill,
  9.                 Text = charity.Name,
  10.                 AutoSize = true,
  11.                 MaximumSize = new Size(Width - pboxWidth - pboxRightMargin - 100, Height),
  12.                 Font = Classes.Styling.GetAppFont(20, FontStyle.Bold),
  13.                 ForeColor = AppSettings.Default.ColorDarkGray
  14.             };
  15.  
  16.             var lblDescription = new Label()
  17.             {
  18.                 Margin = new Padding(10),
  19.                 Dock = DockStyle.Fill,
  20.                 Text = charity.Description,
  21.                 AutoSize = true,
  22.                 MaximumSize = new Size(Width - pboxWidth - pboxRightMargin - 100, Height),
  23.                 Font = Classes.Styling.GetAppFont(15),
  24.                 ForeColor = AppSettings.Default.ColorDarkGray
  25.             };
  26.  
  27.             var pboxLogo = new PictureBox()
  28.             {
  29.                 Dock = DockStyle.None,
  30.                 Image = Image.FromStream(Classes.Styling.GetCharityLogoStream(charity.CharityLogoFileName)),
  31.                 Size = new Size(pboxWidth, pboxHeight),
  32.                 SizeMode = PictureBoxSizeMode.Zoom,
  33.                 Margin = new Padding(5, 5, pboxRightMargin, 5)
  34.             };
  35.  
  36.             lblDescription.Size = TextRenderer.MeasureText(lblDescription.Text, lblDescription.Font);
  37.             lblName.Size = TextRenderer.MeasureText(lblName.Text, lblName.Font);
  38.  
  39.             var textHeight = ControlHeight(lblName) + ControlHeight(lblDescription);
  40.             var pBoxHeight = ControlHeight(pboxLogo);
  41.             var height = (pBoxHeight > textHeight) ? pBoxHeight : textHeight;
  42.  
  43.             var panel = new TableLayoutPanel
  44.             {
  45.                 Margin = new Padding(20),
  46.                 AutoSize = true,
  47.                 AutoSizeMode = AutoSizeMode.GrowAndShrink,
  48.                 RowCount = 2,
  49.                 ColumnCount = 2
  50.             };
  51.  
  52.             panel.Controls.AddRange(new Control[] { pboxLogo, lblName, lblDescription });
  53.  
  54.             panel.SetCellPosition(pboxLogo, new TableLayoutPanelCellPosition(0, 0));
  55.             panel.SetRowSpan(pboxLogo, 2);
  56.  
  57.             panel.SetCellPosition(lblName, new TableLayoutPanelCellPosition(1, 0));
  58.             panel.SetCellPosition(lblDescription, new TableLayoutPanelCellPosition(1, 1));
  59.  
  60.             charityListPanel.Controls.Add(panel);
  61.         }
RAW Paste Data
Top