本文整理匯總了C#中System.Windows.Forms.Binding.ReadValue方法的典型用法代碼示例。如果您正苦於以下問題:C# Binding.ReadValue方法的具體用法?C# Binding.ReadValue怎麽用?C# Binding.ReadValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Windows.Forms.Binding
的用法示例。
在下文中一共展示了Binding.ReadValue方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ApplyWriteRules
private void ApplyWriteRules(
Control ctl, Binding binding,
bool canWrite)
{
if (ctl is Label) return;
// enable/disable writing of the value
PropertyInfo propertyInfo =
ctl.GetType().GetProperty("ReadOnly",
BindingFlags.FlattenHierarchy |
BindingFlags.Instance |
BindingFlags.Public);
if (propertyInfo != null)
{
bool couldWrite =
(!(bool)propertyInfo.GetValue(
ctl, new object[] { }));
propertyInfo.SetValue(
ctl, !canWrite, new object[] { });
if ((!couldWrite) && (canWrite))
binding.ReadValue();
}
else
{
bool couldWrite = ctl.Enabled;
ctl.Enabled = canWrite;
if ((!couldWrite) && (canWrite))
binding.ReadValue();
}
}
示例2: ReadValueTest
public void ReadValueTest ()
{
Control c = new Control ();
c.BindingContext = new BindingContext ();
c.CreateControl ();
ChildMockItem item = new ChildMockItem ();
item.ObjectValue = "A";
Binding binding = new Binding ("Tag", item, "ObjectValue");
binding.ControlUpdateMode = ControlUpdateMode.Never;
c.DataBindings.Add (binding);
Assert.AreEqual (null, c.Tag, "#A1");
item.ObjectValue = "B";
Assert.AreEqual (null, c.Tag, "#B1");
binding.ReadValue ();
Assert.AreEqual ("B", c.Tag, "#C1");
item.ObjectValue = "C";
binding.ReadValue ();
Assert.AreEqual ("C", c.Tag, "#D1");
c.Dispose();
}
示例3: ApplyReadRules
private void ApplyReadRules(
Control ctl, Binding binding,
bool canRead)
{
var status = GetControlStatus(ctl);
// enable/disable reading of the value
if (canRead)
{
ctl.Enabled = true;
// if !CanRead remove format event and refresh value
if (!status.CanRead)
{
binding.Format -= ReturnEmpty;
binding.ReadValue();
}
}
else
{
ctl.Enabled = false;
if (status.CanRead)
{
binding.Format += ReturnEmpty;
}
// clear the value displayed by the control
var propertyInfo = ctl.GetType().GetProperty(binding.PropertyName,
BindingFlags.FlattenHierarchy |
BindingFlags.Instance |
BindingFlags.Public);
if (propertyInfo != null)
{
propertyInfo.SetValue(ctl,
GetEmptyValue(
Utilities.GetPropertyType(
propertyInfo.PropertyType)),
new object[] { });
}
}
// store new status
status.CanRead = canRead;
}