Welcome, Guest
Username: Password: Remember me

Super Beginner Question

Posts 1 to 6 of 6
3 months 1 week ago #7819
Hello I am moving from 20 years with VB6 to Delphi.
Trying to simply fill rect of an image control. It draws on the form not in the imageControl. Using FireMonkey.


procedure TForm1.ImageControl1MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Single);
varMyRect: TRectF;
beginMyRect := TRectF.Create(ImageControl1.Position.x , ImageControl1.Position.y , x, ImageControl1.Height);ImageControl1.Canvas.BeginScene();ImageControl1.Canvas.Fill.Color := claBlue;imagecontrol1.Canvas.Clear(claWhite);ImageControl1.Canvas.FillRect(MyRect,0, 0, [], 1.0);ImageControl1.Canvas.EndScene;end;

Last Edit: 3 months 1 week ago by WInston P35773.
Log in to reply.
  • Roger Cigol
  • Roger Cigol's Avatar
  • OFFLINE
  • Gold User
  • Rank: 33
  • Points: 85
  • Thanks 23
3 months 1 week ago #7834
Hi Winston,
Welcome to the wonderful world of Delphi. I am speaking as a C++ man here! But Embarcadero C++ Builder and Delphi are so closely related that there is a lot of cross over help around!
The Canvas that is available through ImageControl1 is the canvas on which the control draws itself. Although this seems a little counter intuitive at first it does mean your code has complete control over the rendering of the actual control.
If (as in your simple example) you just want to fill rectangles on the form client area you might just as well use the form's Canvas (no doubt you already realise this).
If you want to draw in the ImageControl using co-ordinates relative to the ImageControl you can use the function
ImageControl1.LocalToAbsolute().
Minor hitch is that this requires a TPointF parameter (ie an X,Y co-ordinate pair). But not to worry, because you can also create your TRectF from a pair of TPointF parameters, rather than the four separate integers.
Hope this helps.
You will find the Embarcadero product SO SO SO much better than Visual Basic once you get through the "new system" pain barrier.
Regards. Roger
Log in to reply.
The following user(s) said Thank You: WInston P35773
  • Roger Cigol
  • Roger Cigol's Avatar
  • OFFLINE
  • Gold User
  • Rank: 33
  • Points: 85
  • Thanks 23
3 months 6 days ago #7849
HI Winston,
One more idea, you might like to take a look at the following note by Jordi Corbilla
http://thundaxsoftware.blogspot.co.uk/2017/02/delphi-firemonkey-fmx-rendering-tcanvas.html
Regards, Roger
Log in to reply.
The following user(s) said Thank You: WInston P35773
3 months 6 days ago #7879
Ok please forgive me... But this verbosity and extra objects are driving me mad.
I have to stick to it so here is what I have tried:


procedure TForm1.ImageControl1MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Single);
varMyRect: TRectF;theBitmap: TBitmap;thePoint: TPointf;
beginself.Caption := x.ToString;
thePoint := Tpointf.Create(0,0);thePoint.X := ImageControl1.Position.X;thePoint.Y := ImageControl1.Position.Y;thePoint := ImageControl1.LocalToAbsolute(thePoint);
MyRect := TRectF.Create(thePoint);myRect.Width := x;myRect.Height := ImageControl1.Height;theBitmap := TBitMap.Create;ImageControl1.Bitmap := theBitmap;ImageControl1.Canvas.BeginScene();ImageControl1.Canvas.Fill.Color := claGreen;ImageControl1.Canvas.FillRect(MyRect,0, 0, [], 1.0);ImageControl1.Canvas.EndScene;end;



All im trying to do is paint a line where the cursor is in the ImageControl.
Log in to reply.
3 months 6 days ago #7882
I guess the the fillrect may not be exactly what I am looking for.
in VB6 to achieve a modern look in my GUI I use paintPicture for instance on an pictureBOx to represent a modern slider:
I use a graidient picture and paint in on the pictureBox dependent on the slider value.
What is the best control and method to do this in delphi
Log in to reply.
  • Roger Cigol
  • Roger Cigol's Avatar
  • OFFLINE
  • Gold User
  • Rank: 33
  • Points: 85
  • Thanks 23
3 months 4 days ago #7915
Hi Winston,
TProgressBar is the intended component for this task.
Regards, Roger
Log in to reply.
Moderators: Carlos Perez