Drag and Drop Control in with RightToLeftLayout True - visual-studio-2010

I used following code to drag and drop Button in C# and it works like charm when my Form.RightToLeftLayout=False,
but
when I set RightToLeftLayout=True
it doesnt work and move the control in wrong direction!!!
public partial class Form1 : Form
{
int xPosition;
int yPosition;
bool isDraged;
public Form1()
{
InitializeComponent();
}
private void btnMoveable_MouseDown(object sender, MouseEventArgs e)
{
this.Cursor = Cursors.SizeAll;
xPosition = e.X;
yPosition = e.Y;
isDraged = true;
}
private void btnMoveable_MouseUp(object sender, MouseEventArgs e)
{
isDraged = false;
this.Cursor = Cursors.Default;
}
private void btnMoveable_MouseMove(object sender, MouseEventArgs e)
{
if (isDraged)
{
btnMoveable.Left = btnMoveable.Left + e.X - xPosition;
btnMoveable.Top = btnMoveable.Top + e.Y - yPosition;
}
}
}

Well, you're discovering how RightToLeft is implemented. Everything is still in their normal logical position but the coordinate system is mirror-imaged along the Y-axis. So movement along the X-axis is inverted. You'll need to accommodate that. Fix:
int dx = e.X - xPosition;
if (this.RightToLeft == RightToLeft.Yes) dx = -dx;
btnMoveable.Left = btnMoveable.Left + dx;

Related

Get temperature with x and y values using FlirOneSDK

For getting the temperature in a specific point, you need the X and Y position.
You can get the pixel position using the OnTouch event of View.IOnTouchListener, for example.
Example Code:
public bool OnTouch(View v, MotionEvent e)
{
Position_X = (int)e.GetX();
Position_Y = (int)e.GetY();
return true;
}
and OnFrameProcessed, your code would look like this:
public void OnFrameProcessed(RenderedImage renderedImage)
{
if (renderedImage.InvokeImageType() == RenderedImage.ImageType.ThermalRadiometricKelvinImage)
{
var step = renderedImage.Width();
var pixel = Position_X + (Position_Y * step);
var thermalPixels = renderedImage.ThermalPixelValues();
if (thermalPixels.Length < pixel)
{
pixel = thermalPixels.Length - 1;
}
//temperature in point
AvgPointTemperature = (thermalPixels[pixel] / 100.0) - 273.15;
}
}
I don't know if it's the best method, but it's the one I found.
Thanks.
Okey , this need Customizing a ContentPage to get X and Y from IOS or Android device.
Android:
public override bool OnTouchEvent(MotionEvent e)
{
Console.WriteLine("x->" + e.GetX() + "y->" + e.GetY());
return base.OnTouchEvent(e);
}
IOS:
public override void TouchesBegan(NSSet touches, UIEvent evt)
{
base.TouchesBegan(touches, evt);
UITouch touch = (UITouch)touches.AnyObject;
CGPoint cp = touch.LocationInView(this.View);
Console.WriteLine("x->" + cp.X + "y->" + cp.Y);
}

Camera timer animation on UWP

