Resize in specific increments...

G

Guest

I'm creating a user control where the size always needs to be divisible by three.

In the resize event within the custom control I'm having no problem maintaining the height to be the same as the width, but as soon as I try to add some code to make sure that the width is always divisible by three, VS crashes.

How can I force the width 9and height) to always be a factor of three? Thanks.

J
 
L

Linda Liu [MSFT]

Hi,

Based on my understanding, you have a UserControl and you handle it Resize
event to make the height equal to the width. The problem is that if you try
to add some code to make sure that the width is divisible by three, the VS
IDE crashes when you resize the UserControl on a form in the designer. If
I'm off base, please feel free to let me know.

I think the possible reason of your problem may be that the Resize event
handler is been executed for too many times when the UserControl's width is
changed, because you're attempting to change the width to make sure it is
divisible by three. And it causes the memory overflow.

You may have a try unsubscribing the Resize event before you modify the
value of the width to make sure it divisible by three, and then
re-subscribing this event later.

The following is a sample.

public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
this.Resize += new EventHandler(UserControl1_Resize);
}

void UserControl1_Resize(object sender, EventArgs e)
{
if (this.Width % 3 != 0)
{
this.Resize -= new EventHandler(UserControl1_Resize);
this.Width -= this.Width % 3;
this.Resize += new EventHandler(UserControl1_Resize);
}
this.Height = this.Width;
}
}

Please try my suggestion to see if it could solve your problem.

If the problem is still not solved, you may show me your code of the Resize
event handler in your project, which may help me understand your problem
more exactly.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top