如何使用linq获取数组中控件的最低位置 [英] How to get lowest location of controls in array using linq
问题描述
如何使用linq获取数组中控件的最低位置
i有一系列控件说
dim oClipboard()作为控件< br $>
i需要具有最低位置或最低位置值的控件来自oclipboard
我尝试了什么:
到目前为止我已尝试使用min函数的linq
Dim p = c.Select(Function(g)g.Location).Min.ToString
Dim x = c.Select(Function(g)g).Min(Function (h)h。位置)
以上都给我下面的错误
System.ArgumentException未处理
HResult = -2147024809
消息=至少有一个对象必须实现IComparable。
来源= mscorlib
StackTrace:
在System.Collections.Comparer.Compare(对象a,对象b)
在System.Collections.Generic.ObjectComparer`1.Compare(T x, T y)
在System.Linq.Enumerable.Min [TSource](IEnumerable`1 source)
在System.Linq.Enumerable.Min [TSource,TResult](IEnumerable`1 source,Func`2 selector)
有什么方法可以控制哪个位置最低
how to get lowest location of controls in array using linq
i have array of controls say
dim oClipboard() as control
i needed the control which has lowest location or minimum location value from tha oclipboard
What I have tried:
so far i have tried linq with min function
Dim p = c.Select(Function(g) g.Location).Min.ToString
Dim x = c.Select(Function(g) g).Min(Function(h) h.Location)
both of above give me error stated below
System.ArgumentException was unhandled
HResult=-2147024809
Message=At least one object must implement IComparable.
Source=mscorlib
StackTrace:
at System.Collections.Comparer.Compare(Object a, Object b)
at System.Collections.Generic.ObjectComparer`1.Compare(T x, T y)
at System.Linq.Enumerable.Min[TSource](IEnumerable`1 source)
at System.Linq.Enumerable.Min[TSource,TResult](IEnumerable`1 source, Func`2 selector)
is there any way i could get control whhich has lowest location
推荐答案
尝试类似:
Try something like:
Control lowest = myControls.OrderByDescending(c => c.Location.Y).First();
VB(未经测试):
VB (untested):
Dim lowest As Control = myControls.OrderByDescending(Function(c) c.Location.Y).First()
Enumerable.Min() [ ^ ]和 Enumerable.Max() [ ^ ]函数?
What's wrong with Enumerable.Min()[^] and Enumerable.Max()[^] functions?
var lowest = c.Min(x=>x.Location.Y);
var highest = c.Max(x=>x.Location.Y);
>
这篇关于如何使用linq获取数组中控件的最低位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!