Solved

How do I repaint my ellipse...

Posted on 1998-10-14
13
245 Views
Last Modified: 2010-04-06
I have created a form, on which I have 2 scrollbars, and
a speedbutton which opens a colorDialog!...

The 2 scrollbars is used to make an ellipse on a paintbox,
and the colorDialog is used to change the color of the
ellipse..

I have used the OnClose Event on the colorDialog, but
the color of the ellipse doesn't change immidiately..
I want it to do just that... But how???

I have tried paint, repaint, refresh, update.. Whatever..

Please help me, as I need to get this working....
I am in dire straits....!!
0
Comment
Question by:lar_jens
  • 6
  • 3
  • 3
  • +1
13 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1342919
Can you post some code that shows what is happening?
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 1342920
Hi,

You should have a private variable declared in your form of type TColor which gets set in the OnClose event of the color dialog. You should do the Invalidate, Update, Refresh or whatever here too. This will cause the OnPaint event to be called.

Then in the OnPaint event of the form you should set Canvas.Pen.Color to the TColor private variable, then draw the ellipse.

Cheers,
Phil.

0
 
LVL 1

Author Comment

by:lar_jens
ID: 1342921
Sure I can.. :)

When I push the Speedbutton, this happens :
procedure TfrmSek3.SpeedButton1Click(Sender: TObject);
begin
     if clChoice.Execute then begin                           { Opens the colorDialog }
        pntDisp.Canvas.Pen.Color := clChoice.Color;   { sets the pen color       }
     end;
end;

And when the openDialog closes:
procedure TfrmSek3.clChoiceClose(Sender: TObject);
begin
     frmSek3.Repaint;
end;

Then when I change the scrollbars!!! :
procedure TfrmSek3.ScrollBarChange(Sender: TObject);
var
   c1, c2, c3, c4 :Integer;
begin
     pntDisp.Canvas.Brush.Color := clBtnFace;
     pntDisp.Canvas.FillRect(Rect(0,0,pntDisp.Width,pntDisp.Height));
     pntDisp.Canvas.Brush.Color := pntDisp.Canvas.Pen.Color;
     c1 := Round(pntDisp.Width/2)  - Round((scrHoriz.Max-scrHoriz.Position)/2);
     c2 := Round(pntDisp.Height/2) - Round(scrVert.Position/2);
     c3 := Round(pntDisp.Width/2)  + Round((scrHoriz.Max-scrHoriz.Position)/2);
     c4 := Round(pntDisp.Height/2) + Round(scrVert.Position/2);
     pntDisp.Canvas.Ellipse(c2, c1, c4, c3);
end;




0
 
LVL 1

Author Comment

by:lar_jens
ID: 1342922
Sure I can.. :)

When I push the Speedbutton, this happens :
procedure TfrmSek3.SpeedButton1Click(Sender: TObject);
begin
     if clChoice.Execute then begin                           { Opens the colorDialog }
        pntDisp.Canvas.Pen.Color := clChoice.Color;   { sets the pen color       }
     end;
end;

And when the openDialog closes:
procedure TfrmSek3.clChoiceClose(Sender: TObject);
begin
     frmSek3.Repaint;
end;

Then when I change the scrollbars!!! :
procedure TfrmSek3.ScrollBarChange(Sender: TObject);
var
   c1, c2, c3, c4 :Integer;
begin
     pntDisp.Canvas.Brush.Color := clBtnFace;
     pntDisp.Canvas.FillRect(Rect(0,0,pntDisp.Width,pntDisp.Height));
     pntDisp.Canvas.Brush.Color := pntDisp.Canvas.Pen.Color;
     c1 := Round(pntDisp.Width/2)  - Round((scrHoriz.Max-scrHoriz.Position)/2);
     c2 := Round(pntDisp.Height/2) - Round(scrVert.Position/2);
     c3 := Round(pntDisp.Width/2)  + Round((scrHoriz.Max-scrHoriz.Position)/2);
     c4 := Round(pntDisp.Height/2) + Round(scrVert.Position/2);
     pntDisp.Canvas.Ellipse(c2, c1, c4, c3);
end;




0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1342923
Move the code from the ScrollBarChange method to a new method that ScrollBarChange calls.

eg:

procedure TfrmSek.DrawTheEllipse;

var
          c1, c2, c3, c4 :Integer;
       begin
            pntDisp.Canvas.Brush.Color := clBtnFace;
            pntDisp.Canvas.FillRect(Rect(0,0,pntDisp.Width,pntDisp.Height));
            pntDisp.Canvas.Brush.Color := pntDisp.Canvas.Pen.Color;
            c1 := Round(pntDisp.Width/2)  - Round((scrHoriz.Max-scrHoriz.Position)/2);
            c2 := Round(pntDisp.Height/2) - Round(scrVert.Position/2);
            c3 := Round(pntDisp.Width/2)  + Round((scrHoriz.Max-scrHoriz.Position)/2);
            c4 := Round(pntDisp.Height/2) + Round(scrVert.Position/2);
            pntDisp.Canvas.Ellipse(c2, c1, c4, c3);
end;

procedure TfrmSek3.ScrollBarChange(Sender: TObject);

       begin
           DrawTheEllipse;
       end;

Add a call to this method from the SpeedButton1Click method (see below)

