Painting

  • Thread starter Thread starter Saurabh
  • Start date Start date
S

Saurabh

Hi All,

I have added my own button in the titlebar of a form next to the close
button. Everything works fine but when I resize the dialog, the button does
not get redrawn at a correct location.

I calculate the button position relative to the close button and draw a
button using ControlPaint, but if i increase the size of the form briskly,
the distance between the close button and my button increases till the next
redraw. If i reduce the width of the form by dragging the border inwards, my
button gets drawn overlapping on the close button. I want my button to be at
a fixed position relative to the close button. Is there any way to achieve
this?

TIA,

--Saurabh
 
Try posting in the microsoft.public.dotnet.framework.drawing newsgroup.
There are several people there who can help you with this. Specifically Bob
Powell.

Cheers,
Paul
 
* "Saurabh said:
I have added my own button in the titlebar of a form next to the close
button. Everything works fine but when I resize the dialog, the button does
not get redrawn at a correct location.

I calculate the button position relative to the close button and draw a
button using ControlPaint, but if i increase the size of the form briskly,
the distance between the close button and my button increases till the next
redraw. If i reduce the width of the form by dragging the border inwards, my
button gets drawn overlapping on the close button. I want my button to be at
a fixed position relative to the close button. Is there any way to achieve
this?

Please post the code you use to position the button.
 
here it is, though i don't see how it can make a difference. What I think
is, I am repainting the window for most of the messages but i may still be
missing some. CTLCOLOR may be one of them, not sure....
-----code...........
int CaptionHeight = Bounds.Height - ClientRectangle.Height;

Size CloseButtonSize = SystemInformation.CaptionButtonSize;

int X = Bounds.Width - 4 - CloseButtonSize.Width * 2;

int Y = 6;

MyButton.Bounds = new Rectangle(X, Y, 15, 15);

------------end of code--------------
 
I had a similar problem... The problem is that whenever you do that, your form gets resized and only AFTER that the buttons position gets recalculated. No matter how fast you do your calculations, the human eye will catch the movement of the form before the button gets redrawn. I had a similar problem, I designed a bordereless captionless form with an additional fotter that contained a close button and a resize grip to used it as a sticky-note kinda thing. The same thing was happening, everytime I was resizing the form, the buttons showed this "inertio" kind of movement. I was able to solve this by doing the following: I was overriding the OnResize method and doing something like this:

buttons.Invalidate();
resizing = true;
base.OnResize();
resizing = false;
buttons.Invalidate();

In the paint routine of the form, if resizing was true, then I would reposition the button BEFORE calling the form's paint routine. After a few tests it looked like this pretty much solved the problem, but again, my form was totally ownerdrawn and I am not sure how exactly drawing in the non-client area is affected...

hope this helps,
iulian
 
Back
Top