User: alciro    User
 

Programación en C++ Builder

Share |
 Arrays (matrices)
 Punteros
3. Ejemplo de clase en c++
8. Métodos de la clase AnsiString
 Proyectos en C++
 Packages, distribuir una aplicación sin instalación
 Ordenación por intercambio o burbuja
 Funciones de cadenas de caracteres string.h

6. Propiedades fundamentales de los formularios

6.1. Derivadas de TcustomForm

Active

Especifica cuando el formulario tiene el foco.

__property bool Active = {read = FActive, nodefault};


If Active is true , the form has focus; if Active is false, the form does not have focus.

ActiveControl

Esta propiedad sirve para establecer qué control tiene el foco cuando se abre el formulario.

__property Controls::TWinControl* ActiveControl = {read=FActiveControl, write=SetActiveControl, stored=IsForm};


The following event handler responds to timer events by moving the active control one pixel to the right:
void __fastcall TForm1::Timer1Timer(TObject *Sender)

{
ActiveControl->Left = ActiveControl->Left + 1;
}


ActivateMDIChild

Especifica que formulario hijo MDI tiene el foco.
Cuando de consulta su valor, esta propiedad devuelve un puntero a la ventana MDI hija activa. Se trata de una propiedad de sólo lectura. Devuelve un valor NULL si no hay una ventana MDI hija activa o si la aplicación no es MDI.

__property TForm* ActiveMDIChild = {read=GetActiveMDIChild};

This code uses a button on an MDI application. When the user clicks the button, the active MDI child form is minimized.

void __fastcall TForm1::Button1Click(TObject *Sender){

  TForm* TheForm;

  TheForm = Form1->ActiveMDIChild;

  if (TheForm)
    TheForm->WindowState = wsMinimized;
}

BorderIcons

Especifica que iconos aparecen en la barra del título del formulario.

enum TBorderIcon { biSystemMenu, biMinimize, biMaximize, biHelp };
typedef Set TBorderIcons;
__property TBorderIcons BorderIcons = {read=FBorderIcons, write=SetBorderIcons, stored=IsForm, default=7}

ValueMeaning
biSystemMenuThe form has a Control menu (also known as a System menu).
biMinimizeThe form has a Minimize button
biMaximizeThe form has a Maximize button
biHelpIf BorderStyle is bsDialog or biMinimize and biMaximize are excluded, a question mark appears in the form's title bar and when clicked, the cursor changes to crHelp; otherwise,no question mark appears.

The following code removes a form’s Maximize button when the user clicks a button:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  BorderIcons = BorderIcons - (TBorderIcons()<< biMaximize);
}

 

BorderStyle

Indica qué tipo de borde debe tener el formulario
. El valor por defecto es bsSizable (que la ventana puede cambiar de tamaño).

enum TFormBorderStyle { bsNone, bsSingle, bsSizeable, bsDialog, bsToolWindow, bsSizeToolWin };
__property TFormBorderStyle BorderStyle = {read=FBorderStyle, write=SetBorderStyle, stored=IsForm, default=2};

ValorSignificado
BsDialogNo redimensionable; borde estándar de las cajas de diálogo.
BsSingleNo redimensionable; borde con una línea simple.
BsNoneNo redimensionable; línea del borde no visible.
BsSizeableBorde redimensionable estándar.
BsToolWindowIgual que bsSingle pero con el caption pequeño.
BsSizeToolWinIgual que bsSizeable pero con el caption pequeño.


Canvas

Proporciona acceso al área de cliente del formulario para dibujar.
La propiedad Camvas da acceso a la superficie del formulario para dibujar en tiempo de ejecución mapas de bits, líneas, contornos y texto. Normalmente se utiliza el componente Label para escribir texto, el componente Image para mostrar gráficos y el componente Shape para dibujar contornos o siluetas. Pero algunas veces es necesario dibujar en tiempo de ejecución. También sirve para guardar en disco la imagen del formulario.

__property Graphics::TCanvas* Canvas = {read=GetCanvas};
void __fastcall TForm1::Button1Click(TObject *Sender){
  Graphics::TBitmap *pBitmap = new Graphics::TBitmap();

  try{
    pBitmap->LoadFromFile("C:ProgramFilesBorlandCBuilderImagesSplash256colorfactory.bmp ");
    pBitmap->Transparent = true;
    pBitmap->TransparentColor = pBitmap->Canvas->Pixels[50,50];
    Form1->Canvas->Draw(0,0,pBitmap);
    pBitmap->TransparentMode = tmAuto;  
    // Transparent color now is clDefault = 0x20000000;
    Form1->Canvas->Draw(50,50,pBitmap);

  }
  catch (...)
  {
    ShowMessage("Could not load or display bitmap");
  }
  delete pBitmap;
}

