10-11-2023, 03:00 AM
C# code use chatgpt:
void Main()
{
var form = new Form();
var label = new Label();
var button = new Button();
form.Text = "Test Form";
form.Controls.Add(label);
form.Controls.Add(button);
label.Text = "Hello World";
label.Width = 200; // Set the width of the label to 200
button.Text = "Confirm";
button.Width = 100; // Set the width of the button to 100
button.Location = new Point(100, 100); // Set the position of the button to x=100, y=100
button.Click += (sender, e) => {
MessageBox.Show("The Confirm button has been clicked!");
};
ApplyFontToControls(form);
form.ShowDialog();
}
void ApplyFontToControls(Control parentControl)
{
PrivateFontCollection pfc = new PrivateFontCollection();
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string fontPath = Path.Combine(desktopPath, "SourceSans3-Regular.ttf");
try
{
pfc.AddFontFile(fontPath);
}
catch (Exception ex)
{
MessageBox.Show("Error loading font file: " + ex.Message);
}
Font font = new Font(pfc.Families[0], 14);
foreach (Control control in parentControl.Controls)
{
control.Font = font;
}
}