View Full Version : سوال: لیبل در ادیت Label in Edit
  
seyed_farid
جمعه 23 خرداد 1399, 18:38 عصر
با سلام
من یه کومپوننت میخوام به شکل زیر داشته باشم.
عددهای بزرگ قابل ویرایش توسط کاربر باشه و تکست کوچک هم که عنوانش هست.
کسی از دوستان میتونه راهنمائیم کنه؟
151842
hamedjim
شنبه 24 خرداد 1399, 12:05 عصر
فقط با استفاده از کامپوننت های پیش فرض دلفی، می تونید از TPanel استفاده کنید. یک پنل در فرم قرار بدید و داخل اون دو پنل دیگه ( یکی برای عنوانو یکی هم برای مقدار) قرار بدید و سایز فونت و سایر مشخصات رو تنظیم کنید
seyed_farid
چهارشنبه 28 خرداد 1399, 13:22 عصر
سلام 
تشکر از راهنمائیتون :قلب:
اگه بخوام مقدارش رو ویرایش کنم باید با کلیک روی اون پنل یک ادیت باکس ظاهر کنم و مقدار بدم یا راه بهتری هم هست؟
یوسف زالی
پنج شنبه 29 خرداد 1399, 15:30 عصر
سلام. می تونید اقدام به نوشتن کامپوننت کنید.
اگر بلد هستید، شروع کنید و سوال های احتمالی تون رو بپرسید.
اگر نه، دوستان هستند که با صرف کمی هزینه براتون بنویسند.
seyed_farid
یک شنبه 08 تیر 1399, 19:13 عصر
اوکی.  ممنون.:قلب:
seyed_farid
دوشنبه 27 مرداد 1399, 00:00 صبح
با عرض سلام
من روی این کومپوننت کار کردم و تا یه جاهای پیش رفتم.
یه نگاه بندازید.
unit MyControls;
interface
uses
SysUtils,Classes,ExtCtrls,Controls,StdCtrls;
type
  TMyBoundEdit = class (TEdit)
   private
    { Private-Deklarationen }
     function GetLeft :Integer;
     function GetTop  :Integer;
     procedure SetLeft(const Value: Integer);
     procedure SetTop(const Value: Integer);
     procedure SetHeight(const Value: Integer);
     procedure SetWidth(const Value: Integer);
    // procedure OnExit(Sender: TObject);
  protected
    { Protected-Deklarationen }
  public
    constructor Create(AOwner: TComponent); override;
    { Public-Deklarationen }
  published
    property Top: Integer read GetTop write SetTop;
    property Left: Integer read GetLeft write SetLeft;
    { Published-Deklarationen }
end;
TMyBoundLabel = class (TLabel)
  private
    { Private-Deklarationen }
     function GetLeft :Integer;
     function GetTop  :Integer;
     procedure SetLeft(const Value: Integer);
     procedure SetTop(const Value: Integer);
  protected
    { Protected-Deklarationen }
  public
    { Public-Deklarationen }
      constructor Create(AOwner: TComponent); override;
  published
    property Top: Integer read GetTop write SetTop;
    property Left: Integer read GetLeft write SetLeft;
    { Published-Deklarationen }
  end;
TMyBoundEditLabel = class (TLabel)
  private
    { Private-Deklarationen }
     function GetLeft :Integer;
     function GetTop  :Integer;
     procedure SetLeft(const Value: Integer);
     procedure SetTop(const Value: Integer);
  protected
    { Protected-Deklarationen }
  public
    { Public-Deklarationen }
      constructor Create(AOwner: TComponent); override;
  published
    property Top: Integer read GetTop write SetTop;
    property Left: Integer read GetLeft write SetLeft;
    { Published-Deklarationen }
  end;
TMyLabelEdit = class (TWinControl)
  private
    { Private-Deklarationen }
    FMyEdit:TMyBoundEdit;
    FMyLabel:TMyBoundLabel;
    FMyEditText:TMyBoundEditLabel;
  protected
    { Protected-Deklarationen }
    procedure SetParent(AParent: TWinControl); override;
//    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
    procedure SetName(const Value: TComponentName); override;
  public
    { Public-Deklarationen }
      constructor Create(AOwner: TComponent); override;
     // destructor Destroy(AOwner: TComponent); override;
  published
      property fEdit: TMyBoundEdit read FMyEdit ;
      property fLabel: TMyBoundLabel read FMyLabel ;
      property fEditText: TMyBoundEditLabel read FMyEditText ;
    { Published-Deklarationen }
  end;
procedure Register;
implementation
procedure Register;
begin
  RegisterComponents('Farid Controls', [TMyLabelEdit]);
end;
constructor TMyBoundEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Name := 'SubEdit';  { do not localize }
  SetSubComponent(True);
  if Assigned(AOwner) then
    Text := AOwner.Name;
end;
procedure TMyBoundEdit.SetHeight(const Value: Integer);
begin
inherited height:= Value;
end;
procedure TMyBoundEdit.SetWidth(const Value: Integer);
begin
inherited width:= Value;
end;
procedure TMyBoundEdit.SetTop(const Value: Integer);
begin
inherited top:= Value ;
end;
procedure TMyBoundEdit.SetLeft(const Value: Integer);
begin
inherited left:=Value;
end;
function TMyBoundEdit.GetTop  :Integer;
begin
Result := inherited Top ;
end;
function TMyBoundEdit.GetLeft  :Integer;
begin
Result := inherited Left;
end;
{procedure TMyBoundEdit.OnExit(Sender: TObject);
begin
 //FMyEdit.Caption := MyLabelEdit1.fEdit.Text;
 // Visible := false;
end;}
constructor TMyBoundEditLabel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Name := 'EditText';  { do not localize }
  SetSubComponent(True);
  if Assigned(AOwner) then
    Caption := AOwner.Name;