The following example paints a Rectangle on the form when the user clicks on Button1.

void __fastcall TForm1::Button1Click(TObject *Sender){
    Canvas->Rectangle(0, 0, 40, 40);
}

ClientHeight

Especifica la altura (en pixels) del área del cliente (área en el interior del formulario).

__property ClientHeight = {write=SetClientHeight, stored=IsClientSizeStored};

This example reduces the height of the form's client area by half when the user clicks the button on the form:

void __fastcall TForm1::Button1Click(TObject *Sender)

{
    Form1->ClientHeight = Form1->ClientHeight/2;

}


ClientRect


Esta propiedad contiene las coordenadas de los límites superior, inferior, izquierdo y derecho del área de cliente del formulario.
Especifica las dimensiones del área del cliente.

ClientRec equivale a un rectángulo Rect(0,0,ClientWidth,ClientHeight).

__property Windows::TRect ClientRect = {read=GetClientRect};


ClientWidth


Especifica la anchura (en pixels) del área del cliente (área en el interior del formulario).

__property ClientWidth = {write=SetClientWidth, stored=IsClientSizeStored};

This example starts the form in a position scrolled so that the right hand edge shows:

void __fastcall TForm1::FormCreate(TObject *Sender)

{
/* set the width of the form window to display 300 pixels in the client area */

ClientWidth = 300;

/* now set the range to twice the client width.
This means that the form has a logical size that is twice as big as the physical window.
Note that Range must always be at least as big as ClientWidth! */

HorzScrollBar->Range = 600;

/* start the form fully scrolled */

HorzScrollBar->Position = HorzScrollBar->Range - ClientWidth;

/* clicking the scroll arrows moves the form 10 pixels */

HorzScrollBar->Increment = 10;
HorzScrollBar->Visible := true; // Show the scrollbar
}


FormStyle


Determina el estilo del formulario.

enum TFormStyle { fsNormal, fsMDIChild, fsMDIForm, fsStayOnTop };
__property TFormStyle FormStyle = {read=FFormStyle, write=SetFormStyle, stored=IsForm, default=0};

ValorSignificado
FsNormalFormulario normal (Defecto).
FsMDIChildIndicador de formulario MDI secundario.
FsMDIFormFormulario MDI principal.
FsStayOnTopEl formulario está siempre en primer plano.

This example ensures the main form of the application is an MDI parent form:

__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)
{
if(FormStyle != fsMDIForm)
FormStyle = fsMDIForm;
if(FormStyle == fsMDIForm)
Edit1->Text = "MDI form";
else
//This line never runs
Edit1->Text = "Not an MDI form";
}

HelpFile

Especifica el nombre del fichero de ayuda usado en la aplicación.

__property System::AnsiString HelpFile = {read=FHelpFile, write=FHelpFile};

Icon

Indica el icono que se puede ver en la barra de título cuando se muestra el formulario en tiempo de ejecución o minimizado. Si no se especifica nigún icono, Windows le asigna uno por defecto.

__property Graphics::TIcon* Icon = {read=FIcon, write=SetIcon, stored=IsIconStored};

This code assigns an icon to a form when the form is created:

__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
Icon->LoadFromFile("C:\\PROGRAM FILES\\BORLAND\\CBUILDER\\IMAGES\\ICONS\\EARTH.ICO");
}

KeyPreview

Especifica cuando el formulario puede recibir los eventos del teclado antes del control activo.

  • Si KeyPreview es true, los eventos del teclado ocurren en el formulario y después en el control activo.
  • Si KeyPreview es false, los eventos del teclado sólo ocurren en el control activo.
__property bool KeyPreview = {read=FKeyPreview, write=FKeyPreview, stored=IsForm, default=0};

This example changes a form's color to aqua when the user presses a key, even when a control on the form has the focus. When the user releases the key, the form returns to its original color.

TColor FormColor;
void __fastcall TForm1::FormCreate(TObject *Sender)
{
KeyPreview = true;
}


void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
FormColor = Form1->Color;
Form1->Color = clAqua;
}

void __fastcall TForm1::FormKeyUp(TObject *Sender, WORD &Key, TShiftState Shift)
{
Form1->Color = FormColor;
}


MDIChildCount

Especifica el número de formularios hijos abiertos.

__property int MDIChildCount = {read=GetMDIChildCount, nodefault};

The following code closes Form1 if there are no MDI children open:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(MDIChildCount == 0)
Close();
}

MDIChildren

Proporciona un índice para acceder a los formularios hijos de un MDI.

__property TForm* MDIChildren[int I] = {read=GetMDIChildren};

