Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void AddCharityToList(Classes.Charity charity)
- {
- const int pboxWidth = 100, pboxHeight = 100, pboxRightMargin = 20;
- var lblName = new Label()
- {
- Margin = new Padding(10),
- Dock = DockStyle.Fill,
- Text = charity.Name,
- AutoSize = true,
- MaximumSize = new Size(Width - pboxWidth - pboxRightMargin - 100, Height),
- Font = Classes.Styling.GetAppFont(20, FontStyle.Bold),
- ForeColor = AppSettings.Default.ColorDarkGray
- };
- var lblDescription = new Label()
- {
- Margin = new Padding(10),
- Dock = DockStyle.Fill,
- Text = charity.Description,
- AutoSize = true,
- MaximumSize = new Size(Width - pboxWidth - pboxRightMargin - 100, Height),
- Font = Classes.Styling.GetAppFont(15),
- ForeColor = AppSettings.Default.ColorDarkGray
- };
- var pboxLogo = new PictureBox()
- {
- Dock = DockStyle.None,
- Image = Image.FromStream(Classes.Styling.GetCharityLogoStream(charity.CharityLogoFileName)),
- Size = new Size(pboxWidth, pboxHeight),
- SizeMode = PictureBoxSizeMode.Zoom,
- Margin = new Padding(5, 5, pboxRightMargin, 5)
- };
- lblDescription.Size = TextRenderer.MeasureText(lblDescription.Text, lblDescription.Font);
- lblName.Size = TextRenderer.MeasureText(lblName.Text, lblName.Font);
- var textHeight = ControlHeight(lblName) + ControlHeight(lblDescription);
- var pBoxHeight = ControlHeight(pboxLogo);
- var height = (pBoxHeight > textHeight) ? pBoxHeight : textHeight;
- var panel = new TableLayoutPanel
- {
- Margin = new Padding(20),
- AutoSize = true,
- AutoSizeMode = AutoSizeMode.GrowAndShrink,
- RowCount = 2,
- ColumnCount = 2
- };
- panel.Controls.AddRange(new Control[] { pboxLogo, lblName, lblDescription });
- panel.SetCellPosition(pboxLogo, new TableLayoutPanelCellPosition(0, 0));
- panel.SetRowSpan(pboxLogo, 2);
- panel.SetCellPosition(lblName, new TableLayoutPanelCellPosition(1, 0));
- panel.SetCellPosition(lblDescription, new TableLayoutPanelCellPosition(1, 1));
- charityListPanel.Controls.Add(panel);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement