omid talebi



Re: Windows Forms Data Controls and Databinding Build Class that when I use it; Property "Anchor" of All controls in my form set to "None".

Eli Gazit

public class AnchorChanger

{

public static void ChangeAnchor(Form form)

{

Control[] controls = GetAllControls(form);

foreach (Control var in controls)

{

if (var is Form)

continue;

var.Anchor = AnchorStyles.None;

}

}

public static Control[] GetAllControls(Form form)

{

List<Control> controls = new List<Control>();

GetAllControlsRec(form, controls);

return controls.ToArray();

}

private static void GetAllControlsRec(Control control, List<Control> controls)

{

controls.Add(control);

foreach (Control innerControl in control.Controls)

{

GetAllControlsRec(innerControl, controls);

}

}

}

In the form class:

private void Form1_Load(object sender, EventArgs e)

{

AnchorChanger.ChangeAnchor(this);

}






Re: Windows Forms Data Controls and Databinding Build Class that when I use it; Property "Anchor" of All controls in my form set to "None".

omid talebi

your code is true.

but i want class that i drag it from toolbox into my form.





Re: Windows Forms Data Controls and Databinding Build Class that when I use it; Property "Anchor" of All controls in my form set to "None".

Eli Gazit

public class AnchorChangerComponent : Component

{

private Form _formToChange;

/// <summary>

/// Gets or sets the form to set the anchor to

/// </summary>

public Form FormToChange

{

get { return _formToChange; }

set

{

_formToChange = value;

if(_formToChange != null)

AnchorChanger.ChangeAnchor(_formToChange);

}

}

}

After you drag this component, you need to see the property: FormToChange to the form and all controls anchor value will change.