I am developing an UWP application, and one of my page is actually for user to take photo of them. In the page, I have timers for user to select before they take picture.
However, I wish to have a timer shown, counting down in the camera screen, so that the user know how much time is left for them to prepare, before the picture is taken.
Any idea on how I can do that? Thank you!
Just in case it is needed, here is my codes for the timers and the take picture buttons:
private async void PhotoButton_Click(object sender, RoutedEventArgs e)
{
//If preview is not running, no preview frames can be acquired
if (!_isPreviewing) return;
await Task.Delay(TimeSpan.FromSeconds(_seconds));
await TakePhotoAsync();
await GetPreviewFrameAsSoftwareBitmapAsync();
PreviewFrameBackground.Visibility = Visibility.Visible;
}
private void Timer_3sec_Click(object sender, RoutedEventArgs e)
{
Timer_5sec.Opacity = 0.2;
Timer_7sec.Opacity = 0.2;
Timer_3sec.Opacity = 1.0;
_seconds = 3;
}
private void Timer_5sec_Click(object sender, RoutedEventArgs e)
{
Timer_3sec.Opacity = 0.2;
Timer_7sec.Opacity = 0.2;
Timer_5sec.Opacity = 1.0;
_seconds = 5;
}
private void Timer_7sec_Click(object sender, RoutedEventArgs e)
{
Timer_3sec.Opacity = 0.2;
Timer_5sec.Opacity = 0.2;
Timer_7sec.Opacity = 1.0;
_seconds = 7;
}
You can use a DispatcherTimer to solve your problem.
Here a little code sample how you can do that (The sample dont show how to take the capture or to show the remaining seconds, just to calculate them!)
Class-Parameters:
private int _startTime;
private DispatcherTimer _timer = new DispatcherTimer();
Methods:
private void StartTimer()
{
_timer.Interval = TimeSpan.FromMilliseconds(500);
_timer.Tick += Timer_Tick;
_startTime = Environment.TickCount;
_timer.Start();
}
private void Timer_Tick(object sender, object e)
{
var remainingSeconds = _seconds - TimeSpan.FromMilliseconds(Environment.TickCount - _startTime).Seconds;
if(remainingSeconds <= 0)
{
_timer.Stop();
_timer.Tick -= Timer_Tick;
timerText.Text = "0 Seconds";
//Capture Image
} else
{
timerText.Text = "" + remainingSeconds + " Seconds";
}
}
You need to call the StartTimer-Method in you Click-Methods, after setting the _seconds.

windows phone application button content

I've got incredibly weird problem. I'm making memo game app on windows phone. When I click 2 buttons and if they have the same content they should collapse. Problem is that even if they have the same content for example 1 it shows me that this statement is false! Like 1 was not equal 1.
Here's the code:
public partial class Memo : PhoneApplicationPage
{
private int points = 100;
private string[] numbers={"a","a"};
private Button selected_button;
public Memo()
{
InitializeComponent();
button1.Content = numbers[0];
button2.Content = numbers[1];
}
private void button1_Click(object sender, RoutedEventArgs e)
{
if (selected_button != null)
{
PageTitle.Text = "" + selected_button.Content + " " + button1.Content;
if (selected_button.Content == button1.Content)
{
button1.Visibility = Visibility.Collapsed;
selected_button.Visibility = Visibility.Collapsed;
points += 3;
}
else
{
points -= 1;
selected_button.Background = new SolidColorBrush(Colors.White);
}
selected_button = null;
//PageTitle.Text = "" + points;
}
else
{
selected_button = button1;
selected_button.Background = new SolidColorBrush(Colors.Green);
}
}
private void button2_Click(object sender, RoutedEventArgs e)
{
if (selected_button != null)
{
PageTitle.Text = "" + selected_button.Content + " " + button2.Content;
if (selected_button.Content == button2.Content)
{
button2.Visibility = Visibility.Collapsed;
selected_button.Visibility = Visibility.Collapsed;
points += 3;
}
else
{
points -= 1;
selected_button.Background = new SolidColorBrush(Colors.White);
}
selected_button = null;
//PageTitle.Text = "" + points;
}
else
{
selected_button = button2;
selected_button.Background = new SolidColorBrush(Colors.Green);
}
}
private void button11_Click(object sender, RoutedEventArgs e)
{
button11.Visibility = Visibility.Collapsed;
}
}
Please help :)

Pinch Zoom - Getting touch coordinates

