Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > C++ Builder
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 08-06-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola DSK25.

No conozco ningun componente "linea", pero se me ocurrió un código que podes mejorar y tal vez, quíen te dice, hasta usar.

El ejemplo usa dos TPanel, pero del mismo modo podrían ser un TEdit y un TCheckBox, un TLabel y un TComboBox, etc. Asigna en ambos controles los métodos ControlMouseDown, ControlMouseMove y ControlMouseUp a los eventos correspondientes.

No realiza los quiebres de línea entre los paneles como en tu imágen, pero que los une... los une.
Unit1.h :
Código:
...
#define WM_AFTER_CREATE WM_USER + 300

class TForm1 : public TForm
{

...

private:	
  void __fastcall WMAfterCreate(TMessage &Msg);
  BEGIN_MESSAGE_MAP
    VCL_MESSAGE_HANDLER(WM_AFTER_CREATE, TMessage, WMAfterCreate);
  END_MESSAGE_MAP(TForm);
  void __fastcall GetLineEnds(TControl *C1, TControl *C2);
  void __fastcall DrawLine(TControl *C1, TControl *C2,const TColor aColor);
public:		
  __fastcall TForm1(TComponent* Owner);
};
};
Unit1.cpp:
Código:
...
#define LINECOLOR clBlue

TPoint pVec[1], pIni;
bool Moving = false;
TControl *Ctrl1, *Ctrl2;

/* PRIVATE */
void __fastcall TForm1::WMAfterCreate(TMessage &Msg)
{
  DrawLine(Ctrl1, Ctrl2, LINECOLOR);
}

void __fastcall TForm1::GetLineEnds(TControl *C1, TControl *C2)
{
  if (C1->Left + C1->Width < C2->Left) {
    pVec[0].x = C1->Left + C1->Width ;
    pVec[0].y = C1->Top  + C1->Height / 2;
    pVec[1].x = C2->Left;
    pVec[1].y = C2->Top  + C2->Height / 2;
  } else if (C2->Left + C2->Width < C1->Left){
    pVec[0].x = C2->Left + C2->Width;
    pVec[0].y = C2->Top  + C2->Height / 2;
    pVec[1].x = C1->Left;
    pVec[1].y = C1->Top  + C1->Height / 2;
  } else if (C1->Top + C1->Height > C2->Top + C2->Height) {
    pVec[0].x = C1->Left + C1->Width / 2;
    pVec[0].y = C1->Top;
    pVec[1].x = C2->Left + C2->Width / 2;
    pVec[1].y = C2->Top  + C2->Height;
  } else {
    pVec[0].x = C1->Left + C1->Width / 2;
    pVec[0].y = C1->Top  + C1->Height;
    pVec[1].x = C2->Left + C2->Width / 2;
    pVec[1].y = C2->Top;
  }
}

void __fastcall TForm1::DrawLine(TControl *C1, TControl *C2,const TColor aColor)
{
  if(C1->Left > C2->Left+C2->Width || C1->Left+C1->Width < C2->Left 
     || C1->Top > C2->Top+C2->Height ||C1->Top+C1->Height < C2->Top) {
    Canvas->Pen->Color = aColor;
    Canvas->Pen->Width = 2;
    Canvas->MoveTo(pVec[0].x, pVec[0].y);
    Canvas->LineTo(pVec[1].x, pVec[1].y);
  }
}

/* PUBLIC */
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  Ctrl1 = Panel1;  // Edit, Label, etc
  Ctrl2 = Panel2; // Idem
  Ctrl1->Hint = " Ctrl+Mouse click para arrastrar ";
  Ctrl1->ShowHint = true;
  Ctrl2->Hint = Panel1->Hint;
  Ctrl2->ShowHint = true;
  GetLineEnds(Ctrl1, Ctrl2);
  PostMessage(Handle, WM_AFTER_CREATE, 0, 0);
}

