Question

Bug in TPanel - border doesn't get repainted when TPanel repaints

Asked by: rfwoolf

Using Delphi BDS 2006, if I have a TPanel on a form, with BorderStyle =  BsSingle, and BorderWidth = 1,
if you paint on the form's canvas and paint something over this border,
and then I call Panel1.repaint and Form1.repaint;
everything is redrawn except for the border.

To redraw the border, I have to say:
  Panel1.BorderStyle := bsNone;
  Panel1.BorderStyle := bsSingle;
(the reason this works is because this calls panel1.RecreateWnd which "destroys the underlying windows object" and recreates it. You cannot however call panel1.RecreateWnd directly because it is private);

Another solution seems to be:
How can I repaint this border properly?

Attached are more detailed instructions on how to recreate the problem...

On a form, place a TPanel.
Set its Left to 50;
Set its Top to 50;
Set its BorderStyle = bsSingle
Set BorderWidth to 1 // (this doesn't actually matter, it can also be 0).
 
//Paint onto the forms canvas by putting a TButton with this OnClick event:
 
procedure TForm1.Button1Click(Sender: TObject);
var
  C : TCanvas;
  MyHDC : HDC;
begin
  C := TCanvas.Create;
  with C do
  try
    MyHDC := GetWindowDC(self.handle);
      try
        Handle := MyHDC;
        Brush.Style := bsSolid;
        Pen.Width := 8;
        Rectangle(Rect(10,10,100,100));
      finally
        ReleaseDC(self.handle, MyHDC);
    end;
  finally
    Free;
  end;
//NOW REPAINT THE PANEL
  Panel1.Repaint;
//NOW REPAINT THE FORM
  self.repaint;
end;
 
 
//THE SOLUTION:
  panel1.BorderStyle := bsNone;
  panel1.BorderStyle := bsSingle;
                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-05-07 at 11:59:46ID24390161
Tags

delphi

,

bug

,

border repaint

,

tpanel

Topics

Delphi Programming

,

Delphi Curiosities

,

Graphics and Delphi Programming

Participating Experts
2
Points
500
Comments
34

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Painting on TPanel
    A program I'm working on needs the TPanel painted with a tiled image. I know I can add an TImage to it set to client, but is there a way to paint directly on to the TPanel surface. If so an Example Please on how this is done.
  2. canvas repaint
    I have an applet with a class "Square" that extends canvas. Below is an example of my code : private Square square; private TextArea textarea; public void init () { textarea = new TextArea(); square = new Square(); } ..... //other codes ..... public...
  3. Do not Repaint !  :-)
    D4, W98, Paradox Hello all, How could i tell Windows do not repaint a componant until I want ? I am creating a TCalendar component My component's ancestor is TPanel and had 350 TButons on it. Buttons size and height are proportionals to TCalendar's ones one. But when 1 ...
  4. repaint in a canvas
    hi expertts! i wrote a class that extends canvas. in that class i have a paint method for drawing some images ans strings. the problem is that the method isn't entered into. even when i call repaint(), and there for my images and strings are not displayed (obviously...). do...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: EddieShipmanPosted on 2009-05-07 at 15:35:24ID: 24331378

Why not exclude the border from your painting area, then you don't have to worry about having to repaint it.

 

by: rfwoolfPosted on 2009-05-07 at 15:44:09ID: 24331453

Thanks for the suggestion Eddie, however, 1) aesthetically I do want to paint over the border, and 2) I'm not really looking for that kind of workaround here.

Yaknow, what should have been a simple procedure of painting a rectangle around a button, has turned into a mammoth scope problem: compensating for the form's titlebar size and borders, then not being able to repaint the panel borders. This has cost me now hours and hours of time.

Now I'm moving on to using a transparent panel with a TShape on it as the rectangle but so far can't get it to work.

If this is a bug in TPanel, it should be reported, and if it already has, there should be a proper workaround / fix.

I'm also thinking about simply saving the canvas of the form, then drawing the rectangle and then (later) restoring the canvas of the form instead of repainting it. Do you know how to do this? If so I will open a new question for you :)

Cheers

 