I am developing a Windows 8 app using WinJS. I am trying to get the touch coordinates for pinch and zoom. I have implemented the gesture manipulation handlers via Windows.UI.Input.GestureRecognizer. I am triggering my pinch and zoom logic when for the "manipulationupdated" event, event.delta.scale is not 1. When manipulation happens inside the "manipulationupdated" event object I find coordinates of only 1 position. How do I calculate both the finger touch coordinates from this information?
Also how do I know which touch coordinate the position belong to? I find the position repeated multiple times inside the event object - at event.position and event.detail[0].position
What I am trying to achieve is performing pinch and zoom in a chart(much like a map). Kindly help me out with these questions.
public class PZBehavior : Behavior
{
bool _isDragging;
bool _isPinching;
Point _ptPinchPositionStart;
private Image _imgZoom;
private ScaleTransform _scaleTransform;
private RotateTransform _rotateTransform;
private TranslateTransform _translateTransform;
private MatrixTransform _previousTransform;
private TransformGroup _parentGroup;
private TransformGroup _currentTransform;
protected override void OnAttached()
{
_imgZoom = AssociatedObject;
_imgZoom.RenderTransform = BuildTrasnformGroup();
var listener = GestureService.GetGestureListener(AssociatedObject);
listener.DragStarted += DragStarted;
listener.DragDelta += DragDelta;
listener.DragCompleted += DragCompleted;
listener.PinchStarted += PinchStarted;
listener.PinchDelta += PinchDelta;
listener.PinchCompleted += PinchCompleted;
}
private TransformGroup BuildTrasnformGroup()
{
_parentGroup = new TransformGroup();
_currentTransform = new TransformGroup();
_previousTransform = new MatrixTransform();
_scaleTransform = new ScaleTransform();
_rotateTransform = new RotateTransform();
_translateTransform = new TranslateTransform();
_currentTransform.Children.Add(_scaleTransform);
_currentTransform.Children.Add(_rotateTransform);
_currentTransform.Children.Add(_translateTransform);
_parentGroup.Children.Add(_previousTransform);
_parentGroup.Children.Add(_currentTransform);
return _parentGroup;
}
void PinchCompleted(object sender, PinchGestureEventArgs e)
{
if (_isPinching)
{
TransferTransforms();
_isPinching = false;
}
}
void PinchDelta(object sender, PinchGestureEventArgs e)
{
if (_isPinching)
{
// Set scaling
_scaleTransform.ScaleX = e.DistanceRatio;
_scaleTransform.ScaleY = e.DistanceRatio;
// Optionally set rotation
_rotateTransform.Angle = e.TotalAngleDelta;
// Set translation
Point ptPinchPosition = new Point(0,0);
_translateTransform.X = ptPinchPosition.X - _ptPinchPositionStart.X;
_translateTransform.Y = ptPinchPosition.Y - _ptPinchPositionStart.Y;
}
}
void PinchStarted(object sender, PinchStartedGestureEventArgs e)
{
_isPinching = e.OriginalSource == _imgZoom;
if (_isPinching)
{
// Set transform centers
Point ptPinchCenter = e.GetPosition(_imgZoom);
ptPinchCenter = _previousTransform.Transform(ptPinchCenter);
_scaleTransform.CenterX = ptPinchCenter.X;
_scaleTransform.CenterY = ptPinchCenter.Y;
_rotateTransform.CenterX = ptPinchCenter.X;
_rotateTransform.CenterY = ptPinchCenter.Y;
_ptPinchPositionStart = new Point(0,0);
}
}
void DragCompleted(object sender, DragCompletedGestureEventArgs e)
{
if (_isDragging)
{
TransferTransforms();
_isDragging = false;
}
}
void DragDelta(object sender, DragDeltaGestureEventArgs e)
{
if (_isDragging)
{
_translateTransform.X += e.HorizontalChange;
_translateTransform.Y += e.VerticalChange;
}
}
void DragStarted(object sender, DragStartedGestureEventArgs e)
{
_isDragging = e.OriginalSource == _imgZoom;
}
void TransferTransforms()
{
_previousTransform.Matrix = Multiply(_previousTransform.Matrix, _currentTransform.Value);
// Set current transforms to default values
_scaleTransform.ScaleX = _scaleTransform.ScaleY = 1;
_scaleTransform.CenterX = _scaleTransform.CenterY = 0;
_rotateTransform.Angle = 0;
_rotateTransform.CenterX = _rotateTransform.CenterY = 0;
_translateTransform.X = _translateTransform.Y = 0;
}
Matrix Multiply(Matrix a, Matrix b)
{
return new Matrix(a.M11 * b.M11 + a.M12 * b.M21,
a.M11 * b.M12 + a.M12 * b.M22,
a.M21 * b.M11 + a.M22 * b.M21,
a.M21 * b.M12 + a.M22 * b.M22,
a.OffsetX * b.M11 + a.OffsetY * b.M21 + b.OffsetX,
a.OffsetX * b.M12 + a.OffsetY * b.M22 + b.OffsetY);
}
}

