1

Estoy intentando hacer un Toggle Button/Toggle switch en Delphi 7 definiendo un nuevo componente heredado de TwwCheckBox pero encontré algo similar en C# y estoy traduciendo las funciones que hacen esto

Recurso: Toggle Button

    private GraphicsPath GetFigurePath()
    {
        int arcSize = Height - 1;
        Rectangle leftArc = new Rectangle(0, 0, arcSize, arcSize);
        Rectangle rightArc = new Rectangle(Width - arcSize - 2, 0, arcSize, arcSize);
        GraphicsPath path = new GraphicsPath();
        path.StartFigure();
        path.AddArc(leftArc, 90, 180);
        path.AddArc(rightArc, 270, 180);
        path.CloseFigure();
        return path;
    }

    protected override void OnPaint(PaintEventArgs pevent)
    {
        int toggleSize = Height - 5;
        pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
        pevent.Graphics.Clear(Parent.BackColor);
        if (Checked)
        {
            pevent.Graphics.FillPath(new SolidBrush(onBackColor), GetFigurePath());
            pevent.Graphics.FillEllipse(new SolidBrush(onToggleColor), new Rectangle(Width - Height + 1, 2, toggleSize, toggleSize));
        }
        else
        {
            pevent.Graphics.FillPath(new SolidBrush(offBackColor), GetFigurePath());
            pevent.Graphics.FillEllipse(new SolidBrush(offToggleColor), new Rectangle(2, 2, toggleSize, toggleSize));
        }
    }

Pero al estar traduciendo a Delphi me di cuenta que algunas clases como GraphicsPath , PaintEventArgs pevent, FillPath, SolidBrush no existen como tal en Delphi, hay variantes pero quisiera saber si hay posibilidad de hacer esto en Delphi 7?

Aquí estoy tratando de seguir el patrón que tiene c#, la razón porque la que estoy haciéndolo así es porque es la formas mas sencilla que encontré en c#

uses
   SysUtils, Classes, Controls, StdCtrls, wwcheckbox, Graphics, Variants, Forms, Dialogs, Types;

type
   TinToggleButton = class(TwwCheckBox)
   private
    { Private declarations }
     ...
     procedure SetOnBackColor(Value: TColor);
     procedure SetOnToggleColor(Value: TColor);
     procedure SetOffBackColor(Value: TColor);
     procedure SetOffToggleColor(Value: TColor);
     procedure GetFigurePath(): TCanvas;
   protected
     ...
   public
     ...
   published
     { Published declarations }
     ...
  end;

  procedure Register;

 implementation


  ...

  procedure TinToggleButton.SetOnBackColor(Value: TColor);
  ..
end;

  procedure TinToggleButton.SetOnToggleColor(Value: TColor);
  ...

    procedure TinToggleButton.SetOffBackColor(Value: TColor);
    ...

     procedure TinToggleButton.SetOffToggleColor(Value: TColor);
     ....


   ...

 procedure TinToggleButton.Paint;
 ...

 end.
1
  • No son palabras reservadas, son clases. Pertenecen al namespace System.Drawing, link a la documentación oficial. Tienes que buscar librerías equivalentes en Delphi. Si buscas 'draw in delphi 7' en google, tienes muchos recursos para empezar.
    – Arriel
    el 24 sep. 2021 a las 4:00

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.