none
How to change the size of the letters in a label? RRS feed

  • Question

  • Hello:

    Following this mini videotutorial, you can now create a Windows form.

    See video 1.

    See video 2.

    How do I change the size of the letters in a label in the F # language?

    In the C # language, it is done like this.
    this.label_Mensaje.Font = new System.Drawing.Font("Microsoft Sans Serif", 36F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    How is it done in F#?

    Greetings.

    http://electronica-pic.blogspot.com

    Sunday, May 6, 2018 11:25 AM

Answers

  • Like this

    this.label_Mensaje.Font <- new System.Drawing.Font("Microsoft Sans Serif", 36F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0uy)
    • Assigning to a mutable property is done with the left-arrow
    • IDisposable types are constructed with new
    • 32-bit floats are written with f or F affix
    • Unsigned byte literals are written with the uy affix


    only without the "this." at the start
    • Marked as answer by Metaconta Friday, May 25, 2018 8:38 AM
    Monday, May 21, 2018 10:45 PM

All replies

  • Like this

    this.label_Mensaje.Font <- new System.Drawing.Font("Microsoft Sans Serif", 36F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0uy)
    • Assigning to a mutable property is done with the left-arrow
    • IDisposable types are constructed with new
    • 32-bit floats are written with f or F affix
    • Unsigned byte literals are written with the uy affix

    Sunday, May 6, 2018 3:00 PM
  • Like this

    this.label_Mensaje.Font <- new System.Drawing.Font("Microsoft Sans Serif", 36F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0uy)
    • Assigning to a mutable property is done with the left-arrow
    • IDisposable types are constructed with new
    • 32-bit floats are written with f or F affix
    • Unsigned byte literals are written with the uy affix

    Thanks for the info. It keeps giving me problems in "this".

    Error:

    The value, namespace, type or module "this" is not defined. You can choose one of the following options:
    ThisAssembly


    http://electronica-pic.blogspot.com

    Monday, May 7, 2018 12:37 AM
  • That would be whatever self-identifier you use in the member declaration, be it 'C' style

      member this.ChangeFontSize () =
        this.label_Mensaje.Font <- new System.Drawing.Font("Microsoft Sans Serif", 36F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0uy)
    or Python-like
      member self.ChangeFontSize () =
        self.label_Mensaje.Font <- new System.Drawing.Font("Microsoft Sans Serif", 36F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0uy)
    or just whatever you feel like
      member xyzzy.ChangeFontSize () =
        xyzzy.label_Mensaje.Font <- new System.Drawing.Font("Microsoft Sans Serif", 36F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0uy)


    • Edited by Mr. Tines Monday, May 7, 2018 7:56 PM
    Monday, May 7, 2018 7:56 PM
  • The keyword 'member' was not expected.

    http://electronica-pic.blogspot.com

    Monday, May 7, 2018 8:50 PM
  • open System
    open System.Text
    open System.Windows.Forms // Añadir refrencias.
    open System.Drawing // Añadir referencias.
    open System.Runtime.InteropServices
    
    // Importar librería o dll externo.
    [<DllImport("winmm.dll")>]
    extern int mciSendString(string lpstrCommand, StringBuilder lpstrReturnString,
            int uReturnLength, IntPtr hwndCallback)
    
    let rt = StringBuilder(127)
    
    // Método necesario para admitir el Diseñador. No se puede modificar
    // el contenido de este método con el editor de código.
    let form = new Form()
    let label_Mensaje = new Label()
    let groupBox_Bandeja = new GroupBox()
    let button_Abrir = new Button();
    let button_Cerrar = new Button();
    groupBox_Bandeja.SuspendLayout()
    form.SuspendLayout()
    
    // groupBox_Bandeja
    groupBox_Bandeja.Controls.Add(button_Abrir) // Añadir botones en el 
    groupBox_Bandeja.Controls.Add(button_Cerrar) // groupBox_Bandeja.
    groupBox_Bandeja.Location <- Point(22, 118)
    groupBox_Bandeja.Name <- "groupBox_Bandeja"
    groupBox_Bandeja.Size <- Size(227, 90)
    groupBox_Bandeja.TabIndex <- 0
    groupBox_Bandeja.TabStop <- false
    groupBox_Bandeja.Text <- "Bandeja:"
    
    // button_Abrir
    button_Abrir.Location <- Point(26, 39)
    button_Abrir.Name <- "button_Abrir"
    button_Abrir.Size <- Size(75, 23)
    button_Abrir.TabIndex <- 0
    button_Abrir.Text <- "&Abrir"
    button_Abrir.UseVisualStyleBackColor <- true
    
    // button_Cerrar
    button_Cerrar.Location <- Point(129, 39)
    button_Cerrar.Name <- "button_Cerrar"
    button_Cerrar.Size <- Size(75, 23)
    button_Cerrar.TabIndex <- 1
    button_Cerrar.Text <- "&Cerrar"
    button_Cerrar.UseVisualStyleBackColor <- true
    
    // label_Mensaje 
    label_Mensaje.AutoSize <- true
    //label_Mensaje.Font = new Font("Microsoft Sans Serif", 36.0, FontStyle.Bold, GraphicsUnit.Point, ((byte)(0)))
    member xyzzy.ChangeFontSize() = xyzzy.label_Mensaje.Font <- new Font("Microsoft Sans Serif", 36.0, FontStyle.Bold, GraphicsUnit.Point, 0uy)
    label_Mensaje.Location <- Point(12, 9)
    label_Mensaje.Name <- "label_Mensaje"
    label_Mensaje.Size <- Size(52, 55)
    label_Mensaje.TabIndex <- 1
    label_Mensaje.Text <- "?"
    form.Controls.Add(label_Mensaje) // Añadir en el formulario.
    
    // Crear formulario.
    let AutoScaleDimensions = new Size(6, 13)
    form.AutoScaleMode <- AutoScaleMode.Font
    form.BackColor <- Color.FromArgb(((int)(((byte)(114)))), ((int)(((byte)(54)))), ((int)(((byte)(161))))) // Color violeta.
    let ClientSize = new Size(284, 261)
    form.Controls.Add(groupBox_Bandeja) // Añadir en el formulario.
    form.Name <- "Form1"
    form.StartPosition <- FormStartPosition.CenterScreen
    form.Text <- "Visual F# 2017"
    groupBox_Bandeja.ResumeLayout(false)
    form.ResumeLayout(false)
    form.PerformLayout()
    //----------------------------------------------------------------------------------
    
    // Abrir la bandeja.
    button_Abrir.Click.Add(fun _a ->
    label_Mensaje.Text <- "Abriendo..."
    Application.DoEvents()
    mciSendString("set CDAudio door open", rt, 127, IntPtr.Zero) |> ignore
    label_Mensaje.Text <- "Abierto."
    )
    
    
    // Cerrar la bandeja.
    button_Cerrar.Click.Add(fun _c ->
    label_Mensaje.Text <- "Cerrando..."
    Application.DoEvents()
    mciSendString("set CDAudio door closed", rt, 127, IntPtr.Zero) |> ignore
    label_Mensaje.Text <- "Cerrado."
    )
    
    [<STAThread>]
    Application.Run(form)


    http://electronica-pic.blogspot.com

    Sunday, May 13, 2018 7:17 PM
  • Free form like in the above, as opposed to in an OO context, just write

    label_Mensaje.Font <- new Font("Microsoft Sans Serif", 36.0, FontStyle.Bold, GraphicsUnit.Point, 0uy)
    

    exactly like you write

    label_Mensaje.Location <- Point(12, 9)

    on the next line, which would have been

    this.label_Mensaje.Location = new Point(12, 9);
    in some initialization method in the usual style of C# OO example.

    Monday, May 14, 2018 9:21 PM
  • Hello:

    I have tried the code and the errors.



    Zoom.

    ...

    • Edited by Metaconta Thursday, May 17, 2018 3:55 PM
    Thursday, May 17, 2018 3:54 PM
  • I know nothing about F# but one look in the constructor documentation of F# on MSDN tells me that you have to use the same code as in C# following the keyword "let " and remove the semicolon. 

    https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/members/constructors


    Success
    Cor

    Sunday, May 20, 2018 10:54 AM
  • It does not carry (;).

    What fails is this code.

    label_Mensaje.Font <- new Font("Microsoft Sans Serif", 36.0, FontStyle.Bold, GraphicsUnit.Point, 0uy)

    Not.

    label_Mensaje.Font = new Font("Microsoft Sans Serif", 36.0, FontStyle.Bold, GraphicsUnit.Point, 0uy)




    http://electronica-pic.blogspot.com

    Sunday, May 20, 2018 9:07 PM
  • Like this

    this.label_Mensaje.Font <- new System.Drawing.Font("Microsoft Sans Serif", 36F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0uy)
    • Assigning to a mutable property is done with the left-arrow
    • IDisposable types are constructed with new
    • 32-bit floats are written with f or F affix
    • Unsigned byte literals are written with the uy affix


    only without the "this." at the start
    • Marked as answer by Metaconta Friday, May 25, 2018 8:38 AM
    Monday, May 21, 2018 10:45 PM
  • Hello:

    It finally works.
    label_Message.Font
     <- new System.Drawing.Font ("Microsoft Sans Serif", 36.0f, 
    System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0uy)

    Thanks a lot friend.

    http://electronica-pic.blogspot.com

    Friday, May 25, 2018 8:38 AM