public class ThreeDRenderer : Renderer
{
private Font _Font = new Font("Microsoft YaHei", 15, FontStyle.Bold);
private StringFormat _Format;
///
/// Initializes a new instance of the ThreeDRenderer class.
///
public ThreeDRenderer()
{
_Format = (StringFormat)StringFormat.GenericDefault.Clone();
_Format.LineAlignment = StringAlignment.Center;
_Format.Alignment = StringAlignment.Center;
}
public override void DrawBackground(BackgroundRendererEventArgs args)
{
/*
using (TextureBrush brush = new TextureBrush(global::NumberTouchKeyBoard.Properties.Resources.Fiber))
{
brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;
args.Graphics.FillRectangle(brush, args.Bounds);
}
*/
}
public override void DrawKey(KeyRendererEventArgs args)
{
Rectangle keyBounds = args.Bounds;
args.Graphics.FillRectangle(ColorTable.KeysBrush, keyBounds);
if (args.IsDown || args.Key.Style == KeyStyle.Pressed || args.Key.Style == KeyStyle.Toggled)
{
Draw3DBorder(args.Graphics, keyBounds, ColorTable.DarkKeysBrush, ColorTable.LightKeysBrush);
keyBounds.Offset(1, 1);
if (args.Key.Style == KeyStyle.Toggled)
args.Graphics.DrawString(args.Key.Caption, _Font, ColorTable.ToggleTextBrush, keyBounds, _Format);
else
args.Graphics.DrawString(args.Key.Caption, _Font, ColorTable.TextBrush, keyBounds, _Format);
}
else
{
Draw3DBorder(args.Graphics, keyBounds, ColorTable.LightKeysBrush, ColorTable.DarkKeysBrush);
args.Graphics.DrawString(args.Key.Caption, _Font, ColorTable.TextBrush, keyBounds, _Format);
}
}
public override void DrawTopBar(TopBarRendererEventArgs args)
{
args.Graphics.DrawString(args.Text, _Font, ColorTable.TopBarTextBrush, args.Bounds);
}
public override void DrawCloseButton(CloseButtonRendererEventArgs args)
{
if (args.IsDown)
Draw3DBorder(args.Graphics, args.Bounds, ColorTable.DarkKeysBrush, ColorTable.LightKeysBrush);
else
Draw3DBorder(args.Graphics, args.Bounds, ColorTable.LightKeysBrush, ColorTable.DarkKeysBrush);
Rectangle rect = args.Bounds;
rect.Inflate(-5, -5);
using (Pen p = new Pen(ColorTable.TextBrush, 2))
{
args.Graphics.DrawLine(p, rect.Left, rect.Top, rect.Right, rect.Bottom);
args.Graphics.DrawLine(p, rect.Left, rect.Bottom, rect.Right, rect.Top);
}
}
private static void Draw3DBorder(Graphics g, Rectangle bounds, Brush light, Brush dark)
{
int borderSize = 1;
g.FillRectangle(light, new Rectangle(bounds.Left, bounds.Top, bounds.Width, borderSize));
g.FillRectangle(light, new Rectangle(bounds.Left, bounds.Top, borderSize, bounds.Height));
g.FillRectangle(dark, new Rectangle(bounds.Left, bounds.Bottom - borderSize, bounds.Width, borderSize));
g.FillRectangle(dark, new Rectangle(bounds.Right - borderSize, bounds.Top, borderSize, bounds.Height));
}
}
五、效果图(关闭按钮是自己用Button控件添加的)
六、最后调用软键盘
软键盘写好了,就需要在其他程序里面调用。
其实有很多的解决方案,我是直接在需要出现该软件的事件中,添加消息响应,如在EditBox中添加Click响应事件,调用键盘进程。注意,进程不要忘了kill掉,否则会出现很多进程。每次点击最好将之前的进程全部杀死,然后重建,否则会有软键盘存在,却看不到(在界面后面)的情况发生。该方法未必最科学,请大家批评指正。
public static bool start_keyboard() //启动键盘
{
try
{
Process[] prc = Process.GetProcesses();
foreach (Process pr in prc) //遍历整个进程
{
if (keyboard_name1 == pr.ProcessName) //如果进程存在
{
pr.Kill();
}
}
psInfo = new ProcessStartInfo(@keyboard_name);
pro.StartInfo = psInfo;
if (pro.Start())
{
SetForegroundWindow(pro.MainWindowHandle);
}
return true;
}
catch (Exception)
{
return false;
}
}