by: HypoPosted on 2009-05-07 at 16:04:11ID: 24331686

Hi, You can acheive the same thing as RecreateWnd does with the following line:
  Panel1.Perform(CM_RECREATEWND, 0, 0);

try adding that line after your Panel1.Repaint.

regards
Hypo

 

by: HypoPosted on 2009-05-07 at 16:08:05ID: 24331708

However, it seems more pretty to execute CM_BORDERCHANGE instead... then you don't have to worry about all the things that RECREATEWND might do... :D

So, try adding this line after your Panel1.Repaint instead. And the border will be repainted.
  Panel1.Perform(CM_BORDERCHANGED, 0, 0);

regards
Hypo

 

by: rfwoolfPosted on 2009-05-07 at 16:13:36ID: 24331733

Hi Hypo.

I also saw got to CM_RECREATEWND by digging deeper in the vcl units.
While it did solve the problem, it was very clunky - there's a major flicker for me because all my controls have to be redrawn.
However I did not get to CM_BORDERCHANGED - your apparent knowledge of the Windows API is useful here.

Thank you very much, I'm happy to accept CM_BORDERCHANGED as the solution, but will keep the question open for a while longer for other comments.
Thanks again!

 

by: EddieShipmanPosted on 2009-05-07 at 19:31:58ID: 24332622

rfwoolf,
I don't understand why you are going to such trouble to paint controls with a border when
they are active.

That has been done tons of times and I even have some code done by a friend that does
it. There are several free w/source controls on Torry's that do it, so why don't you download one of those and learn how they do it instead of breaking your head on this problem?

 

by: rfwoolfPosted on 2009-05-07 at 19:50:17ID: 24332687

Eddie:
I am not trying to border active controls.
I am doing something different.
On the form there are groups of buttons (let's call it Group A) and somewhere else a button (let's call it Button A). If the user hovers over Button A, I want a border to be drawn around all of Group A. And visa verse.
Notice that I said AROUND. This means the border is drawn outside of the control.
To make matters worse, most of these controls are tightly packed on panels within panels - so for example I could have drawn on the canvas of a panel - now I have to draw on the canvas of a button's parents' parent's parent - or to make it simple - I want to draw on the form itself.

