private void Table_Validating(object sender, CancelEventArgs e) // { // return to here (begining of the method) if (isReceiveCommand == true) { return; // "isReceiveCommand == true" ==> When the GobangRoom components are changed, won't execute the following code } GobangRoom gobangControl = (GobangRoom)sender; this.tableIndex = int.Parse(gobangControl.Name.Substring(4)); this.side = gobangControl.SelectedSide; //(0:black 1:white 2:Observer) //EnterRoom , tableIndex, side SendToServer(string.Format("EnterRoom,{0},{1}", tableIndex, side)); }
private void SetTextProperty(GobangRoom table, int index, string name) { if (table.InvokeRequired == true) { SetTextPropertyDelegate d = new SetTextPropertyDelegate(SetTextProperty); table.Invoke(d, table, index, name); } else { if (index == 0) //Black Player { table.BlackPlayerName = name; } else //White Player { table.WhitePlayerName = name; } } }
private void SetBoolProperty(GobangRoom table, int index, bool boolValue) //table, black or white, sitted or empty { if (table.InvokeRequired == true) { SetBoolPropertyDelegate d = new SetBoolPropertyDelegate(SetBoolProperty); table.Invoke(d, table, index, boolValue); } else { if (index == 0) //Black Player { table.HasBlackPlayer = boolValue; } else //White Player { table.HasWhitePlayer = boolValue; } } }
private void AddTablesToPanel() { if (panel1.InvokeRequired == true) { AddTablesToPanelDelegate d = new AddTablesToPanelDelegate(AddTablesToPanel); panel1.Invoke(d); } else { tables = new GobangUserControl.GobangRoom[roomNumber]; tableTips = new Label[roomNumber]; for (int i = 0; i < roomNumber; i++) { int xPosition = 15; int yPosition = 15; int offsetX = 60; int offsetY = 60; int currentStartXIndex = i % 3; int currentStartYIndex = i / 3; tables[i] = new GobangRoom(); tableTips[i] = new Label(); tables[i].Left = xPosition + currentStartXIndex * (tables[i].Width + offsetX); tables[i].Top = yPosition + currentStartYIndex * (tables[i].Height + offsetY); tables[i].HasBlackPlayer = false; tables[i].BlackPlayerName = ""; tables[i].HasWhitePlayer = false; tables[i].WhitePlayerName = ""; tables[i].Name = "Room" + i; //tables[i].Visible = false; tables[i].Validating += new CancelEventHandler(Table_Validating); //When click the component, or alter the properties of this component //Validating event will be triggered tableTips[i].Left = tables[currentStartXIndex].Left + (tables[currentStartXIndex].Width - tableTips[currentStartXIndex].Width) / 2 + 25; tableTips[i].Top = yPosition + currentStartYIndex * (tables[i].Height + offsetY) + 90; tableTips[i].Text = "Table " + i; tableTips[i].Image = Properties.Resources._10_140312153051A1; } panel1.Controls.AddRange(tables); panel1.Controls.AddRange(tableTips); } }