Example #1
0
        private void rbLocation_CheckedChanged(object sender, EventArgs e)
        {
            var btn = sender as RadioButton;

            if (btn == null)
            {
                return;
            }
            FormLocation loc = 0;

            if (btn == rbLT)
            {
                loc = FormLocation.LEFT_TOP;
            }
            else if (btn == rbRT)
            {
                loc = FormLocation.RIGHT_TOP;
            }
            else if (btn == rbLB)
            {
                loc = FormLocation.LEFT_BOTTOM;
            }
            else if (btn == rbRB)
            {
                loc = FormLocation.RIGHT_BOTTOM;
            }
            else if (btn == rbCEN)
            {
                loc = FormLocation.CENTER;
            }
            ReLocation(loc);
        }
Example #2
0
        private void ReLocation(FormLocation location)
        {
            switch (location)
            {
            case FormLocation.LEFT_TOP:
                Top  = 0;
                Left = 0;
                break;

            case FormLocation.RIGHT_TOP:
                Top  = 0;
                Left = Screen.PrimaryScreen.WorkingArea.Width - Width;
                break;

            case FormLocation.LEFT_BOTTOM:
                Top  = Screen.PrimaryScreen.WorkingArea.Height - Height;
                Left = 0;
                break;

            case FormLocation.RIGHT_BOTTOM:
                Top  = Screen.PrimaryScreen.WorkingArea.Height - Height;
                Left = Screen.PrimaryScreen.WorkingArea.Width - Width;
                break;

            case FormLocation.CENTER:
                Top  = (Screen.PrimaryScreen.WorkingArea.Height - Height) / 2;
                Left = (Screen.PrimaryScreen.WorkingArea.Width - Width) / 2;
                break;
            }
            Properties.Settings.Default.WindowLocation = (int)location;
            Properties.Settings.Default.Save();
            currentLocation = location;
        }
        /// <summary>
        /// Restore the size, state and location that were saved for a form
        /// </summary>
        /// <param name="form">The form whose properties are to be restored</param>
        public static void RestoreWindowLocation(Form form)
        {
            try
            {
                int currentScreenSizeCode = GetScreenSizeSummaryCode();

                FormLocationsCollection flc = Properties.Settings.Default.FormLocations;
                if (flc != null)
                {
                    string       name = GetWindowName(form);
                    FormLocation fl   = (from f in flc where f.Name == name && f.ScreenSizeCode == currentScreenSizeCode select f).FirstOrDefault();
                    if (fl != null)
                    {
                        if (fl.IsMaximized)
                        {
                            form.WindowState = FormWindowState.Maximized;
                        }
                        else
                        {
                            form.Size     = fl.Size;
                            form.Location = fl.Location;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("RestoreWindowLocation: " + ex.Message);
            }
        }
        /// <summary>
        /// Save the current size, state and location of a form
        /// </summary>
        /// <param name="form">The form whose properties are to be saved</param>
        public static void SaveWindowLocation(Form form)
        {
            try
            {
                int currentScreenSizeCode = GetScreenSizeSummaryCode();

                FormLocationsCollection flc = Properties.Settings.Default.FormLocations ?? new FormLocationsCollection();
                FormLocation            fl  = new FormLocation();
                fl.ScreenSizeCode = currentScreenSizeCode;
                fl.IsMaximized    = form.WindowState == FormWindowState.Maximized;
                if (!fl.IsMaximized)
                {
                    fl.Size     = form.Size;
                    fl.Location = form.Location;
                }

                string name = GetWindowName(form);
                fl.Name = name;

                // Get all locations which are *not* the current one
                FormLocationsCollection flcNew = new FormLocationsCollection(from f in flc where f.Name != name || f.ScreenSizeCode != currentScreenSizeCode select f);

                // Add current location to the collections
                flcNew.Add(fl);

                // Save back the newly formed collection
                Properties.Settings.Default.FormLocations = flcNew;
                Properties.Settings.Default.Save();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("SaveWindowLocation: " + ex.Message);
            }
        }
Example #5
0
        public async Task <IActionResult> LocationCreate(FormLocation form)
        {
            User CurrentUser = dbContext.Users.Where(u => u.Id == HttpContext.Session.GetInt32("LoggedInUserId")).FirstOrDefault();

            if (CurrentUser == null)
            {
                return(RedirectToAction("Logout", "LoginReg"));
            }

            if (ModelState.IsValid)
            {
                Location newLocation = new Location()
                {
                    LocationNickname = form.LocationNickname,
                    Address          = form.Address,
                    City             = form.City,
                    State            = form.State,
                    Zip    = form.Zip,
                    UserId = CurrentUser.Id,
                };

                string fullAddress = newLocation.Address + "+" + newLocation.City + "+" + newLocation.State + "+" + newLocation.Zip;


                var place = await HttpService.GetGeoCode(fullAddress);

                if (place[0] != "ERROR")
                {
                    System.Console.WriteLine($"Lat: {place[0]} Long: {place[1]}");
                    string coords = "{lat: " + place[0] + ", lng: " + place[1] + "}";
                    newLocation.Coords = coords;

                    dbContext.Add(newLocation);
                    dbContext.SaveChanges();
                    return(Redirect($"/commute/new/{HttpContext.Session.GetInt32("cpId")}"));
                }
                else
                {
                    System.Console.WriteLine("Invalid address");
                    ModelState.AddModelError("Address", "Invalid Address");
                    return(View("LocationNew"));
                }
            }
            return(View("LocationNew"));
        }
Example #6
0
 public static void AddControlInGeneralLocation(Form parent, Form child, FormLocation loc)
 {
     child.MdiParent = parent;
     System.Drawing.Point location = child.Location;
     if ((loc & FormLocation.Right) == FormLocation.Right)
     {
         location.X = parent.Width - (child.Width + child.Margin.Right + parent.Margin.Right + RIGHT_OFFSET);
     }
     if ((loc & FormLocation.Bottom) == FormLocation.Bottom)
     {
         location.Y = parent.Height - (child.Height + child.Margin.Bottom + parent.Margin.Bottom + BOTTOM_OFFSET);
     }
     if ((loc & FormLocation.CenterX) == FormLocation.CenterX)
     {
         location.X = ((parent.Width - parent.Margin.Horizontal) / 2) - ((child.Width - child.Margin.Horizontal) / 2);
     }
     if ((loc & FormLocation.CenterY) == FormLocation.CenterY)
     {
         location.Y = ((parent.Height - parent.Margin.Vertical) / 2) - ((child.Height - child.Margin.Vertical) / 2);
     }
     child.Location = location;
     child.Show();
 }