The following code closes all the MDI children of Form1.

void __fastcall TForm1::Button1Click(TObject *Sender)
{
for(int i = 0; i < MDIChildCount; i++)
MDIChildren[i]->Close();
}

Menu

La propiedad Menu se usa para cargar y activar el menú en el formulario en tiempo de ejecución. El componente TmainMenu debe estar cargado en el formulario.

__property Menus::TMainMenu* Menu = {read=FMenu, write=SetMenu, stored=IsForm};

This code displays a new menu named MyMenu when the user clicks the button.

TMenuItem *Item1;

TMainMenu *MyMenu;
//------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Item1=new TMenuItem(this);
Item1->Caption = "New item";

MyMenu = new TMainMenu(this);
MyMenu->Items->Add(Item1);

Menu = MyMenu;
}
//------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
for(int i = 0; i < MyMenu->Items->Count; i++)
MyMenu->Items[i].Remove(Item1);

delete Item1;
delete MyMenu;
}

ModalResult
ObjectMenuItem
OLE
OleFormObject
OLE
Parent
PixelsPerInch

Position

Determina el tamaño y la posición del formulario cuando se abre por primera vez.

enum TPosition { poDesigned, poDefault, poDefaultPosOnly, poDefaultSizeOnly, poScreenCenter };
__property TPosition Position = {read=FPosition, write=SetPosition, stored=IsForm, default=0};

ValorSignificado
PoDesignedMisma posición de la fase de diseño.
PoDefaultWindows establece el tamaño y la posición según el algoritmo Z-ordering.
PoDefaultPosOnlyMisma posición de la fase de diseño. Windows selecciona la posición en la pantalla.
PoDefaultSizeOnlyMisma posición de la fase de diseño. Windows selecciona el tamaño.
PoScreenCenterEl formulario se sitúa siempre en el centro de la pantalla.

PrintScale

Representa las proporciones del formulario en la impresora.

enum TPrintScale { poNone, poProportional, poPrintToFit };
__property TPrintScale PrintScale = {read=FPrintScale, write=FPrintScale, stored=IsForm, default=1}; 
ValorSignificado
PoNoneNo se aplica ninguna escala. La salida del formulario por la impresora varia entre una impresora y otra.
PoProportionalCon la opción proporcional se intenta imprimir el formulario lo más aproximado posible al aspecto que tiene en la pantalla.
PoPrintToFitAumenta o reduce el tamaño de la imagen para ajustarla a los parámetros de la impresora.

The following code maintains the proportions of the form when it is printed.

Form1->PrintScale = poProportional;

Form1->Print();

Scaled
TileMode
MDI

Visible

Indica si el formulario inicialmente es visible o no. Esta propiedad es muy útil en tiempo de ejecución, establece si un formulario es visible o no.

__property Visible = {write=SetVisible, default=0};

The following code uses two forms. Form1 has a button on it. The second form is used as a tool palette. This code makes the palette form visible, and ensures it is the top form by bringing it to the front.
To run this example, you must include Unit2.h in the Unit1 source file.

void __fastcall TForm1::ShowPaletteButtonClick(TObject *Sender)
{
if (!Form2->Visible)
{
Form2->Visible = true;
Form2->BringToFront();
}
}

 

WindowMenu

Se usa la propiedad WindowsMenu para cargar y activar el menú del formulario padre MDI en tiempo de ejecución. El componente TmainMenu debe estar cargado en el formulario.

__property Menus::TMenuItem* WindowMenu = {read=FWindowMenu, write=SetWindowMenu, stored=IsForm};


For this code to run, a menu item called MyWindows must exist on an MDI form parent form. This line of code designates the MyWindows menu to be the Window menu, the menu that lists all open child windows in an MDI application:

WindowMenu = MyWindows;

WindowState

Esta propiedad se puede consultar para determinar el estado actual del formulario (minimizado, maximizado o normal). También se puede utilizar para indicar como debe mostrarse inicialmente el formulario. Las opciones son wsMinimized, wsMaximized y wsNormal.

enum TWindowState { wsNormal, wsMinimized, wsMaximized };
__property TWindowState WindowState = {read=FWindowState, write=SetWindowState, stored=IsForm, default=0} 
ValueMeaning
WsNormalThe form appears in its normal state (that is, its non-minimized, non-maximized state).
WsMinimizedThe form appears in its minimized state.
WsMaximizedThe form appears in its maximized state.

The following code responds to the user clicking a button named Shrink by minimizing the form:

void __fastcall TForm1::ShrinkClick(TObject *Sender)
{
WindowState = wsMinimized;
}
Loading

copyright © 2007-2025  www.alciro.org  All rights reserved.         
Share |