座位预定软件:立即在C#中抽签
我正在用C#构建座位预订软件,我弄不清楚我是如何立即画出很多座位的。 我正在尝试三种方法,即座位预定软件:立即在C#中抽签,c#,C#,我正在用C#构建座位预订软件,我弄不清楚我是如何立即画出很多座位的。 我正在尝试三种方法,即 使用用户控件 使用图形绘制矩形 public void DrawingSquares(int x, int y) { SolidBrush myBrush = new SolidBrush(System.Drawing.Color.Red); Graphics graphicsObj; graphicsObj = this.panel1.CreateGraphics();
public void DrawingSquares(int x, int y)
{
SolidBrush myBrush = new SolidBrush(System.Drawing.Color.Red);
Graphics graphicsObj;
graphicsObj = this.panel1.CreateGraphics();
Rectangle myRectangle = new Rectangle(x, y, 30, 30);
graphicsObj.FillRectangle(myBrush, myRectangle);
graphicsObj.Dispose();
}
我该如何决定呢?您的问题是一次只添加一个控件。添加控件将强制父面板(最佳情况)以及整个表单(最坏情况)的完全刷新(软件GDI+渲染相当慢) 尝试创建所有控件,并使用
Panel.controls.AddRange
将它们添加到一行中。这将只提示一次刷新
您还应该仅在表单首次显示时以及座位数更改时添加这些控件-这是一个昂贵(且相对缓慢)的操作
考虑为每个座椅创建一个
UserControl
,这样您就不必单独管理座椅标签和座椅边框-这样您就可以拥有一个列表。如果您按顺序添加座位,列表中项目的索引将映射到其座位号!您可能不会因此获得性能提升,但您的代码将更易于使用。您可以使用DataGridView,将其绑定到数据源。每个单元格代表一个座位。另一位是:BeginInit()/EndInit()
从控件对iSupportsInitalize进行初始化,和/或控件的SuspendLayout()/ResumeLayout()
。前者可以加速UI控件中的任何大规模更改(并且在InitializeComponent中大量使用),但有时很棘手。后者更安全,当您必须在控件
集合中执行许多不寻常的移位时,后者可以提供帮助,而这些移位不能通过AddRange
来解决。看见完成后别忘了继续;)
public void DrawingPanel(int x, int y)
{
Panel myPanel = new Panel();
int width = 16;
int height = 16;
myPanel.Size = new Size(width, height);
myPanel.BackColor = Color.White;
myPanel.Location = new Point(x, y);
Label mylabel = new Label();
mylabel.Text = "4";
myPanel.Controls.Add(mylabel);
myPanel.BackColor = Color.YellowGreen;
// this.Controls.Add(myPanel);
panel1.Controls.Add(myPanel);
}
public void DrawingSquares(int x, int y)
{
SolidBrush myBrush = new SolidBrush(System.Drawing.Color.Red);
Graphics graphicsObj;
graphicsObj = this.panel1.CreateGraphics();
Rectangle myRectangle = new Rectangle(x, y, 30, 30);
graphicsObj.FillRectangle(myBrush, myRectangle);
graphicsObj.Dispose();
}