Вот версия Silverlight
Особая благодарность @DTig
,
using System.Windows.Controls;
using System.Windows;
using Telerik.Windows;
using System;
using System.Linq;
public class AlignableWrapPanel : Panel
{
public HorizontalAlignment HorizontalContentAlignment
{
get { return (HorizontalAlignment)GetValue(HorizontalContentAlignmentProperty); }
set { SetValue(HorizontalContentAlignmentProperty, value); }
}
public static readonly DependencyProperty HorizontalContentAlignmentProperty =
DependencyProperty.Register("HorizontalContentAlignment", typeof(HorizontalAlignment), typeof(AlignableWrapPanel), new FrameworkPropertyMetadata(HorizontalAlignment.Left, FrameworkPropertyMetadataOptions.AffectsArrange));
protected override Size MeasureOverride(Size constraint)
{
Size curLineSize = new Size();
Size panelSize = new Size();
UIElementCollection children = base.Children;
for (int i = 0; i < children.Count; i++)
{
UIElement child = children[i] as UIElement;
// Flow passes its own constraint to children
child.Measure(constraint);
Size sz = child.DesiredSize;
if (curLineSize.Width + sz.Width > constraint.Width) //need to switch to another line
{
panelSize.Width = Math.Max(curLineSize.Width, panelSize.Width);
panelSize.Height += curLineSize.Height;
curLineSize = sz;
if (sz.Width > constraint.Width) // if the element is wider then the constraint - give it a separate line
{
panelSize.Width = Math.Max(sz.Width, panelSize.Width);
panelSize.Height += sz.Height;
curLineSize = new Size();
}
}
else //continue to accumulate a line
{
curLineSize.Width += sz.Width;
curLineSize.Height = Math.Max(sz.Height, curLineSize.Height);
}
}
// the last line size, if any need to be added
panelSize.Width = Math.Max(curLineSize.Width, panelSize.Width);
panelSize.Height += curLineSize.Height;
return panelSize;
}
protected override Size ArrangeOverride(Size arrangeBounds)
{
int firstInLine = 0;
Size curLineSize = new Size();
double accumulatedHeight = 0;
UIElementCollection children = this.Children;
for (int i = 0; i < children.Count; i++)
{
Size sz = children[i].DesiredSize;
if (curLineSize.Width + sz.Width > arrangeBounds.Width) //need to switch to another line
{
ArrangeLine(accumulatedHeight, curLineSize, arrangeBounds.Width, firstInLine, i);
accumulatedHeight += curLineSize.Height;
curLineSize = sz;
if (sz.Width > arrangeBounds.Width) //the element is wider then the constraint - give it a separate line
{
ArrangeLine(accumulatedHeight, sz, arrangeBounds.Width, i, ++i);
accumulatedHeight += sz.Height;
curLineSize = new Size();
}
firstInLine = i;
}
else //continue to accumulate a line
{
curLineSize.Width += sz.Width;
curLineSize.Height = Math.Max(sz.Height, curLineSize.Height);
}
}
if (firstInLine < children.Count)
ArrangeLine(accumulatedHeight, curLineSize, arrangeBounds.Width, firstInLine, children.Count);
return arrangeBounds;
}
private void ArrangeLine(double y, Size lineSize, double boundsWidth, int start, int end)
{
double x = 0;
if (this.HorizontalContentAlignment == HorizontalAlignment.Center)
{
x = (boundsWidth - lineSize.Width) / 2;
}
else if (this.HorizontalContentAlignment == HorizontalAlignment.Right)
{
x = (boundsWidth - lineSize.Width);
}
UIElementCollection children = Children;
for (int i = start; i < end; i++)
{
UIElement child = children[i];
var rect = new System.Windows.Rect(x, y, child.DesiredSize.Width, lineSize.Height);
child.Arrange(rect);
x += child.DesiredSize.Width;
}
}
}
Добавьте новое поле ввода, пометьте его "Пожалуйста, оставьте пустым", скройте его с помощью CSS и игнорируйте сообщение, если это поле заполнено. Примерно так:
<style type='text/css'>
#other_email_label, #other_email {
display: none;
}
</style>
...
<form action='mail'>
<label id='other_email_label' for='other_email'>Please leave blank:</label>
<input type='text' name='other_email' id='other_email'>
...
</form>
Итак, человек Пользователь не увидит это поле (если у него не отключен CSS, и в этом случае они увидят ярлык и оставят его пустым), но спам-робот заполнит его. Любое сообщение с этим заполненным полем должно быть от спам-робота .
Вот простая математическая капча Фила Хаака. Он работает даже с отключенным javascript.
По его собственным словам:
Он работает так, что отображает какой-то javascript для действительно простой расчет и напишите ответьте в скрытом текстовом поле, используя javascript. Когда пользователь отправляет форме, мы берем отправленное значение из поле скрытой формы, объедините его с секретное значение соли, а затем хешировать все вместе. Затем мы сравниваем это значение с хешем ожидаемый ответ, который хранится в поле скрытой формы в кодировке base64. Если javascript отключен, затем рендерим вопрос в виде текста рядом с видимое текстовое поле, что дает пользователям чтение вашего сайта через не-javascript браузеры имеют возможность комментировать
Я использовал технику текстового поля Display: None и отклонял все сообщения, которые его заполняют, и мне с этим очень повезло.
Если вы имеете в виду - используйте капчу, которую человек не может видеть в качестве проверочного теста - я думаю, что это невозможно.
Таким образом, робот игнорирует капчу сойдет за настоящего человека! Похоже на ловушку для наивного спам-робота.
Если вы хотите, чтобы ваш защищенный капчей сайт работал с клиентами, у которых нет javascript, вам следует жестко закодировать его в html.
Кроме того, если вы можете надежно идентифицировать доверенных пользователей (либо путем вынесения суждения, либо путем обнаружения некоторого шаблона использования) - вы можете разрешить им публиковать сообщения на вашем сайте без ввода кода.