虽然做法很丑,但是,至少把跨线程调用的操心事儿留给了我自己而不是使用这个类的朋友
首先定义一个Delegate:
然后在上一版Splash的基础上加上一个方法:
然后在Form1中设置Form2的Text属性,只需要写上:
Splash<Form2>.Set<string>("Text", "Loading");
这样算是更方便使用了
首先定义一个Delegate:
public
delegate
void
Set
<
T
>
(
string
propertyName, T val);
然后在上一版Splash的基础上加上一个方法:
public
static
void
Set
<
T
>
(
string
propertyName, T val)
{
PropertyInfo property = typeof (TForm).GetProperty(propertyName);
if (property == null )
throw new InvalidOperationException( " Property cannot be found " );
if (property.PropertyType != typeof (T))
throw new InvalidOperationException( " The type of input value does not
match the property type " );
if (_splashForm.InvokeRequired)
_splashForm.Invoke( new Set < T > (Splash < TForm > .Set < T > ),
new object [] { propertyName, val });
else
property.SetValue(_splashForm, val, null );
}
{
PropertyInfo property = typeof (TForm).GetProperty(propertyName);
if (property == null )
throw new InvalidOperationException( " Property cannot be found " );
if (property.PropertyType != typeof (T))
throw new InvalidOperationException( " The type of input value does not
match the property type " );
if (_splashForm.InvokeRequired)
_splashForm.Invoke( new Set < T > (Splash < TForm > .Set < T > ),
new object [] { propertyName, val });
else
property.SetValue(_splashForm, val, null );
}
然后在Form1中设置Form2的Text属性,只需要写上:
Splash<Form2>.Set<string>("Text", "Loading");
这样算是更方便使用了