使用devexpress——tilecontrol制作精美文件上传样式

使用devexpress——tilecontrol制作文件上传样式

    • 附核心代码

利用tilecontrol控件实现文件上传样式,如图

使用devexpress——tilecontrol制作精美文件上传样式_第1张图片

具体demo:https://download.csdn.net/download/chen2466/12752012

附核心代码

private void tileItem1_ItemClick(object sender, DevExpress.XtraEditors.TileItemEventArgs e)
        {
     
            OpenFileDialog FileDialog = new OpenFileDialog();
            FileDialog.Multiselect = false;
            FileDialog.Title = "请选择课件";
            FileDialog.Filter = "选择文件(jpg,docx,xls,pptx)|*.jpg;*.docx;*.xls;*.pptx";
            if (FileDialog.ShowDialog() == DialogResult.OK)
            {
     
                string file = FileDialog.FileName;
                TileItemElement element = new TileItemElement();
                TileItem item = new TileItem();
                tileGroup2.Items.Add(item);
                item.AppearanceItem.Normal.Options.UseBackColor = true;
                item.ItemSize = TileItemSize.Medium;
                item.BorderVisibility = TileItemBorderVisibility.Never;
                item.AppearanceItem.Normal.ForeColor = System.Drawing.Color.White;
                string suffix = Path.GetExtension(file);
                switch (suffix)
                {
     
                    case ".jpg":
                        element.ImageOptions.Image = Image.FromFile(file);
                        item.AppearanceItem.Normal.BackColor = System.Drawing.SystemColors.ActiveCaption;
                        break;
                    case ".docx":
                        element.ImageOptions.Image = global::TileControlDemo.Properties.Resources.WinWordLogo_scale_100;
                        item.AppearanceItem.Normal.BackColor = System.Drawing.SystemColors.HotTrack;
                        break;
                    case ".xls":
                        element.ImageOptions.Image = global::TileControlDemo.Properties.Resources.ExcelLogo_scale_100;
                        item.AppearanceItem.Normal.BackColor = System.Drawing.Color.Green;
                        break;
                    case ".pptx":
                        element.ImageOptions.Image = global::TileControlDemo.Properties.Resources.PowerPntLogo_scale_100;
                        item.AppearanceItem.Normal.BackColor = System.Drawing.Color.Coral;
                        break;
                }
                element.ImageOptions.ImageAlignment = DevExpress.XtraEditors.TileItemContentAlignment.BottomCenter;
                element.Text = Path.GetFileName(file);
                element.TextAlignment = DevExpress.XtraEditors.TileItemContentAlignment.MiddleCenter;
                element.TextLocation = new System.Drawing.Point(0, 10);
                item.Elements.Add(element);
                item.Checked = true;
                item.ItemDoubleClick += new TileItemClickEventHandler(tileItem2_ItemDoubleClick);
            }
        }

你可能感兴趣的:(c#,devexpress,winform)