Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Specify an external font for the control.
#1
I want to use the open-source font from the link below for the label controls in my dialog box.
https://github.com/adobe-fonts/source-sa...egular.ttf

I have created the following QM code, but it's not working.
The method used in the following code is a bit clumsy. I don't want to install the font in the system folder, I just want to use it temporarily. There should be a more suitable method.

How achieve the above functionality in QM and LA? Does anyone have sample code to provide?

Thanks in advance.
David

Macro setF
Code:
Copy      Help
str ttf="$My QM$\SourceSans3-Regular.ttf"
if(!FileExists("$fonts$\SourceSans3-Regular.ttf"))
,cop ttf "$fonts$"

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Static 0x54000000 0x0 60 40 48 12 "Text"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,__Font-- f.Create(ttf); f.SetDialogFont(hDlg "3")
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#2
C# code use chatgpt:
 
Code:
Copy      Help
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;
    }
}
#3
How to convert the above code into QM code?


Forum Jump:


Users browsing this thread: 1 Guest(s)