messagebox - How to set the font in different styles for Message Box in WPF -


how can message box in below style eaisly? messagebox function seems cannot trick

enter image description here

you can make own notification dialog using window

here quick example whipped together

usage:

  notificationdialog.shownotification("backup , restor center"                 , "you need administrator run backup"                 , "use fast user switching switch account administrator privileges, or log off , log on administrator"                 , notifyicon.exclamation); 

code:

using system; using system.componentmodel; using system.drawing; using system.reflection; using system.runtime.compilerservices; using system.runtime.interopservices; using system.windows; using system.windows.interop; using system.windows.media.imaging;  namespace wpfapplication8 {     /// <summary>     /// interaction logic notificationdialog.xaml     /// </summary>     public partial class notificationdialog : window, inotifypropertychanged     {         public static void shownotification(string title, string caption, string message, notifyicon icon)         {             notificationdialog dialog = new notificationdialog();             dialog.title = title;             dialog.caption = caption;             dialog.message = message;             dialog.image = dialog.geticon(icon);             dialog.showdialog();         }          private string _caption;         private string _message;         private bitmapsource _image;          private const int gwl_style = -16;         private const int ws_sysmenu = 0x80000;         [dllimport("user32.dll", setlasterror = true)]         private static extern int getwindowlong(intptr hwnd, int nindex);         [dllimport("user32.dll")]         private static extern int setwindowlong(intptr hwnd, int nindex, int dwnewlong);          public notificationdialog()         {             datacontext = this;             initializecomponent();             loaded += (s, e) =>                 {                     var hwnd = new windowinterophelper(this).handle;                     setwindowlong(hwnd, gwl_style, getwindowlong(hwnd, gwl_style) & ~ws_sysmenu);                 };         }          public string caption         {             { return _caption; }             set { _caption = value; notifypropertychanged(); }         }          public string message         {             { return _message; }             set { _message = value; notifypropertychanged(); }         }           public bitmapsource image         {             { return _image; }             set { _image = value; notifypropertychanged(); }         }          private bitmapsource geticon(notifyicon icontype)         {             icon icon = (icon)typeof(systemicons).getproperty(icontype.tostring(), bindingflags.public | bindingflags.static).getvalue(null, null);             return imaging.createbitmapsourcefromhicon(icon.handle, int32rect.empty, bitmapsizeoptions.fromemptyoptions());         }          private void button_close_click(object sender, routedeventargs e)         {             dialogresult = true;         }          public event propertychangedeventhandler propertychanged;         public void notifypropertychanged([callermembername]string propertyname = null)         {             if (propertychanged != null)             {                 propertychanged(this, new propertychangedeventargs(propertyname));             }         }     }      public enum notifyicon     {         application,         asterisk,         error,         exclamation,         hand,         information,         question,         shield,         warning,         winlogo     }  } 

xaml:

<window x:class="wpfapplication8.notificationdialog"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         height="239" width="417" title="{binding title}" resizemode="noresize" >     <grid>         <grid.rowdefinitions>             <rowdefinition height="223*"/>             <rowdefinition height="50"/>         </grid.rowdefinitions>         <button content="close" horizontalalignment="right" margin="0,0,10,7" grid.row="1" verticalalignment="bottom" width="75" click="button_close_click"/>         <stackpanel margin="70,10,10,0">             <textblock text="{binding caption}" fontsize="20" foreground="darkblue" textwrapping="wrap"/>             <textblock margin="0,10,0,0" text="{binding message}" textwrapping="wrap"/>         </stackpanel>         <image source="{binding image}" stretch="none" horizontalalignment="left" height="52" margin="6,10,0,0" verticalalignment="top" width="55"/>     </grid> </window> 

result: enter image description here


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -