110,549
社区成员
发帖
与我相关
我的任务
分享
private void DrawControl(Control ctl, Point ptOffset, Graphics g)
{
// Cycle through each control on the form and paint
// it on the graphics object
foreach (Control c in ctl.Controls)
{
// Skip invisible controls
if (!c.Visible)
continue;
// Calculate the location offset for the control - this offset is
// relative to the original offset passed in
Point p = new Point(c.Left, c.Top);
p.Offset(ptOffset.X, ptOffset.Y);
// Draw the control
if (c is GroupBox)
DrawGroupBox((GroupBox)c, p, g);
else if (c is Button)
DrawButton((Button)c, p, g);
else if (c is TextBox)
DrawTextBox((TextBox)c, p, g);
else if (c is CheckBox)
DrawCheckBox((CheckBox)c, p, g);
else if (c is Label)
DrawLabel((Label)c, p, g);
else if (c is ComboBox)
DrawComboBox((ComboBox)c, p, g);
else if (c is RadioButton)
DrawRadioButton((RadioButton)c, p, g);
else
return;
// Draw the controls within this control
DrawControl(c, p, g);
}
}
private void DrawRadioButton(RadioButton rdo, Point p, Graphics g)
{
// Setup the size of a RadioButton
Rectangle rRadioButton = new Rectangle(p.X, p.Y, 12, 12);
ControlPaint.DrawRadioButton(g, p.X,
p.Y + (rdo.Height / 2) - (rRadioButton.Height / 2),
rRadioButton.Width,
rRadioButton.Height,
(rdo.Checked ? ButtonState.Checked : ButtonState.Normal));
// RadioButton's text left justified & centered vertically
g.DrawString(rdo.Text,
rdo.Font,
new SolidBrush(rdo.ForeColor),
rRadioButton.Right + 1,
p.Y + (rdo.Height / 2) - (g.MeasureString(rdo.Text,
rdo.Font).Height / 2));
}