alasoft Posted May 16, 2013 Posted May 16, 2013 Pardon my ignorance .. :-) But if I create a TUniLabel at runtime over a TUniForm like this: TMyForm.OnCreate(Sender: TObject); var oMyLabel: TUniLabel; begin oMyLabel:=TUniLabel.Create(Self); with oMyLabel do begin Parent:=Self; Caption:='Hi World; Top:=10; Left:=10; AutoSize:=True; end; end; The control displasy fine .. but, while the Height property was setted .. that does not happen with the Width property, wich remains in 0 (zero) I need to 'calculate' somehow the width - in pixels - of that label created like the sample, in runtime, depending on the Caption property. Help !! :-) Thanks Rober Quote
soledue Posted May 17, 2013 Posted May 17, 2013 you can use the event "resize" of the label resize( this, width, height, oldWidth, oldHeight, eOpts ) Quote
Sherzod Posted May 17, 2013 Posted May 17, 2013 Hi Roberto.Try, can will help you... type TMyForm = class (TUniForm) ...... ...... procedure MyAjaxEvent (Sender: TComponent; EventName: string; Params: TStrings); ...... TMyForm.MyAjaxEvent procedure (Sender: TComponent; EventName: string; Params: TStrings); begin if EventName = 'myAjaxEvent' then begin (Sender as TUniLabel). Width: = StrToInt (Params.Values ['Width']); end; end; procedure TMyForm.UniFormCreate (Sender: TObject); var oMyLabel: TUniLabel; begin oMyLabel := TUniLabel.Create (Self); with oMyLabel do begin Parent := Self; Name := 'XoMyLabel'; OnAjaxEvent := MyAjaxEvent; oMyLabel.ClientEvents.Enabled := True; oMyLabel.ClientEvents.ExtEvents.Values ['onresize'] := 'function (sender, adjWidth, adjHeight, rawWidth, rawHeight) {ajaxRequest (MyForm.XoMyLabel,'' myAjaxEvent'', ['' Width ='' + adjWidth] )}'; AutoSize := True; oMyLabel.Caption := 'Hi World!'; Top := 10; Left := 10; end; // Right here to get the value of width can not succeed ... end; procedure TMyForm.UniButton1Click (Sender: TObject); begin ShowMessage (IntToStr ((Self.FindComponent ('XoMyLabel') as TUniLabel). Width)); end; Sincerely Quote
alasoft Posted May 17, 2013 Author Posted May 17, 2013 Thanks a lot both of you ! .. I will try your samples assp. I'm in fault with some .. 'conceptual understanding' of those 'ajax + js events' .. it seems that not 'everything' is solved within Delphi in this wonderful framewor - I mean UniGUI, of course - Greetings Rober Quote
soledue Posted May 17, 2013 Posted May 17, 2013 se hai bisogno d'aiuto mandami un messaggio privato Quote
Administrators Farshad Mohajeri Posted May 17, 2013 Administrators Posted May 17, 2013 Pardon my ignorance .. :-) But if I create a TUniLabel at runtime over a TUniForm like this: TMyForm.OnCreate(Sender: TObject); var oMyLabel: TUniLabel; begin oMyLabel:=TUniLabel.Create(Self); with oMyLabel do begin Parent:=Self; Caption:='Hi World; Top:=10; Left:=10; AutoSize:=True; end; end; The control displasy fine .. but, while the Height property was setted .. that does not happen with the Width property, wich remains in 0 (zero) I need to 'calculate' somehow the width - in pixels - of that label created like the sample, in runtime, depending on the Caption property. Help !! :-) Thanks Rober Why do you need to access width in the first place? Width is automatically managed in web side. Quote
eduardoA Posted March 6, 2016 Posted March 6, 2016 Because sometimes we need to put a label inside a panel and we need to set the width of that panel with an image width plus label width, but we can't use AutoSize of UniPanel because you removed it in UniGUI project . Quote
eduardoA Posted March 10, 2016 Posted March 10, 2016 Hi Friends, I too need to change my controls width a lot, and a automatic solution would be very nice. We understand that sometimes we want to make better looking screens, so the controls must respond better to user commands and to run-time changes we made in the code. I found a way that is working very well to me. After you made any change that requires other controls to rearrange themselves, just put the code above: Self.With := Self.With +1; Self.With := Self.With -1; Refresh; Example of use: we put 2 panels and a splitter between then. They move fine, but if we have other controls inside those panels, and those controls are aligned with right, left or client, they won't resize unless you use the code I just mention. Farshad Mohajeri did a great job with his framework, but he can't understand that simple issue is real. Quote
eduardoA Posted March 21, 2016 Posted March 21, 2016 function TPaginaPrincipal.TextWidth(s: TUniLabel): Integer; var c: TBitmap; f: TFont; begin { uma forma de calcular o tamanho de um texto na janela se o canvas não atualiza via ajax } c := TBitmap.Create; f := TFont.Create; Result := 8 * Length(s.Caption); f.Height := s.Font.Height; f.Size := s.Font.Size; f.Name := s.Font.Name; f.Style := s.Font.Style; try c.Canvas.Font.Assign(f); Result := c.Canvas.TextWidth(s.Caption); finally c.Free; end; end; Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.