座椅预约软件:在C#中瞬间抽签席位 [英] Seat reserving software: Drawing lots of Seats in C# instantly

查看:260
本文介绍了座椅预约软件:在C#中瞬间抽签席位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬和#2程序员。



我要建座使用C#软件保留我很困惑我怎么瞬间抽签的席位。
我试图三通是..




  1. 使用用户控件



 公共无效DrawUsercontrol(INT X,int y)对
{
INT空间= 4;
INT SeatLimit = 165;
INT RowSeatLimit = 15;
为(VAR I = 1; I< SeatLimit;我++)
{
的UserControl1 CTRL =新的UserControl1();
ctrl.Size =新System.Drawing.Size(25,25);
ctrl.Location =新的点(x +空格,Y);
如果(I%RowSeatLimit == 0)
{
X = 1;
Y = Y + 25 +空间;
}
X = X + 25 +空间;
ctrl.label1.Text = i.ToString();
ctrl.label1.Click + =新的EventHandler(label1_Click);
panel1.Controls.Add(CTRL);
}
}




  1. 使用面板控制

     公共无效DrawingPanel(INT X,int y)对
    {
    面板myPanel =新面板();
    INT宽度= 16;
    INT高度= 16;
    myPanel.Size =新尺寸(宽,高);
    myPanel.BackColor = Color.White;
    myPanel.Location =新点(X,Y);
    标签mylabel =新的Label();
    mylabel.Text =4;
    myPanel.Controls.Add(mylabel);
    myPanel.BackColor = Color.YellowGreen;
    // this.Controls.Add(myPanel);
    panel1.Controls.Add(myPanel);
    }


  2. 使用图形,绘制矩形

     公共无效DrawingSquares(INT X,int y)对
    {
    SolidBrush myBrush =新SolidBrush(System.Drawing.Color.Red);
    图形graphicsObj;
    graphicsObj = this.panel1.CreateGraphics();
    矩形myRectangle =新的Rectangle(X,Y,30,30);
    graphicsObj.FillRectangle(myBrush,myRectangle);
    graphicsObj.Dispose();
    }




我指的第一个选项但它的速度太慢。
和我怎样才能决定。
请帮助我。


解决方案

您的问题是,您要添加在同一时间只有一个控制。添加控制力父面板(最好的情况下),也许整个表单(最坏情况)的完全刷新(的软件的GDI +渲染速度很慢)。



尝试创建所有控件,并使用 Panel.Controls.AddRange 在一行中添加。这将只提示行刷新



您也应该只添加这些控件时,首先显示的形式和时的议席数目改变 - 这是一个昂贵的(和相对的慢)操作。



考虑创建一个用户控件每个座位,这样你不'吨有管理的标签的座位座位边框的分开 - 这样,你可以有一个列表。如果为了增加座位,一个项目的列表索引将映射到其座位号!你可能不会从中得到的性能提升,但你的代码会更容易的工作。


Dear Stackoverflow and Programmer.

I'm building Seat reserving software using C# and i am confusing how i draw lots of seats instantly. i'm trying three way which is..

  1. Using Usercontrol

    public void DrawUsercontrol(int x, int y)
    {
        int space = 4;
        int SeatLimit = 165;
        int RowSeatLimit = 15;
        for (var i = 1; i < SeatLimit; i++)
        {
            UserControl1 ctrl = new UserControl1();
            ctrl.Size = new System.Drawing.Size(25, 25);
            ctrl.Location = new Point(x + space, y);
            if (i % RowSeatLimit == 0)
            {
                x = 1;
                y = y + 25 + space;
            }
            x = x + 25 + space;
            ctrl.label1.Text = i.ToString();
            ctrl.label1.Click += new EventHandler(label1_Click);
            panel1.Controls.Add(ctrl);
        }
    }

  1. Using "Panel" control

    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);
    }
    

  2. Using Graphics and draw Rectangle

    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();
    }
    

i refer first option but its too slow. and how can i decide. Pls Help me.

解决方案

Your problem is that you are adding only one control at a time. Adding a control forces a full refresh (software GDI+ rendering is quite slow) of the parent panel (best case) and perhaps the whole form (worst case).

Try creating all your controls and adding them in one line using Panel.Controls.AddRange. This will only prompt one refresh.

You should also only add these controls when the form is first shown and when the number of seats change - it is an expensive (and relatively slow) operation.

Consider creating a UserControl for each seat so that you don't have to manage the seat labels and seat borders separately - this way you can just have one list. If you add the seats in order, the index of an item in the list will map to its seat number! You probably wont get a performance increase from this but your code will be easier to work with.

这篇关于座椅预约软件:在C#中瞬间抽签席位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