?
Solved

How do I repaint my ellipse...

Posted on 1998-10-14
13
Medium Priority
?
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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 600 total points
ID: 1342931
Hi,

Thanks for the points.

Cheers,
Phil.

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

741 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