procedure TfrmSek3.SpeedButton1Click(Sender: TObject);
       begin
            if clChoice.Execute then begin                           { Opens the colorDialog }
               pntDisp.Canvas.Pen.Color := clChoice.Color;   { sets the pen color       }
               DrawTheEllipse; // The method that draws the ellipse;
            end;
       end;

All you need to do extra is declare the DrawMyEllipse procedure in the form class and you're away!

Cheers,

Raymond.
0
 
LVL 1

Author Comment

by:lar_jens
ID: 1342924
Sure I can.. :)

When I push the Speedbutton, this happens :
procedure TfrmSek3.SpeedButton1Click(Sender: TObject);
begin
     if clChoice.Execute then begin                           { Opens the colorDialog }
        pntDisp.Canvas.Pen.Color := clChoice.Color;   { sets the pen color       }
     end;
end;

And when the openDialog closes:
procedure TfrmSek3.clChoiceClose(Sender: TObject);
begin
     frmSek3.Repaint;
end;

Then when I change the scrollbars!!! :
procedure TfrmSek3.ScrollBarChange(Sender: TObject);
var
   c1, c2, c3, c4 :Integer;
begin
     pntDisp.Canvas.Brush.Color := clBtnFace;
     pntDisp.Canvas.FillRect(Rect(0,0,pntDisp.Width,pntDisp.Height));
     pntDisp.Canvas.Brush.Color := pntDisp.Canvas.Pen.Color;
     c1 := Round(pntDisp.Width/2)  - Round((scrHoriz.Max-scrHoriz.Position)/2);
     c2 := Round(pntDisp.Height/2) - Round(scrVert.Position/2);
     c3 := Round(pntDisp.Width/2)  + Round((scrHoriz.Max-scrHoriz.Position)/2);
     c4 := Round(pntDisp.Height/2) + Round(scrVert.Position/2);
     pntDisp.Canvas.Ellipse(c2, c1, c4, c3);
end;




0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 5

Expert Comment

by:scrapdog
ID: 1342925
It appears as if the only time your ellipse gets redrawn is when you adjust the scrollbars.  You had no Paint method for the paint box, so it calling Repaint would do nothing.  You will want to repaint it when you change the scrollbars, OR when the color gets changed.  Therefore you will have to write on method for painting, and have the event handlers (for scroll bar change and color dialog close) call this method.  Change your code to look like this:

procedure TfrmSek3.SpeedButton1Click(Sender: TObject);
begin
     if clChoice.Execute then begin                           { Opens the colorDialog }
        pntDisp.Canvas.Pen.Color := clChoice.Color;   { sets the pen color       }
     end;
end;

procedure TfrmSek3.clChoiceClose(Sender: TObject);
begin
     pntDisp.Repaint;
end;

procedure TfrmSek3.ScrollBarChange(Sender: TObject);
begin
  pntDispPaint;
end;

procedure TfrmSek3.pntDispPaint(Sender: TObject);
var
   c1, c2, c3, c4 :Integer;
begin
     pntDisp.Canvas.Brush.Color := clBtnFace;
     pntDisp.Canvas.FillRect(Rect(0,0,pntDisp.Width,pntDisp.Height));
     pntDisp.Canvas.Brush.Color := pntDisp.Canvas.Pen.Color;
     c1 := Round(Width/2)  - Round((scrHoriz.Max-scrHoriz.Position)/2);
     c2 := Round(sp.Height/2) - Round(scrVert.Position/2);
     c3 := Round(pntDisp.Width/2)  + Round((scrHoriz.Max-scrHoriz.Position)/2);
     c4 := Round(pntDisp.Height/2) + Round(scrVert.Position/2);
     pntDisp.Canvas.Ellipse(c2, c1, c4, c3);
end;


pntDispPaint is the OnPaint event handler for the paintbox.  Since ScrollbarChange just calls this OnPaint event handler, you could also just set the OnChange event for the scroll bar directly to pntDispPaint if you wanted.
0
 
LVL 1

Author Comment

by:lar_jens
ID: 1342926
The comment from philipleighs, works better, since I can discard the code that clears
the canvas... So if you could please post your comment as an answer, I would be able
to give you the points...

0
 
LVL 1

Author Comment

by:lar_jens
ID: 1342927
The comment from philipleighs, works better, since I can discard the code that clears
the canvas... So if you could please post your comment as an answer, I would be able
to give you the points...

0
 
LVL 3

Expert Comment

by:philipleighs
ID: 1342928
Hi again,

Glad I could help.

You will have to reject rwilsons answer before I can post my response as an answer.

Regards,
Phil.

0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1342929
Um... Not wanting to be picky or anything, but drawing the ellipse on the form repaint will just duplicate what you are doing in the scroll bar change - it really is much nicer to wrap it up in a separet function.

But then its your question. Go ahead, make Phils day!
0
 
LVL 1

Author Comment

by:lar_jens
ID: 1342930
I'm sorry - but we all think different.. But after thinking a while (cause I don't want to be
unfair to anyone) I found that for me it is most logical to put everything that needs to be
painted inside the paint procdure.. I'm sorry..

0
 
LVL 3

Accepted Solution

by:
philipleighs earned 200 total points
ID: 1342931
Hi,

Thanks for the points.

Cheers,
Phil.

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Help to pass a value through a function 2 64
How to use Hashing sha1 in Delphi 2010 4 163
Delphi selector screen 2 58
LAN or WAN ? 11 66
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now