Home > Net >  The control position cannot be changed after copying
The control position cannot be changed after copying

Time:09-25

I use their own copy of the control, copy code changes out of control, but copied out of control to change the position of the Location, please everyone a great god guide exactly where possible problems,
 
using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. The Text;

Mand namespace WindowsFormsApp2.Com
{
Internal static class StaticHelper
{
Internal static T LastByName (this System. Windows. Forms. Control. ControlCollection CLL, Func Func) where T: System. Windows. Forms. Control
{
If (CLL is null)
{
Throw new ArgumentNullException (nameof (CLL));
}

If (func is null)
{
Throw new ArgumentNullException (nameof func ());
}
IList List=new List (a);
The foreach (T item in CLL)
{
List. The Add (item);
}
List. OrderBy (col=& gt; Col. Name);
Return the list. The Last (func);
}
Internal static T Clone (this T col, Func FuncName) where T: System. Windows. Forms. Control
{
Col. SuspendLayout ();
If (col==null)
{
return null;
}
Type colType=typeof (T);
System. Windows. Forms. Control restultCol=the Activator. The CreateInstance (colType) as System. Windows. Forms. The Control;
System. Reflection. PropertyInfo [] proInfo=colType. The GetProperties ();
System. Reflection. FieldInfo [] fieInfo=colType. The GetFields ();
Foreach (System. Reflection. FieldInfo item in fieInfo)
{
The object newValue=https://bbs.csdn.net/topics/item.GetValue (col);
If (newValue=null https://bbs.csdn.net/topics/=
{
continue;
}
Item. SetValue (restultCol, newValue);
}
Foreach (System. Reflection. PropertyInfo item in proInfo)
{
The object newValue=https://bbs.csdn.net/topics/item.GetValue (col);
If (newValue=null https://bbs.csdn.net/topics/=
{
continue;
}
The if (item Name=="Name")
{
NewValue=https://bbs.csdn.net/topics/funcName (col);
}
If (item. CanWrite)
{
Item. SetValue (restultCol, newValue);
}
}
If (col. Controls. Count & gt; 0)
{
Foreach (System. Windows. Forms. The Control item in col. Controls)
{
RestultCol. Controls. The Add (item. Clone (funcName));
}
}
Col. ResumeLayout ();
Return restultCol as T.
}
}
}

 
///& lt; Summary>
///copy an identical control
///& lt;/summary>
///& lt; Param name="col" & gt; & lt;/param>
///& lt; Returns> & lt;/returns>
Private void AddGroupBox ()
{
This. GroupBoxResult. Hide ();
Var regex=new System. Text. RegularExpressions. Regex (@ "(\ D +) (\ D +)");
List Tuples=this. GetTuples (enclosing groupBoxBroder);
GroupBox group=this. GroupBox1. Clone (t=& gt;
{
If (regex. IsMatch (t.N ame))
{
String firstName=regex Matches (t.N ame) [0]. Groups [1]. The Value;
String endIndex=regex Matches (t.N ame) [0]. Groups. [2] the Value;
Int tempNum=int. Parse (endIndex);
Tuple The tuple=tuples. FirstOrDefault (s=& gt; S.I tem1==t.G etType ());
If (a tuple!=null)
{
While (tempNum & lt;=the tuple. Item2)
{
TempNum++;
}
}
The else
{

}
Tuples. Remove (a tuple);
Tuples. Add (new Tuple (t.G etType (), tempNum));
Return firstName + tempNum;
}
The else
{
Return t.N ame.
}
});
System. Text. RegularExpressions. Regex reg=new System. Text. RegularExpressions. The Regex (@ "^ groupBox \ d + $");
Group. The Location=new Point (173, 40);
GroupBox group1=this. GroupBoxBroder. Controls. LastByName (t=& gt; Reg. IsMatch (t.N ame));
Group1. Location=new Point (173, 80);
}


Test code example:

CodePudding user response:

not copy Winform controls,
Because Winform controls on the bottom, it is supported by the Windows kernel object, simply copy the Control of private members are not regular and the practice of safety,

CodePudding user response:

reference 1st floor github_36000833 response:
not copy Winform controls,
Because Winform controls on the bottom, it is supported by the Windows kernel object, simply copy the Control of private members are not regular and the practice of safety,

The winform batch add controls how to add, please?

CodePudding user response:

Interface will not show there is a small lock tag, if there is to lock in the format menu to find just remove lock,
Not lock find again from main specific reasons,

CodePudding user response:

reference Beijing haze days reply: 3/f
interface will not show there is a small lock tag, if there is to lock in the format menu to find just remove lock,
Not lock find again from main specific reasons,

One, the original GroupBox to locking control did not work,
Second, because I am a newly generated a GroupBox, with original GroupBox is two objects, I refers to the newly generated the GroupBox cannot set the Location, the original GroupBox be able to set the Location, and no effect,
As to why the new generation of this GroupBox cannot set the Location, don't understand,

CodePudding user response:

Control the Refresh

CodePudding user response:

Check generated groupbox parent control, where the container is not expected that lead to,

CodePudding user response:

Why do you say first scenario, you want to copy control, we can help you to see if there are any other way to solvenullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related