views:

142

answers:

4

Hello.

I'm developing a Windows Mobile 5.0 or above with .Net Compact Framework 2.0 SP2 and C#.

I have a custom control called PullDownMenu (it inherits from System.Windows.Form.Control). This is the code that I use on a WinForm to show it:

PullDownMenu menu = new PullDownMenu();
menu.Location = new Point(0, 0);
menu.Dock = DockStyle.Fill;
this.Controls.Add(menu);

I've noticed that it size changes during this process. How can I know when it gets its final size?

Yes, I know I can check OnResize event but this event it is called serveral times and I think it can downgrade the perfomance.

Is there an event that is thrown when the control is completely displayed? or when it is added to its parent (on this line: this.Controls.Add(menu);).

Any adviced?

+1  A: 

The Control.ParentChanged event/Control.OnParentChanged method should handle notification of being added to a control

I would use the Control.Paint/Control.OnPaint to determine the 'final' size.

hjb417
How are you going to know it's the _last_ time OnPaint is called?
hometoast
A: 

Does the compact framework allow a container to SuspendLayout and ResumeLayout?

If you suspend beforehand, and check it's size after ResumeLayout, it should be it's intended size.

hometoast
+3  A: 

Some of the controls in the Compact Framework support BeginUpdate and EndUpdate methods which may help this issue. Using a custom control, I believe that you may have to implement your own methods to support this behavior.

To improve rendering performance, call the BeginUpdate, update the properties that may change its size, and then call the EndUpdate method. This will minimize the render calls that are invoked by the resizing.

cbuck12000
Where can I improve perfomance? In OnResize method? I don't want to use this method. I don't understand this answer.
VansFannel
I don't understand you.
VansFannel
A: 

To specify default size for a custom control, add the size value to a xmta file in your project. If you do not have one already, right click project and select add new item, then choose the designtime attribute file and name it whatever you want.

Add the following code to your xmta file:

<Class Name="MyControlNamespace.MyControlClassName">
    <DesktopCompatible>true</DesktopCompatible>
    <Property Name ="Size">
      <DefaultValue>
        <Type>System.Drawing.Size, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Type>
        <Value>100, 20</Value>
      </DefaultValue>
    </Property>
</Class>

Replace namespace and class with your own, also check that the public key token is correct