Well, overriding OnPaint() of in Win Form is fairly simple, using WFP window might be another option, if you use Acad2010 or later (even you are not now, you'll certainly go to it one day anyway). I did a quick sample out of it.
Here is the WPF window's XAML code (In acad DLL project, VS2008/2010 only let you add a WPF UserControl. Go ahead to add a WPF UserControl, and then change the "UserControl" tag to "Window" and change the the code behind class file to let it inherit from System.Windows.Window, instead of System.Windows.UserControl):
<Window x:Class="MyMessageBox.MsgBoxView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="244"
d:DesignWidth="397"
SizeToContent="WidthAndHeight"
ResizeMode="CanResize"
WindowStartupLocation="CenterOwner"
ShowInTaskbar="False"
WindowStyle="ToolWindow"
Title="My Message Box">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50*" />
<RowDefinition Height="98*" />
<RowDefinition Height="57*" />
</Grid.RowDefinitions>
<Button Content="OK" Grid.Row="2" Height="23"
HorizontalAlignment="Left" Margin="281,9,0,0"
Name="button2" VerticalAlignment="Top"
Width="75" Click="button2_Click" />
<StackPanel Grid.Row="1" Name="msgPanel"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Orientation="Horizontal"/>
<StackPanel Name="stackPanel1">
<TextBlock FontSize="20"
FontWeight="ExtraBold"
Foreground="#FF1313D8"
Text="Title of the message" />
</StackPanel>
</Grid>
</Window>
Here is the MsgBoxView class (WPF Window) code behind:
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MyMessageBox
{
/// <summary>
/// Interaction logic for MsgBoxView.xaml
/// </summary>
public partial class MsgBoxView : Window
{
public MsgBoxView()
{
InitializeComponent();
}
public void AddMessage(string[] msgStrings)
{
msgPanel.Children.Clear();
TextBlock txt;
this.DataContext = msgStrings.ToList<string>();
int i = 1;
Brush br = Brushes.Black;
foreach (string s in msgStrings)
{
txt = new TextBlock();
txt.SetValue(TextBlock.TextProperty, s);
double fSize = 10.0;
switch (i)
{
case 1:
fSize = 16.0;
br = Brushes.Red;
break;
case 2:
fSize = 14.0;
br = Brushes.Blue;
break;
case 3:
fSize = 12.0;
br = Brushes.Green;
break;
}
i++;
txt.SetValue(TextBlock.FontFamilyProperty, new FontFamily("Arial"));
txt.SetValue(TextBlock.FontSizeProperty, fSize);
txt.SetValue(TextBlock.ForegroundProperty, br);
txt.SetValue(TextBlock.MarginProperty, new Thickness(0.0, 0.0, 2.0, 0.0));
msgPanel.Children.Add(txt);
}
}
private void button2_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
Then in the Acad Dll project, I added a class "MyMessageBox":
using Autodesk.AutoCAD.ApplicationServices;
namespace MyMessageBox
{
public class MyMessageBox
{
private static MsgBoxView _view = null;
public static void ShowMyMessageBox(string[] messageStrings)
{
_view = new MsgBoxView();
_view.AddMessage(messageStrings);
Application.ShowModalWindow(_view);
_view = null;
}
}
}
And finally, I added a command class in the Acad DLL project:
using Autodesk.AutoCAD.Runtime;
namespace MyMessageBox
{
public class MyCommands
{
[CommandMethod("MyMsg")]
public static void ShowMyMessageBox()
{
MyMessageBox.ShowMyMessageBox(
new string[]
{
"Welcome",
"to",
"My",
"Message",
"Box"
});
}
}
}
As you can see, with WPF window/UserControl, you can easily control text label (TextBlock in WPF) with its font, color, sizeand/or other properties...
This is just showing a concept that how much and how easy control you have to the things showing on a WPF window. Attached in the image of the message box created by the code shown here.
Where should I paste this code in my CSharp project and how can I call the function from Autocad?