I have finally succeeded, but to now 'clear' the borders I have to repaint the entire form and all its controls which causes a big flicker.
So I changed direction again and am now trying a transparent panel - which worked great in tests but now that I'm implementing it, it's not working :(
So now I'm going to change directions AGAIN and do the painting thing.
I like the painting thing but the 'undoing' (repainting) is causing problems :(

 

by: rfwoolfPosted on 2009-05-07 at 19:51:29ID: 24332692

"I want to draw on the form itself." - I meant to say "I want to draw on the form's canvas"  (which would draw over everything else including buttons, panels and all its children)

 

by: rfwoolfPosted on 2009-05-07 at 20:45:25ID: 24332899

LOL...
In the beginning my problem was that TShape is not a TWinControl, and according to the help files even if you say BringToFront it will not stay on top of other TWinControl's such as TButton's or TEdit's.
So my solution was to put TShape on a transparent TPanel, and have TPanel brought to front.
Well this worked as expected, with anything I putting on the panel working correctly, except for TShape, again, doesn't show up in front of TButton's etc.
But what IS working no my transparent TPanel is ....
other TPanels.

So the solution, I think, is to use 4 x TPanels, black, thin, to make boxes around my components, and bring them all to the front.
-No transparent Tpanels
-No TShapes
-No drawing on the form's canvas.

Let's hope it works!!!

 

by: rfwoolfPosted on 2009-05-07 at 21:06:46ID: 24332971

Yes!!! It seems to be working, thank heavens.
I can finally put this chapter to bed I think.
It is still a pitty that I wasn't able to do it the other ways - it's nice to be able to do things in more than one way. At least I learnt one or two things in the process and I'm sure I will be using this information in the near future when I write components.

 

by: EddieShipmanPosted on 2009-05-08 at 04:30:06ID: 24334967

Did yuo want colored borders? It seems that you are doing things the hard way as it is and now that you have made it a little clearer what you want, we can help better.

 

by: rfwoolfPosted on 2009-05-08 at 05:45:46ID: 24335424

Um, just black border is fine - but thick, about 3 pixels in diameter. Solid line. The only problem with using TPanels is you can't make rectangles with rounded corners or circles - but that's fine - I never really intended to do so.

 

by: EddieShipmanPosted on 2009-05-08 at 06:10:56ID: 24335641

Why couldn't you draw a rectangle on the form's canvas with a transparent center that allowed everything else to show through? Can you post a screenshot of what you want?

 

by: rfwoolfPosted on 2009-05-08 at 06:15:24ID: 24335673

"Why couldn't you draw a rectangle on the form's canvas with a transparent center that allowed everything else to show through?"
I did. Then the problem became removing the rectangle - the border of a TPanel would not redraw - hence I posted this question. Hypo posted a solution that passes a message to redraw the border.
Now the problem is the redrawing of everything on the form (to remove the rectangle I drew) is causing a nasty flicker, so I have now opened another question that asks if maybe we can cache the form's canvas, draw the rectangle, and then restore the cache? That way there probably won't be any flicker.
Do you understand?

As a complete alternative, if I use TPanels to construct a rectangle, and simply hide them, then there won't be any flicker :D

 

by: EddieShipmanPosted on 2009-05-08 at 06:20:01ID: 24335713

I'm such a visual person, I guess I'd have to see it, sorry I don't really understand, yrt.

 

by: rfwoolfPosted on 2009-05-08 at 06:41:47ID: 24335910

Eddie I hope you're not joking just to embaress me. Attached is an example

 

by: EddieShipmanPosted on 2009-05-08 at 08:56:51ID: 24337370

Try something like this to avoid all the repaints problems:

procedure DrawBorder(ATag:Integer; ADraw: Boolean);
var
  Rect: TRect;
  fcolor: TColor;
begin
  case ATag of
  0:
    begin
      // draw border around big button
      Rect := Form1.BitBtn3.BoundsRect;
      InflateRect(rect, 2, 2);
      if ADraw then
        fColor := clBlack
      else
        fColor := Form1.Color;
      Frame3d(Form1.Canvas, Rect, fColor, fColor, 2);
    end;
  1:
    begin
      Rect.TopLeft := Form1.BitBtn1.BoundsRect.TopLeft;
      Rect.BottomRight := Form1.BitBtn2.BoundsRect.BottomRight;
      InflateRect(rect, 2, 2);
      if ADraw then
        fColor := clBlack
      else
        fColor := Form1.Color;
      Frame3d(Form1.Canvas, Rect, fColor, fColor, 2);
    end;
  end; // case
end;
 
procedure TBitBtn.CMMouseEnter(var Message: TMessage);
begin
  inherited;
  if not FMouseInControl and Enabled and (GetCapture = 0) then
  begin
    FMouseInControl := True;
    DrawBorder(TControl(Self).Tag, FMouseInControl);
    Repaint;
  end;
end;
 
procedure TBitBtn.CMMouseLeave(var Message: TMessage);
begin
  inherited;
  if FMouseInControl and Enabled then
  begin
    FMouseInControl := False;
    DrawBorder(TControl(Self).Tag, FMouseInControl);
    Invalidate;
  end;
end;
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:

Select allOpen in new window

 

by: EddieShipmanPosted on 2009-05-08 at 08:57:14ID: 24337379

Try this post instead. I forgot the rest of the code:

unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, Buttons;
 
type
  TBitBtn = class(Buttons.TBitBtn)
  private
    FMouseInControl: Boolean;
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  end;
 
  TForm1 = class(TForm)
    BitBtn3: TBitBtn;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Bevel1: TBevel;
  private
    { Private declarations }
    FborderColor: TColor;
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
{ TBitBtn }
 
procedure DrawBorder(ATag:Integer; ADraw: Boolean);
var
  Rect: TRect;
  fcolor: TColor;
begin
  case ATag of
  0:
    begin
      // draw border around big button
      Rect := Form1.BitBtn3.BoundsRect;
      InflateRect(rect, 2, 2);
      if ADraw then
        fColor := clBlack
      else
        fColor := Form1.Color;
      Frame3d(Form1.Canvas, Rect, fColor, fColor, 2);
    end;
  1:
    begin
      Rect.TopLeft := Form1.BitBtn1.BoundsRect.TopLeft;
      Rect.BottomRight := Form1.BitBtn2.BoundsRect.BottomRight;
      InflateRect(rect, 2, 2);
      if ADraw then
        fColor := clBlack
      else
        fColor := Form1.Color;
      Frame3d(Form1.Canvas, Rect, fColor, fColor, 2);
    end;
  end; // case
end;
 
procedure TBitBtn.CMMouseEnter(var Message: TMessage);
begin
  inherited;
  if not FMouseInControl and Enabled and (GetCapture = 0) then
  begin
    FMouseInControl := True;
    DrawBorder(TControl(Self).Tag, FMouseInControl);
    Repaint;
  end;
end;
 
procedure TBitBtn.CMMouseLeave(var Message: TMessage);
begin
  inherited;
  if FMouseInControl and Enabled then
  begin
    FMouseInControl := False;
    DrawBorder(TControl(Self).Tag, FMouseInControl);
    Invalidate;
  end;
end;
 
end.
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:

Select allOpen in new window

 

by: rfwoolfPosted on 2009-05-08 at 09:10:04ID: 24337508

It's looking good Eddie!
I have to rush out but I'll be back shortly to test it further.

 

by: rfwoolfPosted on 2009-05-08 at 13:39:44ID: 24340021

Hi Eddie

It doesn't work if the BitBtn  is on a panel because when you are using Frame3d to draw the rect, you use the form's canvas and it will draw on the form only, and not on its children :(

 

by: rfwoolfPosted on 2009-05-08 at 13:40:09ID: 24340028

Thank you for trying anyway.  I do appreciate it.

 

by: EddieShipmanPosted on 2009-05-09 at 07:45:06ID: 24344019

Then you don't need the panels, correct? otherwise, call it with the panel's canvas. It is protected, so you do know how to access it, correct?

 

by: rfwoolfPosted on 2009-05-09 at 07:49:40ID: 24344042

Eddie: If the TBitBin is on the EDGE of a panel, then if you use the form's canvas you will get the border on the form but not on the panel, and if you use the panel's canvas it won't appear on the form.
Try it yourself if you don't understand:
Put a TPanel on your form, set Left to 100, Top to 100, Width to 200, Height to 200.
Please a TBitBin on your TPanel. Set it's Left to 0, Top to 0, Width to 100, Height to 100.

Now if you use the Form's canvas you can see it won't appear on the TPanel.
If you use the TPanel's canvas, some of the frame will get cut off because it's not being drawn on the form's canvas. :p

 

by: EddieShipmanPosted on 2009-05-09 at 07:53:00ID: 24344057

Make this change and all will be well.

type TMyPanel = class(TPanel);
 
procedure DrawBorder(ATag:Integer; ADraw: Boolean);
var
  Rect: TRect;
  fColor: TColor;
begin
  case ATag of
  0:
    begin
      // draw border around big button
      Rect := Form1.BitBtn3.BoundsRect;
      InflateRect(rect, 2, 2);
      if ADraw then
        fColor := clBlack
      else
        fColor := Form1.Color;
      Frame3d(TMyPanel(Form1.BitBtn3.Parent).Canvas, Rect, fColor, fColor, 2);
    end;
  1:
    begin
      Rect.TopLeft := Form1.BitBtn1.BoundsRect.TopLeft;
      Rect.BottomRight := Form1.BitBtn2.BoundsRect.BottomRight;
      InflateRect(rect, 2, 2);
      if ADraw then
        fColor := clBlack
      else
        fColor := Form1.Color;
      Frame3d(TMyPanel(Form1.BitBtn2.Parent).Canvas, Rect, fColor, fColor, 2);
    end;
  end; // case
end;

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:

Select allOpen in new window

 

by: EddieShipmanPosted on 2009-05-09 at 09:05:44ID: 24344382

[quote]If the TBitBin is on the EDGE of a panel...[/quote]
Then I guess you are going to have to make some adjustments ;-)

I would suggest making the panel that contains the buttons be 4 pixels bigger than the buttons in both height and width. If you set both bevel's to bvNone, it will still do what you want.

 

by: rfwoolfPosted on 2009-05-09 at 13:02:01ID: 24345403

Hi Eddie. I was just trying out your solution now, and yes it still won't work because a) the TBitBtn is on the edge of a panel, b) there are other objects next to the TBitBtn such as other TBItBtns and some images
I hope at least you now understand the problem. I do appreciate your sagely attention though, but I don't expect you to solve it. I am going with using TPanel's to make a rectangle border and saying TPanel.BringToFront and TPanel.hide / show.
I have also found some transparent panels, but could not get them to work for this, but, I was able to using transparent panels to 'dim' (darken) regions of my form and menus (I am using a combonation of rectangles and dimmed regions to highlight to the user the section of the form he is interacting with) :)
Have a good weekend. P

 

by: EddieShipmanPosted on 2009-05-09 at 19:37:48ID: 24346611

Is there any reason you can't post your DFM so I can actually see what the form looks like exactly? I can reconstruct it and work with it.

 

by: EddieShipmanPosted on 2009-05-12 at 08:30:18ID: 24365730

You still there? Can you post your DFM?

 

by: EddieShipmanPosted on 2009-05-20 at 12:01:14ID: 24435163

so, you gonna post your DFM or what?

 

by: rfwoolfPosted on 2009-05-21 at 11:45:52ID: 24444592

Hey Eddie
I've just started a full time job, so I'm very tired right now and pressed for time, so won't be able to show you the DFM - I did find a solution with TPanel's though. Also you should be able to find this problem yourself if you play around enough.
Basically I have a form, centered on the form is a panel1 let's say 600 x 400px. At the top of this panel is  a panel2 let's say 600 x 100px and aligned to top. On Panel2 are 6 buttons, each 100 x 100px - I think they are TBitBtns actually.

Now try to draw a black border around one of the TBitBtns. Which canvas shall you use?
You cannot use the TBItBtn canvas because the black border is on the OUTSIDE of the buttons.
You cannot use the TPanel2's canvas because in this case the black border is also OUTSIDE of the TPanel2.
You cannot use the canvas of TPanel1 because also some of the border is OUTSIDE of this TPanel1.
So you use the canvas of the window

Problems:
1) The canvas of the window starts from the title bar. So just for example if my button was 100 left, 100 top, and I paint a border there on the window canvas, it will not be accurate because you have to add the height of the title bar, and also you have to add the width of the window's border. This problem was solved with the help of Geert Gruwez and myself.
2) So let's say you have successfully draw on the window's canvas in the right place. Now you need to remove it! The only way I was able to do this was to redraw everything on the form. But TPanel will not repaint its border. That is why I posted this question. So if you painted your rectangle border over the TPanel, and you redraw the TPanel, it will not remove the rectangle on its border.
3) Also redrawing everything on the form causes a flicker which is very ugly.

Cheers
-Richard

 

by: EddieShipmanPosted on 2009-05-22 at 16:01:18ID: 24455723

Well, I'm kind of a visual person and need to see it myself but if you have a solution working for you, great.
I do think I said that you would need to move the buttons away from the panel's edges to get the effect you are looking for with the code I posted. That shouldn't be a problem, now, should it?

 

by: EddieShipmanPosted on 2009-07-09 at 07:47:38ID: 24814238

Richard, How's things coming on this? Are you able to post your DFM, yet?

 

by: rfwoolfPosted on 2009-08-13 at 02:22:49ID: 25086520

Thanks for trying Eddie - your solution didn't work in the end but I gave you points because it still might help other people and I appreciate the effort.

In the end Hypo's solution I think did repaint the panel's borders, but the final solution was to make borders out of black TPanels. This was much easy and 'clean' than drawing on canvasas, iterating through all the controls and repainting them and doing all kinds of crap.

 

by: EddieShipmanPosted on 2009-08-13 at 05:32:16ID: 25087429

I still think that if you'd posted a DFM, I would have been able to come up with a solution for you but, whatever...

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...