Sorting ASP Datalist after BINDING

I am binding a DataList with dynamic values (ie distances from google api From a particular location.)
ie from x location :
10 km away
15 km away etc as follows
Using this code in ItemDataBound :
private void bindDataList(string location)
{
DataSet dstProperty = Tbl_PropertyMaster.getPropertiesByLocation(location);
dlstNearbyProperties.DataSource = dstProperty;
dlstNearbyProperties.DataBind();
}
.
protected void dlstNearbyProperties_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
Label lblPropId = (Label)e.Item.FindControl("lblPropId");
Label lblKmAway = (Label)e.Item.FindControl("lblKmAway");
Label lblPrice = (Label)e.Item.FindControl("lblPrice");
DataSet dstEnabledStat = Tbl_PropertyMaster.GetPropertyDetailsbyId(Convert.ToInt32(lblPropId.Text));
if (dstEnabledStat.Tables[0].Rows.Count > 0)
{
//string origin = "8.5572357 ,76.87649310000006";
string origin = InitialOrigin;
string destination = dstEnabledStat.Tables[0].Rows[0]["Latitude"].ToString() + "," + dstEnabledStat.Tables[0].Rows[0]["Longitude"].ToString();
lblKmAway.Text = devTools.getDistance(origin, destination) + " Away";
}
lblPrice.Text = getMinnimumOfRoomPrice(Convert.ToInt32(lblPropId.Text));
}
}
Is there a way to sort these value in ascendind or descening w.r.t distances .
NB: Distances are not DB values,they are dynamic.
Can this be sorted in a Button1_Click ?
Alrite after lot of hours of playing with codes I did it.
The following is for GRIDVIEW,Similar steps can be followed for DataList As well.
Page Load : I added an extra column 'Miles' to the already existing datatable
protected void Page_Load(object sender, EventArgs e)
{
dtbl = Tbl_PropertyMaster.SelectAllPropertyAndUserDetails().Tables[0];
dtbl.Columns.Add("Miles", typeof(int));
//userId = devTools.checkAdminLoginStatus();
if (!IsPostBack)
{
fillDlPhotoViewAll();
FillGrProperty();
}
}
Row Data Bound :
protected void grProperty_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataSet dstEnabledStat = Tbl_PropertyMaster.GetPropertyDetailsbyId(PropId);
if (dstEnabledStat.Tables[0].Rows.Count > 0)
{
string origin = InitialOrigin;
string destination = dstEnabledStat.Tables[0].Rows[0]["Latitude"].ToString() + "," + dstEnabledStat.Tables[0].Rows[0]["Longitude"].ToString();
decimal Kilometre=0.00M;
if(devTools.getDistance(origin, destination)!=0)
{
Kilometre=Convert.ToDecimal(devTools.getDistance(origin, destination))/1000;
}
lblmiles.Text = Kilometre.ToString() + "Kms";
dtbl.Rows[inn]["Miles"] = Convert.ToInt32(devTools.getDistance(origin, destination));
inn = inn + 1;
}
}
ViewState["dtbl"] = dtbl;
}
Sort by distance Button_Click:
protected void btnSort_Click(object sender, EventArgs e)
{
DataTable dataTable;
dataTable = (DataTable)ViewState["dtbl"];
if (dataTable.Rows.Count > 0)
{
dataTable.DefaultView.Sort = "Miles DESC";
dataTable.AcceptChanges();
grProperty.DataSource = dataTable;
grProperty.DataBind();
}
}

Resources