代码改变世界

初始化toolstrip

2012-05-30 10:16  极无宪  阅读(205)  评论(0编辑  收藏  举报
        /// <summary>
        /// 初始化工具条
        /// </summary>
        private void InitializeToolbar()
        {
            Image img = global::Win.Properties.Resources.mainfram;
            //240 15
            int heigh = 15;
            int width = 16;
            for (int i = 0; i < 15; i++)
            {
                Bitmap bitmap = new Bitmap(16, 15, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                Graphics graphics = Graphics.FromImage(bitmap);
                graphics.DrawImage(img, new Rectangle(0, 0, width, heigh), i * width, 0, 16, 15, GraphicsUnit.Pixel);
                ToolStripButton tsb = new ToolStripButton();
                tsb.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
                tsb.Image = Image.FromHbitmap(bitmap.GetHbitmap());
                tsb.ImageTransparentColor = System.Drawing.Color.Magenta;
                tsb.Name = "tsbtn" + i;
                tsb.Size = new System.Drawing.Size(23, 22);
                tsb.Text = "toolStripButton1";
                tsb.Click += new EventHandler(tsb_Click);
                tsToll.Items.Add(tsb);
            }
        }