void __fastcall TForm1::ControlMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  if (Shift.Contains(ssCtrl)) {
    Moving = true;
    DrawLine(Ctrl1, Ctrl2, Color);
  }
  pIni.x = X;
  pIni.y = Y;
}

void __fastcall TForm1::ControlMouseMove(TObject *Sender, TShiftState Shift,
      int X, int Y)
{
  TControl *Ctrl = static_cast<TControl*>(Sender);
  if (Moving) {
    Ctrl->Left += X - pIni.x;
    Ctrl->Top  += Y - pIni.y;
  }
}

void __fastcall TForm1::ControlMouseUp(TObject *Sender, TMouseButton Button,
      TShiftState Shift, int X, int Y)
{
  GetLineEnds(Ctrl1,Ctrl2);
  DrawLine(Ctrl1, Ctrl2, LINECOLOR);
  Moving = false;
}
Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 08-06-2013 a las 02:02:22. Razón: ortografía
Responder Con Cita
  #2  
Antiguo 08-06-2013
DSK25 DSK25 is offline
Miembro
NULL
 
Registrado: jun 2012
Posts: 46
Poder: 0
DSK25 Va por buen camino
Gracias ecfisa, todo ok
Responder Con Cita
  #3  
Antiguo 09-06-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola DSK25.

Y ya que estamos, una idea para la miniatura.

Agregá un TPanel del tamaño que desees la miniatura, dentro de él pone un TImage y proba este código:
Código:
...

/* Ajustar propiedades de Panel2 y Image1 */
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  Panel2->BevelInner = bsNone;
  Panel2->BevelOuter = bsNone;
  Panel2->Ctl3D = false;
  Panel2->BorderStyle = bsSingle;
  Image1->Align = alClient;
  Image1->Stretch = true;
}

void WinCtrlToImage(TWinControl *aWinCtrl, TImage *aImg)
{
  Graphics::TBitmap *bm = new Graphics::TBitmap;
  HDC hDC;
  __try {
    bm->Width  = aWinCtrl->Width;
    bm->Height = aWinCtrl->Height;
    hDC = GetWindowDC(aWinCtrl->Handle);
    __try {
       BitBlt(bm->Canvas->Handle, 0, 0, bm->Width,
             bm->Height, hDC, 0, 0, SRCCOPY);
    }
    __finally {
      ReleaseDC(aWinCtrl->Handle, hDC);
    }
    aImg->Picture->Bitmap->Canvas->Draw(0, 0, bm);
    aImg->Picture->Bitmap->Assign(bm);
    aImg->Stretch = true;
  }
  __finally {
    delete bm;
  }
}
Ejemplo de uso:
Código:
void __fastcall TForm1::btnToImgClick(TObject *Sender)
{
  WinCtrlToImage(Panel1, Image1);
}
Ejemplo de salida:


Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 10-06-2013 a las 15:05:05. Razón: cambio del servidor de imagen
Responder Con Cita
  #4  
Antiguo 09-06-2013
DSK25 DSK25 is offline
Miembro
NULL
 
Registrado: jun 2012
Posts: 46
Poder: 0
DSK25 Va por buen camino
Excelente ecfisa, me funciono perfectamente, gracias
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
El programa se queda "colgado" mientras copia y luego "despierta" NeWsP OOP 5 10-03-2010 22:05:40
"OBJECT OR CLASS TYPE REQUIRED" en "APPLICATION EXENAME" Xavierator Varios 3 27-10-2008 09:09:50
Necesito llamar a métodos de clases "hija" desde su clase "padre" Flecha OOP 17 20-04-2007 00:03:53
RFID Dispositivos miniatura permiten "espiar" tus movimientos Magician^ Debates 2 07-04-2004 07:54:04
Error "Ya existe un componente con el nombre QRStandarPreview" Jose Manuel Impresión 5 13-06-2003 07:55:26


La franja horaria es GMT +2. Ahora son las 12:03:56.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi