123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- using DevExpress.CodeParser;
- using DevExpress.Utils;
- using DevExpress.XtraEditors;
- using DevExpress.XtraEditors.Controls;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Ips.Library.Basic;
- using DevExpress.Utils.Url;
- namespace Ips.Library.DxpLib
- {
- public static class ButtonEditExtensions
- {
- public static ButtonEdit SetUnitText(this ButtonEdit source, string unitText, bool isDecimal = true, bool clearOther = true, string mask = "")
- {
- if (clearOther)
- {
- source.Properties.Buttons.Clear();
- }
- var unitBtn = new EditorButton()
- {
- Caption = unitText,
- Kind = ButtonPredefines.Glyph,
- Enabled = false,
- };
- var props = source.Properties;
- props.Appearance.Options.UseTextOptions = true;
- props.Appearance.TextOptions.HAlignment = HorzAlignment.Near;
- props.MaskSettings.UseMaskAsDisplayFormat = true;
- if (isDecimal)
- {
- props.MaskSettings.MaskExpression = mask.IfNullOrWhitespace("############0.0#####");
- }
- else
- {
- props.MaskSettings.MaskExpression = mask.IfNullOrWhitespace("d");
- }
- props.Buttons.Add(unitBtn);
- return source;
- }
- public static ButtonEdit SetFileOpen(this ButtonEdit source, string fileName = "", string title = "", string initPath = "", string filter = "", bool mutiSelect = false, bool clearOther = true)
- {
- var props = source.Properties;
- if (clearOther) props.Buttons.Clear();
- title = title.IfNullOrWhitespace("选择文件");
- var btnOpenFile = new EditorButton()
- {
- Caption = title,
- Kind = ButtonPredefines.Glyph
- };
- btnOpenFile.ImageOptions.ImageUri.Uri = "actions/open2";
- btnOpenFile.ImageOptions.SvgImageSize = new Size(12, 12);
- props.Buttons.Add(btnOpenFile);
- source.ButtonClick += (sender, args) =>
- {
- if (args.Button.Caption == title)
- {
- string selectFile = ToolDialog.OpenFile(fileName, title, initPath, filter, mutiSelect);
- source.EditValue = selectFile;
- }
- };
- return source;
- }
- public static ButtonEdit SetFolderOpen(this ButtonEdit source, string title = "", bool clearOther = true)
- {
- var props = source.Properties;
- if (clearOther) props.Buttons.Clear();
- title = title.IfNullOrWhitespace("选择文件");
- var btnOpenFile = new EditorButton()
- {
- Caption = title,
- Kind = ButtonPredefines.Glyph
- };
- btnOpenFile.ImageOptions.ImageUri.Uri = "actions/open";
- btnOpenFile.ImageOptions.SvgImageSize = new Size(12, 12);
- props.Buttons.Add(btnOpenFile);
- source.ButtonClick += (sender, args) =>
- {
- if (args.Button.Caption == title)
- {
- string selectFile = ToolDialog.OpenFolder(title);
- source.EditValue = selectFile;
- }
- };
- return source;
- }
- public static ButtonEdit SetFileSave(this ButtonEdit source, string fileName = "", string title = "", string initPath = "", string filter = "", bool clearOther = true)
- {
- var props = source.Properties;
- if (clearOther) props.Buttons.Clear();
- title = title.IfNullOrWhitespace("选择文件");
- var btnOpenFile = new EditorButton()
- {
- Caption = title,
- Kind = ButtonPredefines.Glyph
- };
- btnOpenFile.ImageOptions.ImageUri.Uri = "actions/open2";
- btnOpenFile.ImageOptions.SvgImageSize = new Size(12, 12);
- props.Buttons.Add(btnOpenFile);
- source.ButtonClick += (sender, args) =>
- {
- if (args.Button.Caption == title)
- {
- string selectFile = ToolDialog.SaveFile(fileName, title, initPath, filter);
- source.EditValue = selectFile;
- }
- };
- return source;
- }
- public static ButtonEdit EnableDragDropFile(this ButtonEdit source)
- {
- ((TextEdit)source).EnableDragDropFile();
- return source;
- }
- }
- }
|