C# button.image 如何是使用icon格式的图标?如何当点击button时显示多个可选图标??

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C# button.image 如何是使用icon格式的图标?如何当点击button时显示多个可选图标??相关的知识,希望对你有一定的参考价值。

参考技术A 这不存在问题啊,你可以单击button在右边的image选项里找到你保存为icon格式的图标,找本书看看一下就明白了。弹出的话,你可以在BUTTON做几个弹出的button,而这些BUTTON的图标显示样式是可以让你自己随意选择图片的。 参考技术B 通过分别修改按钮的鼠标鼠标经过;按下等事件设置按钮的图片实现动态按钮
如何当点击button时显示多个可选图标??:可以把多个按钮放到GroupBox控件中,
设置Visible属性为false,当按下按钮时修改为true。如:
this.GroupBox1.Visible = true;本回答被提问者采纳
参考技术C 看一下

C# DevExpress XtraMessageBox自定义字体,字体大小,自定义按钮大小,自定义Icon

1.使用XtraMessageBoxForm,自定义Icon

2.重写XtraMessageBoxForm,自定义消息字体,标题字体

3.注册XtraMessageBoxForm的Showing事件,自定义按钮字体及按钮大小

 

具体代码如下,只写了简单两种方法,可自己扩展,赋值MessageBoxIcon可以显示想要的Icon

 

    public static class UIMessageBox
    
        static UIMessageBox()
        
            MessageBoxForm.MessageBoxFont = new Font("Arial", 14F); //定义字体类型
        

        static readonly Icon MessageBoxIcon = null;


        public static void Show(string message)
        
            ShowInternal(null, message, "Notice", SystemIcons.Information, DialogResult.OK);
        

        public static void Show(Control owner, string message)
        
            ShowInternal(owner, message, "Notice", SystemIcons.Information, DialogResult.OK);
        

private static DialogResult ShowInternal(Control owner, string message, string caption, Icon messageIcon, params DialogResult[] dialogResults) MessageBoxForm form = new MessageBoxForm(); form.Icon = MessageBoxIcon; XtraMessageBoxArgs args = new XtraMessageBoxArgs(owner, message, caption, dialogResults, messageIcon, 0); args.Showing += Args_Showing; return form.ShowMessageBoxDialog(args); private static void Args_Showing(object sender, XtraMessageShowingArgs e) MessageButtonCollection buttons = e.Buttons as MessageButtonCollection; SimpleButton btn = null; foreach (var dialog in (DialogResult[])Enum.GetValues(typeof(DialogResult))) btn = buttons[dialog] as SimpleButton; if (btn != null) btn.Size = new Size(Convert.ToInt32(btn.Width * 1.2), Convert.ToInt32(btn.Height * 1.2)); //按钮大小 btn.Font = e.Form.Font; //按钮字体 internal class MessageBoxForm : XtraMessageBoxForm internal static Font MessageBoxFont = new Font("Arial", 10F); public MessageBoxForm() Appearance.Font = MessageBoxFont; protected override FormPainter CreateFormBorderPainter() return new MessageBoxFormPainter(this, LookAndFeel); internal class MessageBoxFormPainter : FormPainter internal MessageBoxFormPainter(Control owner, ISkinProvider provider) : base(owner, provider) protected override void DrawText(GraphicsCache cache) string text = Text; if (text == null || text.Length == 0 || TextBounds.IsEmpty) return; AppearanceObject appearance = new AppearanceObject(GetDefaultAppearance()); appearance.Font = Owner.Font; appearance.TextOptions.Trimming = Trimming.EllipsisCharacter; Rectangle r = RectangleHelper.GetCenterBounds(TextBounds, new Size(TextBounds.Width, appearance.CalcDefaultTextSize(cache.Graphics).Height)); DrawTextShadow(cache, appearance, r); cache.DrawString(text, appearance.Font, appearance.GetForeBrush(cache), r, appearance.GetStringFormat()); protected override int CalcTextHeight(Graphics graphics, AppearanceObject appearance) return (int)(graphics.MeasureString(Text, Owner.Font).Height); //标题栏的高度

 

调用时:

UIMessageBox.Show("This is a message");

 

以上是关于C# button.image 如何是使用icon格式的图标?如何当点击button时显示多个可选图标??的主要内容,如果未能解决你的问题,请参考以下文章

C#界面里Form.Icon 属性的使用

C#无损转换Image为Icon

C# DevExpress XtraMessageBox自定义字体,字体大小,自定义按钮大小,自定义Icon

全网首发:C#中Form设置$this.Icon,任务栏图标错误的解决办法(bitmap转icon)

微信小程序之常用组件

微信小程序之常用组件