end;
function TMyBoundEditLabel.GetTop  :Integer;
begin
Result := inherited Top;
end;
function TMyBoundEditLabel.GetLeft  :Integer;
begin
Result := inherited Left;
end;
procedure TMyBoundEditLabel.SetTop(const Value: Integer);
begin
inherited top:= Value ;
end;
procedure TMyBoundEditLabel.SetLeft(const Value: Integer);
begin
inherited left:=Value;
end;
constructor TMyBoundLabel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  try
   Name := 'SubLabel';  { do not localize }
  except
   Name := 'SubLabel2';
  end;
  SetSubComponent(True);
  if Assigned(AOwner) then
    Caption := AOwner.Name;
end;
function TMyBoundLabel.GetTop  :Integer;
begin
Result := inherited Top;
end;
function TMyBoundLabel.GetLeft  :Integer;
begin
Result := inherited Left;
end;
procedure TMyBoundLabel.SetTop(const Value: Integer);
begin
inherited top:= Value ;
end;
procedure TMyBoundLabel.SetLeft(const Value: Integer);
begin
inherited left:=Value;
end;
constructor TMyLabelEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  if Assigned(FMyLabel) then exit;
  FMyLabel := TMyBoundLabel.Create(Self);
  //Width := 125;
  FMyLabel.FreeNotification(Self);
  if Assigned(FMyEditText) then exit;
  FMyEditText := TMyBoundEditLabel.Create(Self);
  FMyEditText.top := 15;
  FMyEditText.font.Size := 14;
 // FMyEditText.Font.Style :=  [TFontStyle.fsBold]
  FMyEditText.Anchors := [akLeft,akBottom,akRight];
  FMyEditText.FreeNotification(Self);
  if Assigned(FMyEdit) then exit;
  FMyEdit := TMyBoundEdit.Create(Self);
  FMyEdit.Top := 15;
  FMyEdit.Visible := False;
  FMyEdit.font.Size := 14;
  //FMyEdit.Font.Style := [fsBold];
  FMyEdit.Anchors := [akLeft,akBottom,akRight];
  FMyEdit.FreeNotification(Self);
end;
{procedure TMyLabelEdit.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  if (AComponent = FMyLabel) and (Operation = opRemove) then
    FMyLabel := nil;
end;         }
procedure TMyLabelEdit.SetName(const Value: TComponentName);
begin
  if (csDesigning in ComponentState) and ((FMyLabel.GetTextLen = 0) or
     (CompareText(FMyLabel.Caption, Name) = 0)) then
    begin
      FMyLabel.Caption := Value;
      FMyEdit.Text  := Value;
      FMyEditText.Caption := Value;
    end;
  inherited SetName(Value);
end;
procedure TMyLabelEdit.SetParent(AParent: TWinControl);
begin
  inherited SetParent(AParent);
  if FMyEdit = nil then exit;
  FMyEdit.Parent := self; // AParent;
  FMyEdit.Visible := True;
  if FMyLabel = nil then exit;
  FMyLabel.Parent := self; // AParent;
  FMyLabel.Visible := True;
  if FMyEditText = nil then exit;
  FMyEditText.Parent := self; // AParent;
  FMyEditText.Visible := True;
end;
initialization
finalization
end.
==================
procedure TForm1.OnExit1(Sender: TObject);
begin
 (sender as TMyBoundEdit).Visible := False;
 (((sender as TMyBoundEdit).Parent) as TMyLabelEdit).fEditText.Caption :=
   (sender as TMyBoundEdit).text;
end;
procedure TForm1.OnDblClick1(Sender: TObject);
begin
  (((sender as TMyBoundEditLabel).Parent) as TMyLabelEdit).fEdit.Visible := True;
end;
========================
الان اگه بخوام دو بخش بعد از End. رو در رویداد OnDblClick EditText  و OnExit Edit  اضافه کنم باید چطور بنویسم؟
seyed_farid
دوشنبه 27 مرداد 1399, 00:13 صبح
موقع خروج از برنامه هم که خطا میده.
اساتید لطفا راهنمایی بفرمائید. :تشویق:
seyed_farid
جمعه 11 مهر 1399, 01:32 صبح
یادش بخیر 
قدیما هیچ سوالی تو این سایت بی جواب نمی موند. 
اما الان خیلی تغییر کرده.:افسرده::افسرده:
دلفــي
دوشنبه 14 مهر 1399, 08:40 صبح
با سلام
من یه کومپوننت میخوام به شکل زیر داشته باشم.
عددهای بزرگ قابل ویرایش توسط کاربر باشه و تکست کوچک هم که عنوانش هست.
کسی از دوستان میتونه راهنمائیم کنه؟
151842
شما می تونید با استفاده از دو کامپوننت پیش فرض دلفی این کارو به راحتی انجام بدید
به فایل ضمیمه مراجعه کنید
seyed_farid
سه شنبه 29 مهر 1399, 11:42 صبح
سلام 
ممنون از راهنماییتون.
جالب بود.
آیا راهی هم برای وسطچین کردن ادیت باکس وجود داره؟
hamedjim
سه شنبه 29 مهر 1399, 14:00 عصر
Edit1.Alignment:= taCenter
seyed_farid
سه شنبه 29 مهر 1399, 15:46 عصر
ممنونم. ولی روی ورژن 7 دلفی Alignment برای ادیت وجود ندارد. 
راه دیگهای براش نیست؟
seyed_farid
سه شنبه 29 مهر 1399, 23:38 عصر
اینطور حل شد.
میشه اینو تبدیل کنیم به یه کومپوننت که همه رو با هم داشته باشه؟    152354
 
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.