Reputation: 361
I got a user control called PicturePanel. On the mouse events (MouseDown, MouseMove, MouseUp), I have the following:
protected override void OnMouseDown(MouseEventArgs e)
{
if (marquee == true && e.Button == MouseButtons.Left && BackgroundImage != null)
{
//Code to create rectangular marquee
}
else
{
}
}
Class level variable private bool marquee = false
by default. And a public one.
private bool marquee = false;
public bool Marquee
{
get { return marquee; }
set { marquee = value; }
}
I even tried assigning the false
at initialization:
public PicturePanel()
{
InitializeComponent();
marquee = false;
}
But marquee is always true by default. If I want to turn off marquee, I have to set it through the public variable picturePanel1.Marquee = false
in the form. How can I make marquee false by default within the user control?
Upvotes: 3
Views: 2398
Reputation: 15810
I'm not sure if this is what you're talking about, but if you're referring to the default value that you see in the designer, then you just need to add the following attribute to your property:
[DefaultValue(false)]
public bool Marquee
...
Upvotes: 2
Reputation: 15810
Your issue might be that when you use the designer to "draw" the control on the form, it might be registering the MouseDown event, setting the Marquee to true. You can prevent this by checking this.DesignMode
in your event handler.
Example:
if (this.DesignMode) return;
Upvotes: 0
Reputation: 59012
Well, booleans are always false by default. You don't happen to have a local variable called marquee or something?
Just set a breakpoint on private bool marquee = false;
and step through your code and you'll find it pretty quick.
Upvotes: 0