public void SetSelectedClassroom(int classroomRow) { enable(true); beforeSelected = new ClassroomLabel("", ""); nowSelected = buttons[classroomRow]; nowSelected.Background = selectedColor; }
private void OnMouseLeftButtonDown(object sender, RoutedEventArgs e) { nowSelected = sender as ClassroomLabel; ResetBackground(); nowSelected.Background = selectedColor; previousColor = -1; mouseLeftButtonDown = true; }
public ClassroomSelectControl() { InitializeComponent(); List <string> classroomList = ServerClient.getInstance().classroomList; TOTAL_NUM = classroomList.Count; buttons = new ClassroomLabel[TOTAL_NUM]; overlaps = new Rectangle[TOTAL_NUM]; Border nowBuildingLabelBorder = null; int buildingLabelOrder = 0; for (int row = 0; row < TOTAL_NUM; row++) { //Add RowDefinition RowDefinition rowDef = new RowDefinition(); rowDef.Height = new GridLength(1, GridUnitType.Star); mainGrid.RowDefinitions.Add(rowDef); //Get building name and classroom name string buildingName = (classroomList[row] as string).Split(':')[0]; string classroomName = (classroomList[row] as string).Split(':')[1]; //Add label to Grid ClassroomLabel classroomLabel = new ClassroomLabel(buildingName, classroomName); classroomLabel.Content = classroomName; classroomLabel.MouseLeftButtonDown += new MouseButtonEventHandler(OnMouseLeftButtonDown); classroomLabel.MouseLeftButtonUp += new MouseButtonEventHandler(OnMouseLeftButtonUp); classroomLabel.MouseEnter += new MouseEventHandler(OnMouseEnter); classroomLabel.MouseLeave += new MouseEventHandler(OnMouseLeave); Grid.SetRow(classroomLabel, row); Grid.SetColumn(classroomLabel, 1); buttons[row] = classroomLabel; mainGrid.Children.Add(classroomLabel); //Adjust building label if (nowBuildingLabelBorder != null && (nowBuildingLabelBorder.Child as Label).Content.Equals(buildingName)) { Grid.SetRowSpan(nowBuildingLabelBorder, Grid.GetRowSpan(nowBuildingLabelBorder) + 1); } else { Label buildingLabel = new Label(); buildingLabel.Content = buildingName; buildingLabel.Style = Resources["buildingLableStyle"] as Style; buildingLabel.Background = (buildingLabelOrder++ % 2 == 0) ? backgroundEven : backgroundOdd; Border border = new Border(); border.Style = Resources["buildingBorderStyle"] as Style; border.Child = buildingLabel; Grid.SetRow(border, row); Grid.SetColumn(border, 0); Grid.SetRowSpan(border, 1); nowBuildingLabelBorder = border; mainGrid.Children.Add(border); } Rectangle overlap = new Rectangle(); Grid.SetRow(overlap, row); Grid.SetColumn(overlap, 1); overlaps[row] = overlap; mainGrid.Children.Add(overlap); } ResetBackground(); }
public void ResetSelection() { beforeSelected = null; nowSelected = null; ResetBackground(); }